I am trying to update a table in my DB for the past two days. But I am unable to get it to work. Somebody please help me. I could connect to my database, see my table fields perfectly. Posted values from the form could be read perfectly from the destined PHP file. MySQL query doesn't seen to return any error. But I dont understand why the values are not getting updated into the table.
//form.html
<form name="account" action="test.php" method="post">
<td align="left" valign="top" class="labelstyle" width="25%">First Name</td>
<td align="left" valign="top" class="labeltextstyle" width="75%"><input type="text" name="fname" value="" /></td>
<td align="left" valign="top" class="labelstyle" width="25%">Last Name</td>
<td align="left" valign="top" class="labeltextstyle" width="75%"><input type="text" name="lname" value="" /></td>
<td align="left" valign="top" class="labelstyle" width="25%">Email</td>
<td align="left" valign="top" class="labeltextstyle" width="75%"><input type="text" name="email" value="" /></td>
<td align="left" valign="top" class="labeltextstyle"><input type="submit" name="submit" value="Save" /></td>
</form>
// test.php
<?php
$dbhost = "localhost";
$dbname = "test";
$dbuser = "";
$dbpass = "";
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
if(isset($_REQUEST['submit'])){
// $query = "select * from form";
// $result = mysql_query($query);
// $numcolumn = mysql_num_fields($result);
// for ( $i = 0; $i < $numcolumn; $i++ ) {
// $columnnames = mysql_field_name($result, $i);
// echo $columnnames;
// }
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
echo $fname ;
echo $lname ;
echo $email ;
$query = "update test set
fname = $fname,
lname = $lname,
email = $email
where 1 ";
$result = mysql_query($query);
if ($query = 1) {
echo "IT WORKED";
} else {
echo "DIDNT WORK";
}
}else{
echo "NOT SUBMITTED";
}
?>
//form.html
<form name="account" action="test.php" method="post">
<td align="left" valign="top" class="labelstyle" width="25%">First Name</td>
<td align="left" valign="top" class="labeltextstyle" width="75%"><input type="text" name="fname" value="" /></td>
<td align="left" valign="top" class="labelstyle" width="25%">Last Name</td>
<td align="left" valign="top" class="labeltextstyle" width="75%"><input type="text" name="lname" value="" /></td>
<td align="left" valign="top" class="labelstyle" width="25%">Email</td>
<td align="left" valign="top" class="labeltextstyle" width="75%"><input type="text" name="email" value="" /></td>
<td align="left" valign="top" class="labeltextstyle"><input type="submit" name="submit" value="Save" /></td>
</form>
When i fill the form with values A, B and C and submit the form, I get the following output.
fnamelnameemailABCIT WORKED
please help me soon.