kev wood Posted October 21, 2008 Share Posted October 21, 2008 i have this page which contains three different forms <form name="dropdown_list" action="insert.php" method="POST"> <select name="dropdown"> <option value="constructiondb">Construction</option> <option value="electricaldb">Electrical</option> <option value="technicaldb">Technical</option> </select> </form> <br /> <form name="radio_btn" action="insert.php" method="POST"> <select name="radio"> <option value="internal">Internal News</option> <option value="general">General News</option> </select> </form> <br /> <form name="form" action="insert.php" method="POST"> Date: <input type="text" name="date" /><br /><br> Title: <input type="text" name="title" /><br /><br /> Article:<br /><textarea cols="50" rows="10" name="article" onkeyup="textLimit(this, 500);"></textarea><br /> </form> the first form is used to select the db the user wants access to and the second form is used to select which table the user will be adding the data taken from the third form into. i have tried to use javascript to submit the forms but when i go to the next page some of the variables are not being sent through. here is the page which is retrieving the data <?php if (isset($_POST['dropdown_list'])) { $db = $_POST['dropdown_list']; } if (isset($_POST['radio_btn'])) { $table = $_POST['radio_btn']; } $a = substr(mysql_escape_string($_POST['date']),0,25); $b = substr(mysql_escape_string($_POST['title']),0,25); $c = substr(mysql_escape_string($_POST['article']),0,500); $con = mysql_connect("localhost","xxxxxx","xxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db", $con); $sql= "INSERT INTO $table (date, title, article) VALUES ('$a', '$b', '$c')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> when i go to this page i am not getting any connection errors and the variables $a, $b and $c all have the data which they supposed to hold. the error that i am getting is as follows Error: You have an error in your SQL syntax near '(date, title, article) VALUES ('21/10/2008', 'The first Article', '\r\n\r\nI set' at line 1 to me this looks like the only data not being set through is the data sent from the second form. i cannot work this out any help would be great. Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/ Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 why are you using three separate forms, if they are all going to the same place via the same method? Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-670887 Share on other sites More sharing options...
kev wood Posted October 21, 2008 Author Share Posted October 21, 2008 i not sure why. i was unsure if i could get all the data i need sent over with one form. if i put it into one form how can i get the information i need from the posted variables. Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-670891 Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 <form action="insert.php" method="POST"> <select name="dropdown"> <option value="constructiondb">Construction</option> <option value="electricaldb">Electrical</option> <option value="technicaldb">Technical</option> </select> <br /> <select name="radio"> <option value="internal">Internal News</option> <option value="general">General News</option> </select> <br /> Date: <input type="text" name="date" /><br /><br> Title: <input type="text" name="title" /><br /><br /> Article:<br /><textarea cols="50" rows="10" name="article" onkeyup="textLimit(this, 500);"></textarea><br /> </form> <?php if (!isset($_POST['dropdown_list'])) { die("No DB selected"); } $db = $_POST['dropdown_list']; if (!isset($_POST['radio_btn'])) { die("No Table selected"); } $table = $_POST['radio_btn']; $a = substr(mysql_real_escape_string($_POST['date']),0,25); $b = substr(mysql_real_escape_string($_POST['title']),0,25); $c = substr(mysql_real_escape_string($_POST['article']),0,500); $con = mysql_connect("localhost","xxxxxx","xxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($db, $con); $sql= "INSERT INTO $table (date, title, article) VALUES ('$a', '$b', '$c')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-670900 Share on other sites More sharing options...
kev wood Posted October 21, 2008 Author Share Posted October 21, 2008 i have just put a submit button at the bottom of this now and it will not submit the form now i am just staying on the same page? Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-670908 Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 did you make sure and put it INSIDE the FORM tags? <form action="insert.php" method="POST"> <select name="dropdown"> <option value="constructiondb">Construction</option> <option value="electricaldb">Electrical</option> <option value="technicaldb">Technical</option> </select> <br /> <select name="radio"> <option value="internal">Internal News</option> <option value="general">General News</option> </select> <br /> Date: <input type="text" name="date" /><br /><br> Title: <input type="text" name="title" /><br /><br /> Article:<br /><textarea cols="50" rows="10" name="article" onkeyup="textLimit(this, 500);"></textarea><br /> <input type="submit" value="Submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-670913 Share on other sites More sharing options...
kev wood Posted October 21, 2008 Author Share Posted October 21, 2008 ignore the last post submit button in the wrong place. i think i have been looking at code too long for today simple things are passing me by. i have got the form submitting now just getting errors about the passwords. i have had enough for one day my eyes are sore now. i will come back tomorrow it is time for me to go home now. thanks for your help anyway i can sort the rest i think. Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-670918 Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 good luck! Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-670944 Share on other sites More sharing options...
kev wood Posted October 22, 2008 Author Share Posted October 22, 2008 is it possible to set up an if statement for the database connection. i have three options to choose from the drop down list. and depending on which option is chosen then the corresponding connection details will be used. Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-671590 Share on other sites More sharing options...
kev wood Posted October 22, 2008 Author Share Posted October 22, 2008 yes it is. i have set up a else if statement to select the different db setting and it is importing the data into the selected tables and db. thanks for all your help on this rhodesa. Link to comment https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/#findComment-671606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.