Page 1 of 1

[SOLVED]If- Else or what to use

Posted: Sun Jul 18, 2004 5:13 pm
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 !

Posted: Sun Jul 18, 2004 5:21 pm
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

}
?>

...

Posted: Sun Jul 18, 2004 5:23 pm
by Calimero
Thanks