Jump to content

My code isn't updating my database


adamjones

Recommended Posts

Ok. So this is a form I did for user to update their details;

 

<?php
$host="localhost";
$username="wowdream_domaine";
$password="pass";
$db_name="wowdream_domaine";
$tbl_name="members";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name WHERE username='$myusername'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
	<form name="form1" method="post" action="updateaccount_ac.php">
	<fieldset>
		<label>Your Name:</label>
		<input class="small" name="name" type="text" id="name" value="<? echo $rows['name']; ?>"><br class="hid" />
	<br class="hid" />
            <label>Your Password:</label>
		<input class="small" name="pass" type="password" id="pass" value="<? echo $rows['password']; ?>"><br class="hid" />
	<br class="hid" />
		<label>Your E-Mail:</label>
		<input class="small" name="email" type="text" id="email" value="<? echo $rows['email']; ?>"><br class="hid" />
	<br class="hid" />
            <label>Contact Number:</label>
		<input class="small" name="number" type="text" id="number" value="<? echo $rows['number']; ?>"><br class="hid" />
	<br class="hid" />
		<br /><br /><br /><br /><a href="#" class="button submit" title="Submit"><span>Submit</span></a>
		<span class="clear"></span>
	</fieldset>
	</form>
        <? mysql_close();
	?>

 

And this is 'updateaccount_ac.php';

 

<? 
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>
<?php
$host="localhost"; 
$username="wowdream_domaine";
$password="pass";
$db_name="wowdream_domaine"; 
$tbl_name="members";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="UPDATE $tbl_name SET name='$name', password='$pass', email='$email', number='$number' WHERE username='$myusername'";
$result=mysql_query($sql);

if($result){
echo "GOOD";
}

else {
echo "ERROR";
}

?>

 

Thing is, It just echo's ''GOOD", and doesn't actually update the database. I have a similar one, that just updates the users password. That one work- I just can't see why this one wont!

Link to comment
https://forums.phpfreaks.com/topic/129463-my-code-isnt-updating-my-database/
Share on other sites

After you added the or die(mysql_error()) you aren't getting "GOOD" anymore?

 

Also, why are you using register_globals? Try enabling E_ALL and E_NOTICE for errors if you are just seeing a blank white page, that typically can mean an error is being suppressed.

Ok Thanks. This is the error;

 

Notice: Use of undefined constant myusername - assumed 'myusername' in /home/wowdream/public_html/domaine/admin/beta/updateaccount_ac.php on line 4

 

Notice: Undefined variable: pass in /home/wowdream/public_html/domaine/admin/beta/updateaccount_ac.php on line 18

 

...but the variables are registered, aren't they? :s

Just as it says, pass isn't being set for some reason. The myusername error's just because you didn't put quotes around it when you used it, it wouldn't stop the script from working (though you should put die() after the header redirect because the script keeps running after you redirect unless you tell it to stop.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.