[SOLVED] fetch result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

[SOLVED] fetch result

Post by sguy »

i need to send a message to a receiver, if the user not in the database, echo the "Unknown user", if the user is in the database, then the message will be sent to the receiver
although i use mysql_fetch_row, mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_field, mysql_num_fields, mysql_num_rows
it just shows "Unknown user".....
hope you all can teach me...
thank you..

Code: Select all

$result = mysql_query("SELECT username FROM ".$DBprefix."signup WHERE username='$nickname'") or die(mysql_error()); 
 
if (mysql_fetch_field($result) != $adres) { 
echo"Unknown user";	
} else { 
$datetime = date("Y-m-d G:i:s ");
	$query = mysql_query("INSERT INTO ".$DBprefix."inbox (messageID,adres,sender,DateRecieved,title,message,isRead) values ('','$adres','$nickname','$datetime','$subject','$content','')");
	echo"Your message has been sent to $adres";
} 
} 
$result = mysql_query($query);
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

are you sure that

Code: Select all

<?php
$result = mysql_query("SELECT username FROM ".$DBprefix."signup WHERE username='$nickname'")
?>
returns a row? check it running the query directly in the DB.

I think a better approach could be asking if the [php_man]mysql_num_rows[/php_man] function returns 1.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

$result = mysql_query($query) or die('error: '. mysql_error());
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

Post by sguy »

problem solved

Code: Select all

$result = mysql_result(mysql_query("select count(*) from ".$DBprefix."signup where `username`='".$adres."'"), 0,0); 
if ($result == 0) 
{ 
echo "Unknown user"; 
} 
else 
{ 
$datetime = date("Y-m-d G:i:s ");
	$query = mysql_query("INSERT INTO ".$DBprefix."inbox (messageID,adres,sender,DateRecieved,title,message,isRead) values ('','$adres','$nickname','$datetime','$subject','$content','')");
	echo"Your message has been sent to $adres";
} 
} 
$result = mysql_query($query);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd highly suggest removing line 13.
Post Reply