Page 1 of 1

Update Query in php

Posted: Wed Mar 31, 2010 1:11 am
by ash4u

Code: Select all

<?php
$con=mysql_connect("localhost", "root" ,  "");
if(!$con)
{
die(('could not connect to server') .  mysql_error());
}
MYSQL_SELECT_DB("form" , $con);

$name = "ash";

$khads=mysql_query("SELECT * FROM khadz  WHERE name = '" . $name .  "';");
?>

<html>
<head>
</head>
<body>
<?php
WHILE($row=mysql_fetch_array($khads)){
?>
<form method = "post" action =  "getdata.php">
name<input type = "text" value = "<?php echo  $row['name'];?>"><br>
address1<input type = "text" value = "<?php  echo $row['address1'];?>"><br>
address2<input type = "text" value = "<?php  echo $row['address2'];?>"><br>
<input type = "submit" value = "update">
</form>

<?php 
}
?>
</body>
</html>
my this file is save as a updatedata.php

now i need to code for getdata.php

Re: Update Query in php

Posted: Wed Mar 31, 2010 1:23 am
by ash4u

Code: Select all

<?php
$con=mysql_connect("localhost", "root" ,   "");
if(!$con)
{
die(('could not connect to server') .   mysql_error());
}
mysql_select_db("form" , $con);

$name = "ash";

$khads=mysql_query("SELECT * FROM khadz   WHERE name = '" . $name .  "';");
echo ("name . '"$name" . address1 . '"$address1" ' . address2 . '"address2" ' . 
email . ' "$email"');")
?>
this is a file for getdata.php

now its shows so many error

i m fetching data from my table name khadz whose field name are name password address1 address2 and email , database name is form)

Re: Update Query in php

Posted: Wed Mar 31, 2010 1:44 am
by Christopher
For your first example, you need to check the online PHP manual for mysql_fetch_array() : http://us.php.net/manual/en/function.my ... -array.php

You are fetching an array, but using an associative array for $row['name'], $row['address1'], $row['address2']. Check the manual for mysql_fetch_array() instead: http://us.php.net/manual/en/function.my ... -assoc.php

You are very close. The manual has many very good examples. And user supplied examples in the comments.


For the second example, you need to get the values from the form from the superglobal array $_POST (e.g., $_POST['name']).