FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php if statement confusion





asiddle423
Can anybody answer me this question?

Why when i enter the exact url as what i have got in my database does it still enter the information in the database when it should run the else code instead?

This is the code below:

//run a query to check to see if url already in database
$validateURL = mysql_query("SELECT siteURL FROM Site");
while($row=mysql_fetch_row($validateURL))
{
}

if($siteURL == $row[0])
{
$result = mysql_query("SELECT custID FROM Customer");
while($row=mysql_fetch_row($result))
{
$x = $x + 2;
}

//insert into customers table
mysql_query("INSERT INTO Customer(custTitle, custForename, custSurname, custEmail)
VALUES('{$title}','{$forename}','{$surname}','{$email}')");
//insert into sites table
mysql_query("INSERT INTO Site(siteName, siteCategory, siteURL)
VALUES('{$siteName}','{$siteCategory}','{$siteURL}')");
//insert into accounts
mysql_query("INSERT INTO Account(custID, siteID)
VALUES('{$x}','{$x}')");
echo 'Registration Complete';

}
else
{
echo 'Already in database';
}
LukeakaDanish
Im not clever enough to give you an answer, but im clever enough to help you get one! Put your code inside code tags...
kv
Change your query to this

Code:
$validateURL = mysql_query("SELECT siteURL FROM Site where siteURL='".$siteURL."'");


The problem in your code is that you are getting all urls from db and going to the last one in the while loop. Just select what you want.
asiddle423
that still doesn't work for some reason :S

thanks any way this is the current code from your update

//run a query to check to see if url already in database
$validateURL = mysql_query("SELECT siteURL FROM Site where siteURL='".$siteURL."'");
while($row=mysql_fetch_row($validateURL))
{
}

if($siteURL == $row[0])
{
$result = mysql_query("SELECT custID FROM Customer");
while($row=mysql_fetch_row($result))
{
$x = $x + 2;
}

//insert into customers table
mysql_query("INSERT INTO Customer(custTitle, custForename, custSurname, custEmail)
VALUES('{$title}','{$forename}','{$surname}','{$email}')");
//insert into sites table
mysql_query("INSERT INTO Site(siteName, siteCategory, siteURL)
VALUES('{$siteName}','{$siteCategory}','{$siteURL}')");
//insert into accounts
mysql_query("INSERT INTO Account(custID, siteID)
VALUES('{$x}','{$x}')");
echo 'Registration Complete';

}
else
{
echo 'Already in database';
}
Rhysige
what is
Code:
while($row=mysql_fetch_row($validateURL))
{
}
There for?

Why not use for checking if its there

Code:

$validateURL = mysql_count_rows(mysql_query("SELECT `siteURL` FROM `Site` WHERE `iteURL`='$siteURL'"));

if($validateURL == 1){ //it exists already
Related topics
The worlds shortest and laziest Mambo tutorial.
PHP Toturail
How To : Improve Your PHP Programming
How To : Secure Your PHP Website
Ip Banning Using Php
PHP Tutorials
PHP OOP Tutorial
Inserting data to MYSQL with a PHP script
PHP login/logout problem
Indigoperl includes a copy of Apache 2.0.44, PHP 4.2.3, perl
PHP vs RUBY
FriHost PHP Parser doesn´t work?
How tough is PHP?
pls help about mysql errorr
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.