Jump to content

UPDATE not updating..


digitalgod

Recommended Posts

hey guys,

I have a form that updates entries in a table but for some reason it doesn't update nor does it give me a MySQL error.

[code]case "editpromo":
      $process=$_POST['process'];
        if ($process == "yes") {
        $process_b=$_POST['process_b'];
        $username=$_POST['username'];
          if ($process_b == "yes") {
          $new_uname=$_POST['new_uname'];
          $new_email=$_POST['new_email'];
          $new_type=$_POST['new_type'];
          if (strlen($new_uname) < 4 || strlen($new_email) < 6) {
            $tmpl->add_template("edituser_tooshort");
            }
            else {
            echo $new_type;
            mysql_query("UPDATE ".$prefix."promo SET username='$new_uname',email='$new_email',type='$new_type' WHERE username='$username'") or die(query_error());
            $tmpl->add_template("edituser_success");
            }
          }
          else {
          $result=mysql_query("SELECT * FROM ".$prefix."promo WHERE username='$username'") or die(query_error());
          $row=mysql_fetch_array($result);
            if ($row['id'] != "") {
            $tmpl->add_template("editpromo_form2");
            }
            else {
            $tmpl->add_template("username_no");
            }
          }
        }
        else {
        $tmpl->add_template("editpromo_form1");
        }      
      break;[/code]

I even echoed $new_type to make sure the variable wasn't empty but it does return the right value.

here's my form
[code]
<div id="article">
<form action="admin.php?a=editpromo" method="post">
<input type="hidden" name="process" value="yes" />
<input type="hidden" name="process_b" value="yes" />
<input type="hidden" name="username" value="<?php echo $username; ?>" />
<table border="0">
<tr>
<td>Username:</td>
<td><input type="text" name="new_uname" value="<?php echo $username; ?>" maxlength="<?php echo $max_username; ?>" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="new_email" value="<?php echo $row['email']; ?>" maxlength="150" /></td>
</tr>
<tr>
<td>Type:</td>
<td><select name="new_type" id="new_type">
  <option value="<?php echo $row['type']; ?>"><?php echo $row['type']; ?></option>
  <option value="promoter">Promoter</option>
  <option value="hotel">Hotel</option>
</select>
</td>
</tr>
</table>
<br />
<input type="submit" value="Edit '<?php echo $username; ?>'" />
</form>
</div>
[/code]

I'm still having problems with the echos in the form, it doesn't return anything, I've been told it's a scope issue but I'm really not sure how I can fix this.

any ideas?

**edit**

ok I think I found the problem when I echo $username after the form is submitted it doesn't return anything so I'm guessing it's also a scope issue, is there any way I can fix this? It's getting frustrating
Link to comment
Share on other sites

[!--quoteo(post=376050:date=May 22 2006, 11:08 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ May 22 2006, 11:08 AM) [snapback]376050[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I cant see where you set $prefix ... I think that's the problem.

Orio.
[/quote]

$prefix is set in config.php which is included at the top of the file
Link to comment
Share on other sites

thing is I also have a delete function but it works perfectly so why doesn't the update work...?

[code]
case "delpromo":
      $process=$_POST['process'];
        if ($process == "yes") {
        $username=$_POST['username'];
        $result=mysql_query("SELECT * FROM ".$prefix."promo WHERE username='$username'") or die(query_error());
        $row=mysql_fetch_array($result);
          if ($row['id'] == "") {
          $tmpl->add_template("username_no");
          }
          else {
          mysql_query("DELETE FROM ".$prefix."promo WHERE username='$username'") or die(query_error());
          $tmpl->add_template("userdel_success");
          }
        }
        else {
        $tmpl->add_template("promodel_form");
        }      
      break;[/code]

I think that the variable gets lost when it goes to the 2nd form and that's why $username returns nothing. How can I fix this?
Link to comment
Share on other sites

[!--quoteo(post=376081:date=May 22 2006, 12:47 PM:name=Yeshua Watson)--][div class=\'quotetop\']QUOTE(Yeshua Watson @ May 22 2006, 12:47 PM) [snapback]376081[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Have you tried adding the prefix in manually to see if it will update then?

Replace the prefix with the actual prefix and test it out.
[/quote]

yup I did but it still doesn't work. Like I said the delete function works but not the update
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.