PDA

View Full Version : mysql_num_rows is empty?? +rep



Blinger1
24-03-2009, 09:20 AM
G'day everyone.

I have a quick question. This is starting to piss me off to the max :eusa_wall!!

Why doesn't this code work?

<?php
include("includes/connect.php");

$sender = $_SESSION['username'];
$reciever = "lol";
$message = $_POST['message'];
$date = date("d/m/Y");
$status = "unread";

$sql = "SELECT * FROM `members` WHERE `username`='{$reciever}'";
$query = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($query) or die(mysql_error());
echo("$num_rows");
?>
The reciever is a made up name, but that should return "0" yeah?? Well, it kinda just ends the script.

The following script works:

<?php
include("includes/connect.php");

$sender = $_SESSION['username'];
$reciever = "shane";
$message = $_POST['message'];
$date = date("d/m/Y");
$status = "unread";

$sql = "SELECT * FROM `members` WHERE `username`='{$reciever}'";
$query = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($query) or die(mysql_error());
echo("$num_rows");
?>



okay, i figured it is this part (the bold one) because if i remove that part, it runs fine..:
$num_rows = mysql_num_rows($query) or die(mysql_error());

Moved by ReviewDude (Forum Moderator) from "Web Design", this is a coding-related issue.

Four
24-03-2009, 09:37 AM
why dot you remove the mysql error then?

Blinger1
24-03-2009, 09:42 AM
Because wouldn't it be safer to have that :S? And to practice 'good coding'

Four
24-03-2009, 09:47 AM
its a tiny bit safer, but if you come across these errrors and need them fixed, you have to do what it takes.
it doesnt really matter if its there or not.

sure it would practise 'good' coding, but then again, its not exactly 'bad' coding, and you could always code some different stuff

Source
24-03-2009, 11:53 AM
Its annoying when people ask for help and don't post the error in question.

Want to hide these adverts? Register an account for free!