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 !
[SOLVED]If- Else or what to use
Moderator: General Moderators
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)
an example to see if a username is already made:
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
}
?>