Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating a table using php

Status
Not open for further replies.

Delphiwhat

Programmer
Apr 1, 2003
74
EU
Guys

I'm new to php and what I want to do is update a table (mytable) in a myssql database.

So basically I need to create a webpage with 2 fields 'house number' and 'status'.

Status is a dropdown list populated from another table (haven't worked out how to do this)

house number is populated by the user typing in a number.

When the user presses submitt button the mytable should be updated with a new record.

Any ideas how to do this or could someone start me of

Thanks

st

 
This is an easy task.
You have the pseudo-op code writeen out yourself - where is the problem?
 
This is what I would do. Beware my ways arn't always the best.

<?php

$housenum = $_REQUEST['housenum'];
$status = $_REQUEST['status'];

if ($submit){
$host = "localhost";
$user = "root";
$password = "password";
$database = "database";
/* Connect to the db and select a database*/
$dbLink = mysql_connect($host,$user, $password) or die("Couldn't connect to the database!");
$success = mysql_select_db($database) or die("Error selecting the database! <br> ".mysql_error());

$query = "INSERT INTO houseinfo (housenum, status) VALUES ('$housenum', '$status')";
$result = mysql_query($query);
mysql_close($dbLink);
}
$HTML ="
<form name='addhouse' action='thisscript.php' method='get'>
<table border='0'>
<tr>
<td>Housenum: </td>
<td><input type='text' name='housenum'></td>
</tr>
<tr>
<td>Status: </td>
<td><input type='text' name='status'></td>
</tr>
</table>
<input name='submit' type='submit' value='Submit'>";

echo $HTML;

?>

Sera
I often believe that...
My computer is possessed!
 
thank thats put me on the right direction. Just one more question with refernce to your code how would i make the status box a dropdown that is filled from another table lets say 'status_table' ?

thanks for all your help
dw
 
This is what i have.

include('dbconnect.php');
$query = mysql_query("SELECT name FROM experiment WHERE experiment.project_ID = $projectnum");
while( $option = mysql_fetch_array( $query )){
$experimentselect .= "<option value=\"{$option['name']}\">{$option['name']}</option>";
}
$HTML .= "<form name='form2' action='index2.php' method='get'>
Experiment Name: <select name='experimentname'>
<option value=''></option>$experimentselect</select>
<input type='hidden' name='projectname' value='$projectname'>
<input type='hidden' name='body' value='downloads'>
<input name='submit4' type='submit' value='Submit'>
</form>";

Sera
I often believe that...
My computer is possessed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top