Mysql query does not update row [closed]
- by Gerculy Robert
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
/*$id=$_GET['$usrid'];*/
// Retrieve data from database
$sql="SELECT * FROM user WHERE id='$usrid'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update site info</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>User Name</strong></td>
<td align="center"><strong>Site url</strong></td>
<td align="center"><strong>Url banner</strong></td>
</tr>
<tr>
<td> </td>
<td align="center">
<input name="username" type="text" id="username" value="<? echo $rows['username']; ?>">
</td>
<td align="center">
<input name="siteurl" type="text" id="siteurl" value="<? echo $rows['siteurl']; ?>" size="40">
</td>
<td>
<input name="urlbanner" type="text" id="urlbanner" value="<? echo $rows['urlbanner']; ?>" size="40">
</td>
</tr>
<tr>
<td> </td>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php
// close connection
mysql_close();
?>
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="update user SET siteurl='$siteurl', username='$username', urlbanner='$urlbanner' WHERE id=$usrid";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='edit.php'>View result</a>";
}
else {
echo "ERROR";
}
Hello,
I have this two pages wich should update 3 rows.
The problem is it does not update all , only 2 .
I tried over 1 hour to find the problem but nothing.
The row , siteurl, is not being updated at all .
The table is :
varchar(255)
Database and session is ok.
Any idea ? It's just a simple update code , should work fine :(