Jump to content

form being silly...


pro_se

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/33638-form-being-silly/
Share on other sites

"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());
Link to comment
https://forums.phpfreaks.com/topic/33638-form-being-silly/#findComment-157591
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/33638-form-being-silly/#findComment-157597
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/33638-form-being-silly/#findComment-157600
Share on other sites

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.