Jump to content


Photo

UPDATE not updating..


  • Please log in to reply
5 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 22 May 2006 - 02:48 PM

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.

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;

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

here's my form
<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>

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

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 22 May 2006 - 03:08 PM

I cant see where you set $prefix ... I think that's the problem.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 22 May 2006 - 03:21 PM

[!--quoteo(post=376050:date=May 22 2006, 11:08 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ May 22 2006, 11:08 AM) View Post[/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

#4 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 22 May 2006 - 03:33 PM

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

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;

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?

#5 yeshuawatso

yeshuawatso
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 22 May 2006 - 04:47 PM

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.

#6 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 23 May 2006 - 04:06 AM

[!--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) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users