Hi,
I have this code. It works fine using PHP 4 and MySQL 5.0. but it doesn't work at all on my webhost (php4 mySQL 4) and I cannot for the life of me figure out why.
Here's my code:
/<?
// Connect database.
include("connectdb.php");
//if "Submit" button is clicked
if($_POST){
//Get parameters from form
$id=$_GET;
$name=$_POST;
$email=$_POST;
$tel=$_POST;
//Update database record
mysql_query("update phonebook set name='$name', email='$email', tel='$tel' where id='$id'");
//Redirect to record view page
header("location:select.php");
exit;
}
// ************* End update part *************
//Get record id to display data for record to be updated
$id=$_GET;
//Put all the results from the query into $result
$result=mysql_query("select * from phonebook where id='$id'");
//Split result into rows and put in $row
$row=mysql_fetch_assoc($result);
?>
<!-- END PHP. This is the HTML form for updating the record -->
<html>
<body>
<!-- set this form to POST method and target itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<p>Name :
<!-- name of this text field is "name" -->
<input name="name" type="text" id="name" value="<? echo $row; ?>"/>
<br />
Email :
<!-- name of this text field is "email" -->
<input name="email" type="text" id="email" value="<? echo $row; ?>"/>
<br />
Tel :
<!-- name of this text field is "tel" -->
<input name="tel" type="text" id="tel" value="<? echo $row; ?>"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
---end update.php----
For some reason this fails to update the db, but doesn't give an error. The exact same code works perfectly on my development system (php4 and mysql 5.0).
When I try to do the following in phpmyadmin on my webhost it works fine:
UPDATE phonebook SET name='test', email='test', tel='123' WHERE id='2';
But somehow it doesn't work when i use the update.php script.
The weirdest thing is that I can do a lookup query just fine, for example the code below works just fine and it also uses the same $id variable.
$result=mysql_query("select * from phonebook where id='$id'");
$row=mysql_fetch_assoc($result);
I'm at my wits end and don't know what else to try. Do you have any suggestions?