Jump to content

[SOLVED] $_GET values into queries


dadamssg

Recommended Posts

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?

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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!  ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.