digitalgod Posted May 22, 2006 Share Posted May 22, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10185-update-not-updating/ Share on other sites More sharing options...
Orio Posted May 22, 2006 Share Posted May 22, 2006 I cant see where you set $prefix ... I think that's the problem.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/10185-update-not-updating/#findComment-37963 Share on other sites More sharing options...
digitalgod Posted May 22, 2006 Author Share Posted May 22, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/10185-update-not-updating/#findComment-37965 Share on other sites More sharing options...
digitalgod Posted May 22, 2006 Author Share Posted May 22, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/10185-update-not-updating/#findComment-37970 Share on other sites More sharing options...
yeshuawatso Posted May 22, 2006 Share Posted May 22, 2006 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 Link to comment https://forums.phpfreaks.com/topic/10185-update-not-updating/#findComment-37993 Share on other sites More sharing options...
digitalgod Posted May 23, 2006 Author Share Posted May 23, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/10185-update-not-updating/#findComment-38140 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.