Update Profile Script Problems...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

Update Profile Script Problems...

Post by partiallynothing »

I have a script to update my users profile, but it doesn't work. I can't find whats wrong with it. No error message either. When I hit "submit", it just reloads the page.

Here is my code:

Code: Select all

<?php
      if (isSet($_POST['submit'])) {
        if (empty($_POST['firstname']) || empty($_POST['lastname']) || empty($_POST['email'])) {
          echo "<head><meta http-equiv=refresh content="2;
          URL=index.php"></head><b>Login Invalid</b><BR>Please wait.  You will be redirected in two seconds.";
          die;
      } else {
        $query = "UPDATE users WHERE username = $username AND password = $password VALUES ('', '', '', '{$_POST['firstname']}', '{$_POST['lastname']}', '{$_POST['email']}', '', '', '', '{$_POST['backcolor']}', '', '', '')";
        $result = mysql_query($query) or die(mysql_error);
        echo "<head><meta http-equiv=refresh content="2;
          URL=index.php"></head><b>Profile Updated.<BR>You will have to log back in.</b><BR>Please wait.  You will be redirected in two seconds.";
        }
    } else {
        if ($pref_backcolor == 1) {
        $pref_backcolor_white = "selected";
        $pref_backcolor_black = "";
      } else {
        $pref_backcolor_white = "";
        $pref_backcolor_black = "selected";
      }
      echo "<td><div align="$bodyalign">
      <form action="{$_SERVER['PHP_SELF']}" method="post">
      <table width="0" cellpadding="5" cellspacing="0">
      <tr><td>First Name: </td>
      <td><input type="text" name="firstname" maxlength="50" value="$firstname"></td></tr>
      <tr><td>Last Name: </td>
      <td><input type="text" name="lastname" maxlength="50" value="lastname"></td></tr>
      <tr><td>Email: </td>
      <td><input type="text" name="email" maxlength="150" value="$email"></td></tr>
      <tr><td>Backround Color: </td>
      <td><select name="backcolor">
      <option name="1" $pref_backcolor_white>White</option>
      <option name="2" $pref_backcolor_black>Black</option>
      </select></td></tr>
      <tr>
      <td><input type="submit" name="Submit" value="Submit"></td>
      </tr>
      </forum></table></div>
      </td>
     </table></div>"; }
?>
Any help is appreciated. Thanks!
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

try..

Code: Select all

if (isSet($_POST&#1111;'Submit'])) &#123;
The name of your submit button is 'Submit'
so that is the POST var to look for.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Just be careful, if the user submits by pressing enter rather than pressing the submit button, Submit may not be set.
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

Post by partiallynothing »

xisle, I already have that code at the top, is there something I'm missing.
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

you are naming your submit button with an uppercase 'S'ubmit
but your code is checking $POST var lowercase 's'ubmit.
Post Reply