Hybride Posted August 14, 2007 Share Posted August 14, 2007 I have two search functions, one that searchs the options before bringing down the selected form, and the other to actually submit the data into the database. What happens is that if I search, it will bring the selected form down, however without the first search values (name, label) being shown if typed in; then when I do search it, I can submit the form with either pressing the search again or with pressing the submit button. I've tried doing the (if(isset($_POST['send'])) also, but it does the same thing (submit with either send/search being pressed). I just need the form to send when the submit button is pressed and keep the values in the search part to stay there instead of disappearing on me. Any help will be greatly appreciated. <table> <tr><td>Artist: </td> <td><input type="text" name="name" value="<? echo $row['name']; ?>" ></td></tr> <tr><td>Label: </td><td><input type="text" name="label" value="<? echo $row['label']; ?> "></td></tr> <tr><td> <select name="option"> <option name="featured" value="featured">Featured</option> <option name="oartist" value="oartist">Artist</option> </select> <input type="hidden" name="search" value="first"> <input type="submit" name="search" value="Search"> </td></tr></table> if (isset($_POST['search'])) { echo '<table>'; switch($option) { case "featured": print '<tr><td>Song: </td><td><input type="text" name="song"></td></tr>'; print '<tr><td>Type: </td><td><input type="text" name="type"></td></tr>'; print '<tr><td>Comment: </td><td><textarea name="comment"></textarea></td></tr>'; if ($_POST['send']) { $query = "INSERT INTO featured (name,label,song,type,comment) VALUES ('$name','$label','$song','$type','$comment')"; $result = mysql_query($query) OR die(mysql_error()); if($result) { print '<br />Data to featured (' . $name . ') has been sent!</center>'; } else { print 'Error.' . mysql_error(); } } break; case "regevnt": print '<tr><td>Description: </td><td><input type="text" name="desc"></td></tr>'; print '<tr><td>Code: </td><td><input type="text" name="code"></td></tr>'; break; } echo '</table>'; print '<center><input type="hidden" name="send" value="second">'; print '<input type="submit" name="send" value="Submit">'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64857-solved-mutiple-submit-error/ Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 Are they in two different forms? If so, that won't work. Otherwise it would be helpful to see more of your code; the form tags, in particular. Quote Link to comment https://forums.phpfreaks.com/topic/64857-solved-mutiple-submit-error/#findComment-323638 Share on other sites More sharing options...
Hybride Posted August 14, 2007 Author Share Posted August 14, 2007 Actually, it's all in the same form, just two submit buttons. This is most of the code then (I took out extra options in the select and the case to compact it) : <form action="<? echo $PHP_SELF; ?>" method="post"> <table> <tr><td>Artist: </td> <td><input type="text" name="name" value="<? echo $row['name']; ?>" ></td></tr> <tr><td>Label: </td><td><input type="text" name="label" value="<? echo $row['label']; ?> "></td></tr> <tr><td> <select name="option"> <option name="featured" value="featured">Featured</option> <option name="oartist" value="oartist">Artist</option> <option name="albumart" value="albumart">Album Art</option> </select></td> <td> <input type="hidden" name="search" value="first"> <input type="submit" name="search" value="Search"> </td></tr></table> <? require('../includes/dbconnect.php'); echo '<b>' . $option . '</b>'; if (isset($_POST['search'])) { if(empty($name)) { echo '<br /><i>Please insert a name.</i>'; } echo '<table>'; switch($option) { case "featured": print '<tr><td>Song: </td><td><input type="text" name="song"></td></tr>'; print '<tr><td>Type: </td><td><input type="text" name="type"></td></tr>'; print '<tr><td>Comment: </td><td><textarea name="comment"></textarea></td></tr>'; if ($_POST['send'] && $name) { $query = "INSERT INTO featured (name,label,song,type,comment) VALUES ('$name','$label','$song','$type','$comment')"; $result = mysql_query($query) OR die(mysql_error()); if($result) { print '<br />Data to featured (' . $name . ') has been sent!</center>'; } else { print 'Error.' . mysql_error(); } break; case "regevnt": print '<tr><td>Description: </td><td><input type="text" name="desc"></td></tr>'; print '<tr><td>Code: </td><td><input type="text" name="code"></td></tr>'; break; } echo '</table>'; print '<center><input type="hidden" name="send" value="second">'; print '<input type="submit" name="send" value="Submit">'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64857-solved-mutiple-submit-error/#findComment-323701 Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 What do you mean by "bringing down the selected form?" Quote Link to comment https://forums.phpfreaks.com/topic/64857-solved-mutiple-submit-error/#findComment-323764 Share on other sites More sharing options...
Hybride Posted August 14, 2007 Author Share Posted August 14, 2007 The first search button has a list of variables that you can search through, and if you select one (click "search"), it brings down/shows another set in relation to that variable so that you can submit the data. Basically it'd go something like this: Desert form -> Select: 1) Ice cream, 2) cake Search [submit button1] If 1) -> show: a) vanilla, b) chocolate, c) strawberry if 2) -> show: a) M&Ms, b) candy bar Submit your selection into the database. [submit button2] So there are 2 submit buttons, but the first submit button does the work of 2nd one... and I don't know how to fix that. ; I fixed the other part, where the form wasn't keeping the search variables; I had to change $row to $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/64857-solved-mutiple-submit-error/#findComment-324009 Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 Take the code out of the if (isset($_POST['search'])) { block that you want to execute by the second button and put it in a new if statement like this: if (isset($_POST['send'])) { Those are simply the names of your submit buttons. Whichever one is clicked to post on your php is the one that will be set. Quote Link to comment https://forums.phpfreaks.com/topic/64857-solved-mutiple-submit-error/#findComment-324048 Share on other sites More sharing options...
Hybride Posted August 14, 2007 Author Share Posted August 14, 2007 Well, I managed to fix it, by changing both submit names to "submit" and the "if" statement to "if($_POST['submit'] == 'Submit')". Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/64857-solved-mutiple-submit-error/#findComment-324099 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.