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
https://forums.phpfreaks.com/topic/148015-solved-_get-values-into-queries/
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");

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.