Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
it's probably only when you load this page without submitting it.
If you submit the form, the result should be ok, I don't see any errors in your code.
The fact is, that php will run through your update code at each time the page is loaded, not only when a post is made.
It's your job to tell php when to do the update.
PHP Code:
<?php
$server = "localhost"; $username = "admin"; $password = "admin"; $database = "local_db"; $con = mysql_connect($server, $username, $password); $ok = mysql_select_db($database, $con); if(sizeof($POST)>0){ //we go in here only where there was a POST submitted $Cname = mysql_real_escape_string($_POST['newname']); $sql = "UPDATE people SET name='{$Cname}' WHERE id=1"; mysql_query($sql) or die(mysql_error()); } ?> <form method="post" action=""> <input name="newname" type="text" id="textfield"/> <input type="submit" name="change" value="Change now" /> </form>
__________________
Only a biker knows why a dog sticks his head out the window.
|