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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
fenway Posted August 17, 2008 Share Posted August 17, 2008 Please echo $sql. Quote Link to comment 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? ??? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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? Quote Link to comment 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.