Hi ive got this bit of code, trying to reteach myself stuff about PHP ive forgotten and having a general play. However i can only get this code to half work

<?php

include_once("connect.php");

$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];

$existing= "select * from CSLE_User where Username = '$username'";

$exist=mysql_query($existing) or die (mysql_error());

$num=mysql_numrows($exist) or die (mysql_error());


if($num != 0)
{
echo "<center><p>computer Says No</p></center>";
}
else
{
echo "<center><p>Test Wins</p></center>";
}
?>

I wanted the form to check weather the user being created was already in the database. It half works.

What I expect is when it finds something it posts the line "Computer says no" which works fine i have a user called A there and if i try to add another user called A it says "Computer says no"

However when i try add a user called B im expecting to see "Test Wins" but instead im presented with a blank screen.

Im sure its somthing stupid ive missed but looking though it all im not sure, also wasnt sure if this was classed as PHP or MYSQL, but as it seems the MYSQL works it must be the way ive presnted the PHP part

try changing ur test to "if $num>0 to be very sure..hope it works..i have done sumfin like that severally

Just Tried

if($num > 0)

No Change works exactly the same way.

Member Avatar for spthorn

I think your logic's just reversed. I'd do something like this:

if (mysql_numrows($exist) > 0)
  echo "There are ".mysql_numrows($exist)." users with that name.";

if ur "computer Says No" means that the user cant make use of the Username entered...then the above suggestions should work perfectly well

Turns out the problem was with the

$num=mysql_numrows($exist) or die (mysql_error());

when it was returning no value it died rather than returning 0 after removing the end part it all works now thanks for trying to help guys :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.