...

View Full Version : Does anyone have an Update script/demo?



webandwe
04-24-2007, 02:19 PM
Hi

Say I have two forms: name and surname which puts the data into my sql.
How can I make a update page that you see your name and surname once on the update page?

Must I like put <? echo"$name?> in the form?

Does anyone have a script I can look at or have a demo?

Nightfire
04-24-2007, 02:22 PM
http://www.tizag.com/mysqlTutorial/mysqlupdate.php
http://www.google.co.uk/search?q=mysql+update+php&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a

webandwe
04-24-2007, 02:57 PM
Hi,

No, I want to echo a name into the form.

example:

Enter Name

[ ]
---------------
Then
--------------

Result Displays

Your Name [peter]
your surname [smiht ]
{button(update)}

-------------------------
Updated

Your name [peter]
your suraname [smith]

I want to see the text to display from mysql into my fields.

Thanks

rafiki
04-24-2007, 05:13 PM
http://www.google.com/search?q=getting+info+from+mysql+database

webandwe
04-25-2007, 01:49 PM
Hi, I made this code but it still need some editing. (Please note I'm learning php adn not yet familiar with updating the way I want to...)

Write a name to extract the name with surname for updating
----------------------------------------------------------



<form id="form1" name="form1" method="post" action="up2.php">
<label>
Enter
<input name="name" type="text" id="name" />
</label>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>



Update page
---------------


<?PHP
header( "cache-control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
$self = $_SERVER['PHP_SELF'];
if (!isset($_POST['submit'])){
?>
<?php
$con = mysql_connect("localhost","design","superdesign");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("gptesting_co_za_-_contact", $con);$result = mysql_query("SELECT * FROM persons");while($row = mysql_fetch_array($result))
{
$name = "name"
$name = "name";
}

mysql_close($con);
?>

<form id="form1" name="form1" method="post" action="<?php echo( $self ); ?>">
<label>
Name
<input name="dname" type="text" VALUE="<? echo "$name"?>" id="name" />
</label>
<p>Surname:
<input name="dsurname" type="text" VALUE="<? echo "$surname"?>" id="name2" />
ghgh</p>
<p>
<label>
<input type="submit" name="Submit" value="update" />
</label>
</p>
</form>


<?php
}else{
$dname = $_POST['dname'];
$dsurname = $_POST['dsurname'];

$con = mysql_connect("localhost", "user", "pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("mydb", $con);

mysql_query("UPDATE persons SET name = '$name' and '$surname' WHERE name = '$dname' AND surname = '$surname'");mysql_close($con);
mysql_close($con);


echo "Record updated!<br/> Would you like to <a href=\"up.php\">update</a>one more record?" ;
}
?>

</body>
</html>

Nightfire
04-25-2007, 02:04 PM
You're turning the results into an array, so you need to call the results in an array format.


$name = "name"

Will be


$name = $row['name'];
$surname = $row['surname'];

webandwe
04-25-2007, 04:33 PM
Thanks...It looks like it is almost working...The only problem now is it only shows the second entry of mysql.

Must I fix this on my coding page or the form and where/wat causes this?

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum