pro_se Posted January 10, 2007 Share Posted January 10, 2007 can someone tell me why this form is not updating the database...[code] <p> <?php if(isset($_POST[Submit])) { $post_email = $_POST['email']; $youruserid = $_SESSION['userid']; mysql_query("UPDATE users SET email_address=$post_email WHERE userid='$youruserid'"); } ?><form action="settings.php" method="post"> <label>eMail Address: <input name="email" type="text" id="email" value="<?php echo "$email_address"; ?>" /> </label><br /> <label>Would you like your email address hidden?<br> <input name="pub_email" type="checkbox" id="pub_email" <?php $username = $_SESSION['username'];$sql78 = mysql_query("SELECT * FROM users WHERE username='$username'");while($row78 = mysql_fetch_array($sql78)){ $pub_email_setting = $row78['setting_email'];} if ($pub_email_setting == '0') { echo 'checked'; } ?> value="true" /> </label><br> <label> <input type="submit" name="Submit" value="Submit"> </label> </p></form>[/code] Quote Link to comment Share on other sites More sharing options...
emehrkay Posted January 10, 2007 Share Posted January 10, 2007 "UPDATE users SET email_address=$post_email WHERE userid='$youruserid'"i personally like to concat strings like this"UPDATE users SET email_address= '". $_POST['email'] ."' WHERE userid='$youruserid'"others like to do the curly braces"UPDATE users SET email_address= '{$_POST['email']}' WHERE userid='$youruserid'"either way add an or die to your mysql_query(query) or die ("<h1>there is a problem</h1>".mysql_error()); Quote Link to comment Share on other sites More sharing options...
psychohagis Posted January 10, 2007 Share Posted January 10, 2007 change your query to:[code]$sql = "UPDATE users SET email_address='$post_email' WHERE id='$youruserid'";if (@mysql_query($sql)) {echo 'Update succesful';} else {echo '<p>Error updating: ' . mysql_error() . '</p>\n';}[/code]if that doesnt work, it will tell u what is wrong Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 10, 2007 Share Posted January 10, 2007 Is the session variable $_SESSION['username'] set?If you use the "or die" clause on the query statement it will tell you if there is a mysql error:[code]<?php if(isset($_POST['Submit'])) { // you should quote all literal keys $post_email = $_POST['email']; $youruserid = $_SESSION['userid']; $q = "UPDATE users SET email_address='$post_email' WHERE userid='$youruserid'"; // strings need to be quoted in MySQL queries. mysql_query($1) or die("Problem with the query: $q<br>" . mysql_error()); } ?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.