Jump to content

[SOLVED] No results, no errors


timmah1

Recommended Posts

I get no errors or no results with this.

$sport = $_GET['sports'];
$query = "SELECT * FROM articles WHERE sport = '$sport' AND publish = '".date('Y-m-d')."'";

 

If I hard-code the variables in like this

$query = "SELECT * FROM articles WHERE sport = 'nba' AND publish = '2009-01-05'";

 

Can someone tell me why?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/139616-solved-no-results-no-errors/
Share on other sites

Are you running mysql_query on the query?

 

Or you checking if it errors out? You should really do mysql_real_escape_string on $_GET['sports'] as if you have a ' in that get statement it will cause an error. And it leaves you open to SQL Injection.

When I echo $query, I get this

SELECT * FROM articles WHERE sport = 'nba' AND publish = '2009-01-05' 

 

Just what I need, but no results

 

The code is like so

$query = "SELECT * FROM articles WHERE sport = '$sport' AND publish = '".date('Y-m-d')."'";
$q = mysql_query($query);
while ($a = mysql_fetch_array($q)) {
echo $a['article'];

}

yes he did, and I've already done that

<?php
$sport = mysql_real_escape_string($_GET['sports']);
$query = "SELECT * FROM articles WHERE sport = '$sport' AND publish = '".date('Y-m-d')."'";
$q = mysql_query($query)
or die("Sorry, there was a problem selecting the articles<br /> ".mysql_error());	
while ($a = mysql_fetch_array($q)) 
{
echo $a['article'];

}
?>

 

With no results, no errors, nothing

<?php
$sport = mysql_real_escape_string($_GET['sports']);
$query = "SELECT * FROM articles WHERE sport = '$sports' AND publish = '".date('Y-m-d')."'";

 

You're using $sports in the query, and setting $sport on the line above it.  Pick one. ;)

 

 

lol sorry was funny.

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.