dadamssg Posted March 5, 2009 Share Posted March 5, 2009 ok, this is my url http://www.mysite.com/test/number.php?days=1 and this the php/mysql part of the script to get that number and insert it into a query, it just displays Couldn't Execute. How do i go about gettin this sucker to work? $days = $_GET["days"]; $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("Couldn't connect"); $quer = "SELECT * FROM test WHERE DATE(DATE_ADD(CURDATE(), INTERVAL $days DAYS)) BETWEEN DATE(start) AND DATE(end) ORDER BY start ASC"; $rsult = mysqli_query($cxn,$quer) or die ("Couldn't execute"); the query works in phpMyAdmin if replace $days to a number, what in the world am i doin wrong? Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/ Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 def didn't know it was going to make my fake url a link... Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776892 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 DAYS should be DAY. Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776896 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 thanks but that wasn't it, should $day be in parenthesis, quotes, apostrophes, brackets, or anything like that? <?php include("caneck.inc"); $days = $_GET["days"]; $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("Couldn't connect"); $quer = "SELECT * FROM test WHERE DATE(DATE_ADD(CURDATE(), INTERVAL $days DAY)) BETWEEN DATE(start) AND DATE(end) ORDER BY start ASC"; $rsult = mysqli_query($cxn,$quer) or die ("Couldn't execute"); Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776907 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 No. Numeric values are almost never [need to be] enclosed in quotes in queries. (One exception is when setting a textual field to a numeric value.) Instead of die("Couldn't execute") which is entirely useless, replace "Couldn't execute" with mysqli_error($cxn). Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776910 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 but thats what i want...i want the $days to be a numeric value....? Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776920 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 Uhhh.... I said that you don't need to put it in quotes. Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776939 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 i guess im misunderstanding you..either way, this isn't working and i don't know what i need to do to grab that number out of the url and use it in my query $days = $_GET["days"]; $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("Couldn't connect"); $quer = "SELECT * FROM test WHERE DATE(DATE_ADD(CURDATE(), INTERVAL $days DAY)) BETWEEN DATE(start) AND DATE(end) ORDER BY start ASC"; $rsult = mysqli_query($cxn,$quer) or die ("Couldn't execute"); Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776947 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 Please do my suggestion and change the code to: or die (mysqli_error($cxn)); The error message "Couldn't execute" might mean something, but an actual error message would be much more useful for debugging. Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776954 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 corbin..i love you. thanks for stickin with me! i got it $days = $_GET["days"]; $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("Couldn't connect"); $quer = "SELECT * FROM test WHERE DATE(DATE_ADD(CURDATE(), INTERVAL $days DAY)) BETWEEN DATE(start) AND DATE(end) ORDER BY start ASC"; $rsult = mysqli_query($cxn,$quer) or die (mysqli_error($cxn)); not real sure what i tweaked that make it work, but its workin! Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776971 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 No idea why that made it work, but what ever ;p. Quote Link to comment https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/#findComment-776979 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.