Update Query in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ash4u
Forum Newbie
Posts: 2
Joined: Tue Mar 30, 2010 11:44 pm
Contact:

Update Query in php

Post 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
ash4u
Forum Newbie
Posts: 2
Joined: Tue Mar 30, 2010 11:44 pm
Contact:

Re: Update Query in php

Post 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)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Update Query in php

Post 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']).
(#10850)
Post Reply