web_master Posted May 17, 2010 Share Posted May 17, 2010 Hi, I got in one form 3 submit button, How can I put in database different values for a different Submit: Submit[1] - value 1 Submit[2] - value 2 Submit[3] - value 3 <form... <input type="submit" name="Submit[1]" value="SEND" /> <input type="submit" name="Submit[2]" value="SEND" /> <input type="submit" name="Submit[3]" value="SEND" /> .../form> if($_POST['Submit']) { $Query = mysql_query( 'INSERT INTO `table` (`Submit`) VALUES ("' . $_POST['Submit'] . '",)' ); } ?> I got problem with Array... Thnx in advanced Link to comment https://forums.phpfreaks.com/topic/202023-array-in-submit/ Share on other sites More sharing options...
scvinodkumar Posted May 17, 2010 Share Posted May 17, 2010 could u please much clearly, as per your post what i understand is, you want to store three different values separately, right? if so, if($_POST['Submit1']) $Query = mysql_query( 'INSERT INTO `table` (`Submit`) VALUES ("' . $_POST['Submit1'] . '",)' ); if($_POST['Submit2']) $Query = mysql_query( 'INSERT INTO `table` (`Submit`) VALUES ("' . $_POST['Submit2'] . '",)' ); if($_POST['Submit3']) $Query = mysql_query( 'INSERT INTO `table` (`Submit`) VALUES ("' . $_POST['Submit3'] . '",)' ); If this is not what u want, then explain? Link to comment https://forums.phpfreaks.com/topic/202023-array-in-submit/#findComment-1059405 Share on other sites More sharing options...
web_master Posted May 17, 2010 Author Share Posted May 17, 2010 OK, as You see, the value of the submit buttons is a same, but I want to put a different values in database. The submit form have a Submit[1], Submit[2] and Submit[3] names. So how can I put value "1" or value "2" or value "3" put into database that looks like: when I submit <input type="submit" name="Submit[1]" value="SEND" /> the value in database need to be 1, when I submit <input type="submit" name="Submit[2]" value="SEND" /> the value in database need to be 2, when I submit <input type="submit" name="Submit[3]" value="SEND" /> the value in database need to be 3 I hope its clearly... Link to comment https://forums.phpfreaks.com/topic/202023-array-in-submit/#findComment-1059408 Share on other sites More sharing options...
scvinodkumar Posted May 17, 2010 Share Posted May 17, 2010 Change your submit name like this, <form method="post"> <input type="submit" name="Submit1" value="SEND" /> <input type="submit" name="Submit2" value="SEND" /> <input type="submit" name="Submit3" value="SEND" /> </form> f(isset($_POST['Submit1'])) $Query = mysql_query( 'INSERT INTO `table` (`Submit`) VALUES ("' . $_POST['Submit1'] . '",)' ); f(isset($_POST['Submit2'])) $Query = mysql_query( 'INSERT INTO `table` (`Submit`) VALUES ("' . $_POST['Submit2'] . '",)' ); f(isset($_POST['Submit3'])) $Query = mysql_query( 'INSERT INTO `table` (`Submit`) VALUES ("' . $_POST['Submit3'] . '",)' ); Try this Link to comment https://forums.phpfreaks.com/topic/202023-array-in-submit/#findComment-1059423 Share on other sites More sharing options...
web_master Posted May 17, 2010 Author Share Posted May 17, 2010 Ok this can be a solution, but in file - in query - is a so many things, what I must to duplicate... - if no other solution, I will use this... Thnxs T Link to comment https://forums.phpfreaks.com/topic/202023-array-in-submit/#findComment-1059431 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2010 Share Posted May 17, 2010 Does it have to be three submit buttons? If you don't want you users to modify the value on the form, you can use either a hidden value, or a readonly field. If it has to be in the submit button, you have to realize that only one value will be sent back to your script, so <?php if (isset($_POST['submit'])) { $sub_val = implode('',$_POST['submit']); $q = "insert into `table` (`Submit`) values ('$sub_val')"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); } ?> Ken Link to comment https://forums.phpfreaks.com/topic/202023-array-in-submit/#findComment-1059442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.