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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.