Jump to content

what problem in this code


blacktiger786

Recommended Posts

<?php
require 'databaseconnect.php';
if(isset($_POST['username']))
{
$username=$_POST['username'];
$query="SELECT `username` FROM `user` WHERE `username`='$username'";
if($run=mysql_query($query))
{

if(mysql_num_rows($run)==1)
{
echo 'user already exist';
}
else
{
echo'its fine';
}
}
}
?>


<form method="post" action="11.php">
<input name="username" type="text"/><br>
<input name="submit" type="submit"/>
</form>

like i enter blacktiger this user already in my database but when i click on button its show

its fine echo run .. why is not run user already exist..

Link to comment
https://forums.phpfreaks.com/topic/283512-what-problem-in-this-code/
Share on other sites

I would check that there is none with that username, if you have 2 or more already stored while comparing with "1", it will always allow yet another one.

if(mysql_num_rows($run) === 0){
  echo 'nobody with that username was found in database';
}
else{
  echo 'You cannot use this username';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.