PDA

View Full Version : Simple question about adding a field with data


tvollmer
08-26-2002, 09:53 AM
Ok, I am fairly new to this whole PHP thing.

I have a script that has a form to enter a username and password.

This script then sends the username and password to a second script as variables.

Now what I want to do in the second script is this:

(after code for opening the database)

* Check to see if the username is already in the "users" table

* If the username IS in the "users" table, return an error

* if the username IS NOT in the "users" table, create a new field in the table with the username and password as data.

I this an easy thing to accomplish?

Todd

firepages
08-27-2002, 05:22 AM
<?
$yaks=mysql_query("SELECT username FROM user WHERE username='$_POST[username]'");

if(!mysql_num_rows($yaks)){
//INSERT NEW USER etc//
}else{
echo "sorry that username is already taken !";
}
?>

Spookster
08-27-2002, 05:26 AM
Ok I gotta ask....what is it with you and the word yaks? lol

firepages
08-27-2002, 06:21 AM
ok I will fess up, I know nothing of PHP.. but I got a pet Yak (Yolanda) who does, now since Yaks are not great typists - I type the stuff and Yolanda dictates (saved me a fortune in broken keyboards!) , and she always gets a credit !

err or possibly cos internally (i.e. in my head) I reserve $query && $Q for certain standard SQL queries, specifically for resourse ID's that I am happy to overwrite/reuse later in a script, for anything that may have to stay unique I use $yaks or $llama - or any other animal I can think of and $yaks is my fave (I was going to go alphabetical but $aarvark looks iffy).

So for no reason other than thats the way I write my code normally and cant get out of the habit!, no rhyme or reason!

and yes I probably need to talk to someone.

[[edit - yep that query above is disposable so I really should have used (if I follow my own methodology) $Q or $query ;)]]

Spookster
08-27-2002, 07:14 AM
lol I had to ask didn't I.