You do not ever execute the UPDATE query. You just defined a string, $r, containing some text. You have to call mysql_query() to send that text to the MySQL server.
Your query is inside an infinite loop, and does not in any way use the data you retrieved from the previous SELECT query. If you did call mysql_query() within the while loop, it would send that query to the server as many times as possible before the script execution time limit is reached. The query would also update all rows of the table with the new value, since you specify no WHERE clause restricting it to whatever row you wanted to update.
I think you want something more like this:
if (isset($_POST['update'])) {
$query = "UPDATE client SET age = " . (int)$_POST['age'] . " WHERE id = " . (int)$_POST['id'];
mysql_query($query);
}
Note that numeric values should not be enclosed in single quotes in SQL.
<?php
if(isset($_POST[‘Update’]))
{
$sql=“SELECT * FROM client WHERE id=‘1’”;
$result= mysql_query($sql) or die(mysql_error());
if($row=mysql_fetch_row($result))
{
While($row)
$r=“UPDATE client SET age=‘$age’”;
}
}
?>
in updation there is no need of select query you should write only
<?php
if(isset($_POST[‘Update’]))
{
mysql_connect(‘localhost’, ‘root’, ‘password’) or die(“cannot connect the database”);
mysql_select_db(“databasename”) or die(“can not open database”);
$age = $_POST[‘age’];
$r = “UPDATE client SET age=‘$age’ WHERE id=‘1’”;
$res = mysql_query($r);
}
$sql = "SELECT * FROM client WHERE `id` = " . mysql_real_escape_string ( $_GET['id'] );
if ($query = mysql_query ( $sql ) )
{
$row = mysql_fetch_assoc ( $query );
if ( $_POST [ 'name' ] != '' && $_POST [ 'email' ] != '' )
{
$query = "UPDATE
client
SET
`name` = " . mysql_real_escape_string ( $_POST [ 'name' ] ) . "
`email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . "
WHERE
`id` = " . mysql_real_escape_string ( $_GET['id'] );
if (mysql_query ( $query ) )
{
$success = 'Query updated successfully!';
}
else {
die ( mysql_error () );
}
}
else {
echo 'Please ensure that you have a title and some content for this article!';
}
}
else {
die ( mysql_error () );
}
}
if ( isset ( $success ) ) {
echo $success;
}
else {
//we need this form only if we don’t have the success message
?>
<form id=“update” name=“update” method=“post” action=“<?=$_SERVER[‘PHP_SELF’]?>”>
Easier if you answer the question. If you select multiple records, then the loop will display them. If you only want one record, then the query should reflect that and the loop will only display one.
Your query a few posts above selects by id, which should be unique, hence no possibility of getting multiple records.