[SOLVED]If- Else or what to use

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

[SOLVED]If- Else or what to use

Post by Calimero »

what must be done:

connect to first db see if username exists, if yes (return Sorry etc..)

if not (connect to second db, check if username exists there,) if yes, (again sorry )
if not (its ok to use this one)

Need just to solve IF- ELSE or IF=ELSEIF-ELSE loop,

How would you do it?
Thanks Ahead !
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

if you dont know how to connect to a db, you need not worry about if - else statements, but you need to google for some mysql/ php tutorials cause thats bad (no offense)

:roll:

an example to see if a username is already made:

Code: Select all

<?php
$sql = "SELECT * FROM table_name WHERE username='$name'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$user = $row['username'];
 if (!$user == "") {
echo "The username is already in use, choose another";
} else {

// use the INSERT query

}

// another method most people use is mysql_num_rows(), ie:

$sql = "SELECT * FROM table_name WHERE username='$name'";
$result = mysql_query($sql);
$row = mysql_num_rows($result);


if ($row >= 1) {
echo "The username is already in use, choose another";
} else {

//Insert query

}
?>
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

Thanks
Post Reply