lukep11a Posted June 25, 2011 Share Posted June 25, 2011 Hi, I am trying to post 2 selections from radio buttons into 1 row of a mySQL table, this is my code: <form name="form1" method="post" action="new1.php"> <h2>Section 1</h2> <input type="radio" name="section1" value="Man Utd">Man Utd<br> <input type="radio" name="section1" value="Chelsea">Chelsea<br> <input type="radio" name="section1" value="Man City">Man City<br> <input type="radio" name="section1" value="Arsenal">Arsenal<br> <h2>Section 2</h2> <input type="radio" name="section2" value="Liverpool">Liverpool<br> <input type="radio" name="section2" value="Tottenham">Tottenham<br> <input type="radio" name="section2" value="Everton">Everton<br> <input type="radio" name="section2" value="Fulham">Fulham<br> <br> <input type="submit" value="Submit Team Selections"> </form> on submit, the following code is run: $section1 = $_POST['section1']; $section2 = $_POST['section2']; $query="INSERT INTO selections (section1)VALUES ('".$section1."')"; $query="INSERT INTO selections (section2)VALUES ('".$section2."')"; mysql_query($query) or die ('Error updating database'); it worked fine when i tested with only one selection, but after trying with 2 selections i found that only the second selection was posted to the mySql table. Does anybody know why this is? Any help would be very much appreciated. Thanks Luke Quote Link to comment https://forums.phpfreaks.com/topic/240378-post-multiple-columns-of-data-to-one-row/ Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2011 Share Posted June 25, 2011 You can't run two queries with one call to mysql_query(). In this case there isn't even a reason to run two queries. Validate that both values are present and valid and run one query to insert them. $query = "INSERT INTO selections ( section1, section2 ) VALUES ( '$section1', '$section2' )"; Quote Link to comment https://forums.phpfreaks.com/topic/240378-post-multiple-columns-of-data-to-one-row/#findComment-1234714 Share on other sites More sharing options...
fugix Posted June 25, 2011 Share Posted June 25, 2011 when you specify your $query value twice, you are actually overriding the first value of $query. I recommend doing something like this. $section1 = $_POST['section1']; $section2 = $_POST['section2']; $query="INSERT INTO selections (section1, section2) VALUES ('$section1', '$section2')"; mysql_query($query) or die ("Error updating database: " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/240378-post-multiple-columns-of-data-to-one-row/#findComment-1234715 Share on other sites More sharing options...
lukep11a Posted June 25, 2011 Author Share Posted June 25, 2011 Thanks for your help, knew it would be something simple! Quote Link to comment https://forums.phpfreaks.com/topic/240378-post-multiple-columns-of-data-to-one-row/#findComment-1234813 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.