RE: [PHP-DB] If syntax

From: Date: Mon, 03 Oct 2005 00:11:27 +0000
Subject: RE: [PHP-DB] If syntax
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-40449@lists.php.net to get a copy of this message
true, i suppose, A better example would be $result = mysql_query($query); if ($result){ if (mysql_num_rows($result)>0) { echo "Alias already in use"; } else { echo "Unique alias"; } }else{ echo " db error:".mysql_error(); } mysql_close(); bastien
From: RaJeSh VeNkAtA <rajesh_v@students.iiit.net> To: Bastien Koert <bastien_k@hotmail.com> CC: ron.php@actsministries.org, php-db@lists.php.net Subject: RE: [PHP-DB] If syntax Date: Sun, 2 Oct 2005 22:25:16 +0530 (IST) think this is wrong ... as it gives unique alias even if the query is not executed .. rajesh On Sun, 2 Oct 2005, Bastien Koert wrote:
you need to check the num of rows returned, since the query always(if it works) returns true $result = mysql_query($query); if (($result)&&(mysql_num_rows($result)==1)) { echo "Alias already in use"; } else { echo "Unique alias"; mysql_close(); } Bastien
From: "Ron Piggott" <ron.php@actsministries.org> Reply-To: "Ron Piggott" <ron.php@actsministries.org> To: "PHP DB" <php-db@lists.php.net> Subject: [PHP-DB] If syntax Date: Sat, 1 Oct 2005 22:28:46 -0500 Take a look at my if ( ) syntax line below. I am wondering if I have it wrong in same way. What I am trying to achieve is if the alias the user enters is already found in the database I want the words "Alias already in use" to be shown on the screen; otherwise "Unique alias" to be shown on the screen. PRESENTLY alias already in use is what comes up all the time. Ron mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM tablename WHERE alias LIKE '$alias%'"; if (mysql_query($query)) { echo "Alias already in use"; } else { echo "Unique alias"; mysql_close(); } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- ********************************************************************************************* You wouldn't know an OS if it hit you in the face ... Linux Baby ! ********************************************************************************************* -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.db (#40449) next »