Jump to content

Check username


peter11

Recommended Posts

Hi all,

 

Im new here and new to PHP. I cant work out why the following is not working. I hope you can tell me how to fix and why.

 

$checklogin=("SELECT * FROM members");

if ($checklogin==true){
echo "TAKEN";
}

else
echo "free";

 

<input name="$checklogin">
<input type="submit" title="submit">

 

What have i done wrong :S

 

thansk.

Link to comment
Share on other sites

I have connected the DB earlier in the code.

 

still cant get it to work with

 

$checklogin = mysql_query($query);

$query = ("SELECT * FROM members");

if ($query=="[username]"){
echo "TAKEN";
}

else
echo "free";

 

any help?

Link to comment
Share on other sites

Hi here is the code for your problem

 

$con = mysql_connect("hostname","mysql username","mysql password");

mysql_select_db("databse name",$con);

 

$query = "SELECT * FROM members";

$checklogin = mysql_query($query);

while($res = mysql_fetch_array($checklogin,MYSQL_ASSOC)) {

$result[] = $res;

}

 

the results will have the details

 

so now you can loop the results and you can check the conditions as your wish.

 

Let me know if you need in detail code i will provide.

 

Link to comment
Share on other sites

I have no tried this yet however it would really help if you explaned some of it for me :) as i am new to php.

 

I dont understand the following:

 

You have a $result in there. Does php carry out the $'s even if they are not linked? As i can see $checklogin says its a query then carry out $query which asks the database for this info. Once it has this info there is nouthing to tell it what to do with this is there?

 

$result[]

??

 

also

 

$query = "SELECT * FROM members";

Why are the brackets

()

not used around the select from members? Or is this not needed?

 

thanks for the help :) i hope this works.

Link to comment
Share on other sites

I have tried what you said and its saying free every time. Its connecting fine. What have i got wrong here:

 

// Connect // 

$con = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name", $con)or die("cannot select DB");

// CHECK LOGIN //

$query = ("SELECT * FROM members");
$checklogin = mysql_query($query);

while($res = mysql_fetch_array($checklogin,MYSQL_ASSOC)){
$result[] = $res;
}

if ($checklogin==$res){
echo "TAKEN";
}
else
echo "FREE";

Link to comment
Share on other sites

Hello  peter11

 

by seing your post title it seems you are checking the username with database records

 

here is the logic

----------------------

// Connect //

 

$con = mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name", $con)or die("cannot select DB");

 

// CHECK LOGIN //

 

$query = ("SELECT * FROM members WHERE username='".$_POST['username'] ."'");

$checklogin = mysql_query($query);

$res = mysql_fetch_array($checklogin,MYSQL_ASSOC);

 

if (!empty($res)){

echo "TAKEN";

}

else

echo "FREE";

 

 

Still if you are not clear let me know

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.