Jump to content

Recommended Posts

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">';
}
              ?>

Link to comment
https://forums.phpfreaks.com/topic/64857-solved-mutiple-submit-error/
Share on other sites

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">';
}
  ?>

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.