Mko Posted April 19, 2012 Share Posted April 19, 2012 I have this piece of code: if (isset($_POST['type1'])) { mysql_query("UPDATE tabke SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } if (isset($_POST['type2'])) { mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } if (isset($_POST['type3'])) { mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } ?> <br /> <form method="post" action=""> <input type="hidden" name="pageid" value="plyrmgmt"> <input type="hidden" name="action" value="changeBan"> <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>"> <input type="hidden" name="repid" value="<?php echo $rid; ?>"> <input type="submit" name="type1" value="Choice1" onClick="this.form.submit()"> </form> <form method="post" action=""> <input type="hidden" name="pageid" value="plyrmgmt"> <input type="hidden" name="action" value="changeMute"> <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>"> <input type="hidden" name="repid" value="<?php echo $rid; ?>"> <input type="submit" name="type2" value="Choice2" onClick="this.form.submit()"> </form> <form method="post" action=""> <input type="hidden" name="pageid" value="plyrmgmt"> <input type="hidden" name="action" value="changeLock"> <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>"> <input type="hidden" name="repid" value="<?php echo $rid; ?>"> <input type="submit" name="type3" value="Choice3" onClick="this.form.submit()"> </form> Now, for some reason when I click on Choice1, the query doesn't execute. Also, when I click on Choice2 or Choice3, the URL in my browser doesn't change for some odd reason...it stays the same as it was prior to clicking the Submit Button. Can anyone point out some errors I have? Thanks, Mark. Quote Link to comment https://forums.phpfreaks.com/topic/261246-submit-button-execute-a-query/ Share on other sites More sharing options...
trq Posted April 19, 2012 Share Posted April 19, 2012 Where is $rid defined? Quote Link to comment https://forums.phpfreaks.com/topic/261246-submit-button-execute-a-query/#findComment-1338753 Share on other sites More sharing options...
Blauv Posted April 19, 2012 Share Posted April 19, 2012 if you are trying to use an image as a submit button have a look at this it fixed it for me. Quote Link to comment https://forums.phpfreaks.com/topic/261246-submit-button-execute-a-query/#findComment-1338759 Share on other sites More sharing options...
algidDes702 Posted April 19, 2012 Share Posted April 19, 2012 When you have an empty action in a form, ie: <form method="post" action=""> it is a self serving form so the url would not change unless you made the method "GET" instead of post. "GET" puts the variables into your URL. However if you are using these forms for MySQL queries, putting the queries in the URL leaves the application open for SQL injections which can be malicious. Use echo, print, or print_r is using arrays to make sure the data being entered is what you want to be used in the database query. for example i might do this for your code: if (isset($_POST['type1'])) { echo "This was type1:" . $_POST['type1']; echo "UPDATE table SET status = 1 WHERE id = $rid"; //this will print just the database query to make sure $rid is what you want it to be //mysql_query("UPDATE tabke SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } if (isset($_POST['type2'])) { echo "This was type1:" . $_POST['type2']; echo "UPDATE table SET status = 1 WHERE id = $rid"; //this will print just the database query to make sure $rid is what you want it to be //mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } if (isset($_POST['type3'])) { echo "This was type1:" . $_POST['type3']; echo "UPDATE table SET status = 1 WHERE id = $rid"; //this will print just the database query to make sure $rid is what you want it to be //mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } ?> your code that we have is slightly uncomplete to know exactly what you are doing, we dont know where $rid is coming from. Also you said the URL doesnt change but how your forms are set up, your URL shouldnt change UNLESS your function call within the onclick "this.form.submit()" is suppose to alter the URL when hitting submit on any of the three forms. algidDes523 Quote Link to comment https://forums.phpfreaks.com/topic/261246-submit-button-execute-a-query/#findComment-1338768 Share on other sites More sharing options...
Blauv Posted April 19, 2012 Share Posted April 19, 2012 I guess I forgot the link but i was way off anyway. Quote Link to comment https://forums.phpfreaks.com/topic/261246-submit-button-execute-a-query/#findComment-1338777 Share on other sites More sharing options...
Mko Posted April 19, 2012 Author Share Posted April 19, 2012 $rid is defined as: $rid = (int) $_GET['id']; Quote Link to comment https://forums.phpfreaks.com/topic/261246-submit-button-execute-a-query/#findComment-1338917 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.