php? Posted January 2, 2008 Share Posted January 2, 2008 Now what's the problem? [uPDATED PROBLEM] *sigh* Well, according to the script below, it should display "Username ($key) is being deleted...done", or "Username ($key) is being accepted...done" But instead it displays something like this: "11 is being deleted" or "11 is being accepted " For some reason $key is being set to the ID number field of the table... not the username field <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mylogin", $con); $a = mysql_query("SELECT * FROM `pending`"); $b = mysql_num_rows($a); if($b == '0') { echo 'No pending requests at the moment.'; } else { if(!isset($_POST['submit'])) { if (!$result = mysql_query("SELECT * FROM pending")) { die('MySQL Error: ' . mysql_error()); } echo "<form method=\"POST\""; while($row = mysql_fetch_array($result)) { echo "<b>" . $row['Username']; echo "</b> "; echo "<input type=radio name=\"". $row['ID'] ."\" value=1>Accept"." <input type=radio name=\"". $row['ID'] ."\" value=2>Decline<br>"; echo " <br />"; } echo "<br><input type=submit name=submit value=Submit>"; } else { foreach($_POST as $key => $val){ if($val == 1) { $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'")); echo "$key is being accepted..."; mysql_query("INSERT INTO accepted SET Username='".$info['Username']."', Password='".$info['Password']."', Email='".$info['Email']."'"); // Moves user to new table echo "done <br>\n"; } echo "$key is being deleted..."; mysql_query("DELETE FROM pending WHERE ID='".$key."'"); echo "done <br>\n"; /* this deletes the user from the table users regardless if you selected to accept or deny. If you chose to accept the user, it runs the query above first and then this one */ } } mysql_close($con); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/ Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Okay or.... i could make it simple. How would I make it reload the admin.php page when you click submit with a little message above saying 'Requests Updated" Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427829 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 just echo it after the else(last else) and wait where is the update all i see is delete and select Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427834 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 update for what? Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427835 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 you cant use this line foreach($_POST as $key => $val) because there are lots of post that you don't need eg.. the submit ..button it will be include in your loop an what do you mean by For some reason $key is being set wrong, and I have no idea why the "submit" is there... Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427840 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Well $key is what that value is... and for some reason its not the name of the username Do you suggest that I delete the foreach($_POST as $key => $val){ or edit it Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427841 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mylogin", $con); $a = mysql_query("SELECT * FROM `pending`"); $b = mysql_num_rows($a); if($b == '0') { echo 'No pending requests at the moment.'; } else { if(!isset($_POST['submit'])) { if (!$result = mysql_query("SELECT * FROM pending")) { die('MySQL Error: ' . mysql_error()); } echo "<form method=\"POST\">"; while($row = mysql_fetch_array($result)) { echo "<b>" . $row['Username']; echo "</b> "; echo "<input type=radio name='row_s[".$row['ID']."]' value=1>"; echo "Accept"." <input type=radio name='row_s[".$row['ID']."]' value=2>Decline<br>"; echo " <br />"; } echo "<br><input type=submit name=submit value=Submit>"; } else { foreach($_POST['row_s'] as $key => $val){ // print_r($_POST['row_s']);//ro check if yuo get thevalues of chk boxes if($val == 1) { $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'")); echo "$key is being accepted..."; mysql_query("INSERT INTO accepted SET Username='".$info['Username']."', Password='".$info['Password']."', Email='".$info['Email']."'"); // Moves user to new table echo "done <br>\n"; } echo "$key is being deleted..."; mysql_query("DELETE FROM pending WHERE ID='".$key."'"); echo "done <br>\n"; /* this deletes the user from the table users regardless if you selected to accept or deny. If you chose to accept the user, it runs the query above first and then this one */ } } mysql_close($con); } ?> maybe you could try something like that Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427859 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 that solved the "submit" part ... but "16 is being deleted...done" the $key is still wrong =/ The number that is listed instead of the username goes up by 1 every time.. if that helps Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427860 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 give me sample output format you want and ill try to figure that out Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427862 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 The format doesn't matter, i can always edit it later Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427865 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 foreach($_POST['row_s'] as $key => $val){ $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'")); if($val == 1) { echo "{$info['Username']} is being accepted..."; mysql_query("INSERT INTO accepted SET Username='".$info['Username']."', Password='".$info['Password']."', Email='".$info['Email']."'"); // Moves user to new table echo "done <br>\n"; } echo "{$info['Username']} is being deleted..."; mysql_query("DELETE FROM pending WHERE ID='".$key."'"); echo "done <br>\n"; that? Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427866 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Same thing happens.. But i noticed that $key is coming up as the ID in the table instead of the Username Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427880 Share on other sites More sharing options...
Northern Flame Posted January 2, 2008 Share Posted January 2, 2008 lol i just saw ur other post on that other topic asking for help, now im reading this but I cant really see what your problem is, can you try to re-explain your problem to me? Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427887 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Alrighty there Mr. Clarification, After I click decline on a username (lets call the username "Mr. Clarification"), it deletes from the database. After it deletes it should display a message that says: 'Mr. Clarification has been deleted...'. In the code $key should be the username. But... instead it gives me a message that says: '18 has been deleted.... And 18 is the ID code of the table that the username should be taken from. Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427891 Share on other sites More sharing options...
Northern Flame Posted January 2, 2008 Share Posted January 2, 2008 lol alright, try this: <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mylogin", $con); $a = mysql_query("SELECT * FROM `pending`"); $b = mysql_num_rows($a); if($b == '0') { echo 'No pending requests at the moment.'; } else { if(!isset($_POST)) { if (!$result = mysql_query("SELECT * FROM pending")) { die('MySQL Error: ' . mysql_error()); } echo "<form method=\"POST\""; while($row = mysql_fetch_array($result)) { echo "<b>" . $row['Username']; echo "</b> "; echo "<input type=radio name=\"". $row['ID'] ."\" value=1>Accept"." <input type=radio name=\"". $row['ID'] ."\" value=2>Decline<br>"; echo " <br />"; } echo "<br><input type=submit value=Submit>"; } else { foreach($_POST as $key => $val){ if($val == 1) { $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'")); echo "$val is being accepted..."; mysql_query("INSERT INTO accepted SET Username='".$info['Username']."', Password='".$info['Password']."', Email='".$info['Email']."'"); // Moves user to new table echo "done <br>\n"; } echo "$key is being deleted..."; mysql_query("DELETE FROM pending WHERE ID='$key'"); echo "done <br>\n"; /* this deletes the user from the table users regardless if you selected to accept or deny. If you chose to accept the user, it runs the query above first and then this one */ } } mysql_close($con); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427893 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Lol now it displays no usernames to even delete from *wink* and it doesn't say: no pending requests atm anymore. Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427895 Share on other sites More sharing options...
Northern Flame Posted January 2, 2008 Share Posted January 2, 2008 lol alright then, give me a minute, im going to put this code in my notepad++ and see if I can see where the errors are Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427897 Share on other sites More sharing options...
kishan Posted January 2, 2008 Share Posted January 2, 2008 u have to use the for loop like this foreach($_POST['row_s'] as $key => $val) or in the javascript when the user checks any radio button put a cooresponding value in a hidden variable and in the php check whether if(isset($_POST['checkradio']) && $_POST['checkradio']!='') { now do the action ... } in any case as ur making the for-element like ...$rows["ID"] i think in the db it is a integer ....... if u print $key it will u like ...18,1,16...like that (or) make sure either u use a different col-name for name or use $val in php Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427962 Share on other sites More sharing options...
Northern Flame Posted January 2, 2008 Share Posted January 2, 2008 man im getting a headache, i cant figure out whats wrong, anyone else have a solution? ima try to create a similar sql table 2 urs so i can see exactly whats going wrong.... but ill do that in the morning Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-427969 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Anyone else have a solution Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-428450 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 For some reason the $key is being set as the ID field in the table instead of the Username field Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-428486 Share on other sites More sharing options...
Northern Flame Posted January 2, 2008 Share Posted January 2, 2008 replace the foreach with this: foreach($_POST['row_s'] as $key => $val){ $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'")); if($val == 1) { echo "{$info['Username']} is being accepted..."; mysql_query("INSERT INTO accepted SET Username='".$info['Username']."', Password='".$info['Password']."', Email='".$info['Email']."'"); // Moves user to new table echo "done <br>\n"; } echo "{$info['Username']} is being deleted..."; mysql_query("DELETE FROM pending WHERE Username='".$info['Username']."'"); echo "done <br>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-428611 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 t is being deleted...done 26 is being deleted...done Almost.. but now it displays 26 still =/ Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-428681 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Oh wait no... for got to edit a part!!! IT works!!!!!! thanks northern Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-428682 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Wait.. one last little error. When you click accept test is being accepted...done test is being deleted...done it still moves it to the right place.. but it just displays the deleted part for some reason Quote Link to comment https://forums.phpfreaks.com/topic/84054-solved-wrong-text/#findComment-428692 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.