mediasix Posted March 19, 2008 Share Posted March 19, 2008 hi guys, i have a page that i am developing which has a few forms on it (or plans to) i am at the stage of adding the second form, i have a conditional 'submit' on the processing page. but when i submit, both of the conditionals process the form attributes. i may not be explaining very well so here is the code: <html> <head> <title>database test</title> </head> <body> <h2>currnt entries</h2> <form action="addentry.php" method="get"> Title: <input type="text" name="title"> Content: <input type="text" name="content"> <input type="submit" name="add_entry" value="DO IT!"> </form> <form action="addentry.php" method="get"> Title: <input type="text" name="title"> Content: <input type="text" name="content"> <input type="submit" name="add_entry_two" value="DO IT! 2"> </form> </body> </html> <?php include("includes/mysqlconnect.php") ?> <?php if($_REQUEST['submit']!='add_entry') { $title=$_REQUEST['title']; $content=$_REQUEST['content']; $query ="INSERT INTO test (title,content)"; $query.=" VALUES ('$title','$content')"; $result=mysql_query($query); if ($result) echo "<b>Successfully Posted!</b>"; else echo "<b>ERROR: unable to post.</b>"; } if($_REQUEST['submit']!='add_entry_two') { $title=$_REQUEST['title']; $content=$_REQUEST['content']; $query ="INSERT INTO test_two (title,content)"; $query.=" VALUES ('$title','$content')"; $result=mysql_query($query); if ($result) echo "<b>Successfully Posted! TWO</b>"; else echo "<b>ERROR: unable to post.</b>"; } else { echo "NOT WORKING BUD"; } ?> thanks in anticipation mediasix Link to comment https://forums.phpfreaks.com/topic/96884-conditional-submit/ Share on other sites More sharing options...
thebadbad Posted March 19, 2008 Share Posted March 19, 2008 Well, you're doing it wrong. You want to request 'add_entry' and 'add_entry_two', since those are the names of the submit fields. Or you could change the names to 'submit', and have different values to check for. If you stick with the former, simply do this: <?php if($_REQUEST['add_entry']) { // bla bla } ?> If you want to check the values of the submit buttons (if that's what you tried): <?php if($_REQUEST['add_entry'] == 'DO IT!') { // bla bla } ?> ... else { echo "NOT WORKING BUD"; } haha Link to comment https://forums.phpfreaks.com/topic/96884-conditional-submit/#findComment-495831 Share on other sites More sharing options...
mediasix Posted March 19, 2008 Author Share Posted March 19, 2008 OK so i've got the submission sorted, but i am faced with a new problem. i also have 2 acctions, and the first one works but the second one does nothing. code below thanks mediasix <?php include("includes/mysqlconnect.php") ?> <?php if($_REQUEST['submit']=='add_entry') { $title=$_REQUEST['title']; $content=$_REQUEST['content']; $query ="INSERT INTO test (title,content)"; $query.=" VALUES ('$title','$content')"; $result=mysql_query($query); } elseif($_REQUEST['submit']=='add_entry_two') { $title=$_REQUEST['title']; $content=$_REQUEST['content']; $query ="INSERT INTO test_two (title,content)"; $query.=" VALUES ('$title','$content')"; $result=mysql_query($query); } elseif($_REQUEST['action']="del") { mysql_query("DELETE FROM test WHERE id={$_REQUEST['id']};"); } elseif($_REQUEST['action']="del_two") { mysql_query("DELETE FROM test_two WHERE id={$_REQUEST['id']};"); } else { echo "NOT WORKING BUD"; } ?> <html> <head> <title>database test</title> <script type="text/javascript" src="scripts/prototype-1.6.0.2.js"></script> </head> <body> <div id="wrapper"> <!--ADD ENTRY FORMS--> <h2>ADD TEST ENTRY</h2> <form id="add_entry" action="index.php" method="get"> Title: <input type="text" name="title"> Content: <input type="text" name="content"> <input type="submit" name="submit" value="add_entry"> </form> <form id="add_entry_two" action="index.php" method="get"> Title: <input type="text" name="title"> Content: <input type="text" name="content"> <input type="submit" name="submit" value="add_entry_two"> </form> <!-- END OF ADD ENTRY FORMS--> <!--CURRNET ENTRIES--> <table border="0" cellpadding="0" cellspacing="0"> <?php $result=mysql_query("SELECT id,title,content FROM test ORDER BY id;"); $i=0; while( $row=mysql_fetch_array($result) ) { echo "<tr valign=center>"; echo "<td class=tabval><b>".$row['id']."</b></td>"; echo "<td class=tabval>".$row['title']." </td>"; echo "<td class=tabval>".$row['content']." </td>"; echo "<td class=tabval><a style=\"color:red;\" href=index.php?action=del&id=".$row['id'].">[Delete?]</a></td>"; echo "<td class=tabval></td>"; echo "</tr>"; $i++; } ?> </table> <!--END OFCURRNET ENTRIES--> <!--CURRNET ENTRIES TWO--> <table border="0" cellpadding="0" cellspacing="0"> <?php $result=mysql_query("SELECT id,title,content FROM test_two ORDER BY id;"); $i=0; while( $row=mysql_fetch_array($result) ) { echo "<tr valign=center>"; echo "<td class=tabval><b>".$row['id']."</b></td>"; echo "<td class=tabval>".$row['title']." </td>"; echo "<td class=tabval>".$row['content']." </td>"; echo "<td class=tabval><a style=\"color:red;\" href=index.php?action=del_two&id=".$row['id'].">[Delete?]</a></td>"; echo "<td class=tabval></td>"; echo "</tr>"; $i++; } ?> </table> <!--END OFCURRNET ENTRIES TWO--> </div><!--END OF WRAPPER--> </body> </html> Link to comment https://forums.phpfreaks.com/topic/96884-conditional-submit/#findComment-495862 Share on other sites More sharing options...
mediasix Posted March 19, 2008 Author Share Posted March 19, 2008 a lot of debugging later, i fixed it. just took out the elseif. code below. mediasix <?php include("includes/mysqlconnect.php") ?> <?php if($_REQUEST['submit']=='add_entry') { $title=$_REQUEST['title']; $content=$_REQUEST['content']; $query ="INSERT INTO test (title,content)"; $query.=" VALUES ('$title','$content')"; $result=mysql_query($query); } if($_REQUEST['submit']=='add_entry_two') { $title=$_REQUEST['title']; $content=$_REQUEST['content']; $query ="INSERT INTO test_two (title,content)"; $query.=" VALUES ('$title','$content')"; $result=mysql_query($query); } if($_REQUEST['action']="del_two") { mysql_query("DELETE FROM `test_two` WHERE `test_two`.`id`={$_REQUEST['id']};"); } if($_REQUEST['action']="del") { mysql_query("DELETE FROM test WHERE id={$_REQUEST['id']};"); } else { echo "NOT WORKING BUD"; } ?> <html> <head> <title>database test</title> </head> <body> <div id="wrapper"> <!--ADD ENTRY FORMS--> <h2>ADD TEST ENTRY</h2> <form id="add_entry" action="index.php" method="get"> Title: <input type="text" name="title"> Content: <input type="text" name="content"> <input type="submit" name="submit" value="add_entry"> </form> <form id="add_entry_two" action="index.php" method="get"> Title: <input type="text" name="title"> Content: <input type="text" name="content"> <input type="submit" name="submit" value="add_entry_two"> </form> <!-- END OF ADD ENTRY FORMS--> <!--CURRNET ENTRIES--> <h2>TABLE test</h2> <table border="0" cellpadding="0" cellspacing="0"> <?php $result=mysql_query("SELECT id,title,content FROM test ORDER BY id;"); $i=0; while( $row=mysql_fetch_array($result) ) { echo "<tr valign=center>"; echo "<td><b>".$row['id']."</b></td>"; echo "<td>".$row['title']." </td>"; echo "<td>".$row['content']." </td>"; echo "<td><a style=\"color:red;\" href=index.php?action=del&id=".$row['id'].">[Delete?]</a></td>"; echo "<td></td>"; echo "</tr>"; $i++; } ?> </table> <!--END OFCURRNET ENTRIES--> <!--CURRNET ENTRIES TWO--> <h2>TABLE test_two</h2> <table border="0" cellpadding="0" cellspacing="0"> <?php $result=mysql_query("SELECT id,title,content FROM test_two ORDER BY id;"); $i=0; while( $row=mysql_fetch_array($result) ) { echo "<tr valign=center>"; echo "<td><b>".$row['id']."</b></td>"; echo "<td>".$row['title']." </td>"; echo "<td>".$row['content']." </td>"; echo "<td><a style=\"color:red;\" href=index.php?action=del_two&id=".$row['id'].">[Delete?]</a></td>"; echo "<td></td>"; echo "</tr>"; $i++; } ?> </table> <!--END OFCURRNET ENTRIES TWO--> </div><!--END OF WRAPPER--> </body> </html> Link to comment https://forums.phpfreaks.com/topic/96884-conditional-submit/#findComment-495906 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.