Jump to content

Array in submit


web_master

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.