outchy Posted August 16, 2008 Share Posted August 16, 2008 I have a php form for inserting concert information into a MySQL database. Right now, I am manually entering the date in YYYY-MM-DD format and it's working good. But, I'd like to have 3 separate drop down boxes (month, day and year) and have their values be combined and submitted into the database as the variable 'dateofshow' (with the same YYYY-MM-DD format). I can make the drop downs no problem, I just need help getting the backend to work. I've tried all of the examples I could find online, but I just can't get any of them to work :/ I've zipped up my three .php files here: http://www.warehamps.org/nik/mysqlhelp.zip Any help would be MUCH appreciated. Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/ Share on other sites More sharing options...
Hooker Posted August 16, 2008 Share Posted August 16, 2008 i've not looked at the phpfiles you uploaded because i'm in a club on my phone but something along the lines of: CONCAT($_POST['year'], "-", $_POST['month'], "-", $_POST['day']) Where you would usualy enter "$dateofshow" (or "$_POST['dateofshow']") should work if you're actualy pulling out in the YYYY-MM-DD format. Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618214 Share on other sites More sharing options...
outchy Posted August 17, 2008 Author Share Posted August 17, 2008 Thanks, I will try to figure out what you said. But here are the three files as plain text: http://www.warehamps.org/nik/index.txt http://www.warehamps.org/nik/insert.txt http://www.warehamps.org/nik/add.txt Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618253 Share on other sites More sharing options...
Hooker Posted August 17, 2008 Share Posted August 17, 2008 Well, if you had 3 drop down boxes for the form to add a show called "year", "month" and "day". In insert.php you would put something like: <?php $con = mysql_connect("localhost","db","psw"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db", $con); $sql="INSERT INTO shows (dateofshow, headliner, place, opener) VALUES (CONCAT($_POST['year'], "-", $_POST['month'], "-", $_POST['day']),'$_POST[headliner]','$_POST[place]','$_POST[opener]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 show added"; mysql_close($con) ?> which would enter the date as: YYYY-MM-DD. Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618281 Share on other sites More sharing options...
outchy Posted August 17, 2008 Author Share Posted August 17, 2008 Hmm, that didn't quite work. When I try submitting the form, it just goes to a blank page. Is this line supposed to add the day, month and year values together to the 'dateofshow' variable that exists in the database? (CONCAT($_POST['year'], "-", $_POST['month'], "-", $_POST['day']),'$_POST[headliner]','$_POST[place]','$_POST[opener]')"; Sorry, I'm a bit of a noob. Here are what the files look like now on my test server: http://www.warehamps.org/nik/index2.txt http://www.warehamps.org/nik/insert2.txt http://www.warehamps.org/nik/add2.txt Any ideas what's going wrong? Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618343 Share on other sites More sharing options...
fenway Posted August 17, 2008 Share Posted August 17, 2008 Please echo $sql. Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618663 Share on other sites More sharing options...
outchy Posted August 17, 2008 Author Share Posted August 17, 2008 Please echo $sql. Okay, how do I do that? ??? Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618684 Share on other sites More sharing options...
Hooker Posted August 17, 2008 Share Posted August 17, 2008 Please echo $sql. Okay, how do I do that? ??? <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("nik", $con); $sql="INSERT INTO test (dateofshow, headliner, place, opener) VALUES (CONCAT($_POST['year'], "-", $_POST['month'], "-", $_POST['day']),'$_POST[headliner]','$_POST[place]','$_POST[opener]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo $sql; echo "1 record added"; mysql_close($con) ?> <br /><br /> <a href="http://localhost:8888/test.php">Back</a> Then submit the page as usual, when you get the blank screen look at the page source and post the sql that is shown in the page source, here. Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618707 Share on other sites More sharing options...
outchy Posted August 17, 2008 Author Share Posted August 17, 2008 Okay, when I did that, the page source itself was completely blank as well. What does that mean? Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618740 Share on other sites More sharing options...
Hooker Posted August 17, 2008 Share Posted August 17, 2008 lol, i just realised something... give this a try <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("nik", $con); $sql="INSERT INTO test (dateofshow, headliner, place, opener) VALUES (CONCAT($_POST['year'], '-', $_POST['month'], '-', $_POST['day']),'$_POST[headliner]','$_POST[place]','$_POST[opener]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo $sql; echo "1 record added"; mysql_close($con) ?> <br /><br /> <a href="http://localhost:8888/test.php">Back</a> my double quotes were possibly closing the query prematurely. If it runs fine, remove the "echo $sql;" line, if not - post the result from it. Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618747 Share on other sites More sharing options...
outchy Posted August 18, 2008 Author Share Posted August 18, 2008 Still nothing happens. When I click Submit, it just returns a blank page with nothing in the page source. Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618870 Share on other sites More sharing options...
outchy Posted August 18, 2008 Author Share Posted August 18, 2008 Hooker just PM'd me this and it totally worked! (CONCAT('$_POST[year]','-','$_POST[month]','-','$_POST[day]'),'$_POST[headliner]','$_POST[place]','$_POST[opener]')"; To all of you really, thank you so much! Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-618894 Share on other sites More sharing options...
fenway Posted August 18, 2008 Share Posted August 18, 2008 Hooker just PM'd me this and it totally worked! Could we keep the discussions to the forums, please? Link to comment https://forums.phpfreaks.com/topic/120007-solved-insert-date-into-mysql-db-using-drop-downs/#findComment-619526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.