RE: [PHP] php $query help

From: Date: Mon, 06 Jan 2003 16:29:37 +0000
Subject: RE: [PHP] php $query help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-130432@lists.php.net to get a copy of this message
First, try to complete that query by executing it. You do that by adding the next couple of lines right after the $query: $result = mysql_query($query); // supposing you already established the connection and that you use MySQL. $num_rows = mysql_num_rows($result); // To count how many matches where found Then compare the names that you have stored with the new one like: if ($num_rows > 0) { echo "Sorry, that name is taken"; } else ($num_rows == 0) { echo "Welcome ".$name.""; } This is made from memory, so it might not work right on. Hope it helps, Cesar L. Aracena icaam@icaam.com.ar caracena@infovia.com.ar (0299) 156-356688 Neuquén (8300) Capital Argentina -----Mensaje original----- De: - [ Paul Ferrie ] - [mailto:info@innovativedesigns.org.uk] Enviado el: lunes, 06 de enero de 2003 10:16 Para: php-general@lists.php.net Asunto: [PHP] php $query help Here is my problem I have created a user login system (flash+php+mysql) And it just about works Here's the prob when i go to register as a new user the code wont properly check to see if the username already exsist's in the DB, I am pretty sure the problem lies in my first $query PHP:-------------------------------------------------------------------- ---- ------ $query = "SELECT name FROM contacts WHERE name='$name'"; if ($name == $name) { print "loginT=UserName in Use"; }else{ $query = "INSERT INTO contacts (name, pass, email, id) VALUES ('$name', '$pass', '$email', NULL);"; } $result = mysql_query($query); // Gets the number of rows affected by the query as a check. $numR = mysql_affected_rows($Connect); if ($numR == 0) { // Sends output to flash print "loginT=Error - Register Again"; } else if ($numR == 1) { // Sends output to flash print "loginT=Success&checklog=1"; } ------------------------------------------------------------------------ ---- -- If i take out PHP:-------------------------------------------------------------------- ---- ------ $query = "SELECT name FROM contacts WHERE name='$name'"; if ($name == $name) { print "loginT=UserName in Use"; ------------------------------------------------------------------------ ---- -- THe login system works fine but dupilcate entries can be submitted to the database. Please help i would love to get this up and running Cheers -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#130432) next »