Page 1 of 1

MySQL

Posted: Wed Jan 20, 2010 3:02 pm
by dannon
Well...
I have:

Code: Select all

while($info = mysql_fetch_array( $data ))
{
    $username = $info['username'];
    $password = $info['password'];
    $siteurl = $info['siteurl'];
    $email = $info['email'];
    $sitename = $info['sitename'];
    $shortdetails = $info['shortdetails'];
    $conf_code = $info['conf_code'];
    $details = $info['details'];
    
    if($info['conf_code'] == $confcode){
 
        mysql_query("INSERT INTO site (username, password, siteurl, email, sitename, shortdetails, conf_code, details) VALUES ('$username', '$password', '$siteurl', '$email', '$sitename', '$shortdetails', '$conf_code', $details)")
or die(mysql_error());
        mysql_query("DELETE FROM tempsite WHERE conf_code = '$confcode'")
or die(mysql_error());
        echo "
            <html>
    <link rel=\"stylesheet\" href=\"./style.css\" type=\"text/css\"/>
    <title>Online Servers | Home</title>
 
    <body>
";
include './includes/menu.php';
include './includes/banner.php';
echo "
<div id=\"content\">
<table id=\"content\">
    <tr>
        <td><h1>Added!</h1><p>
        Your website has been successfully added!
        </td>
    </tr>
</table>
</div>
    </body>
</html>
";
    }
 
}
How can I make it - if they will enter an invalid code it will show a different page?

For example

Code: Select all

 
if($info['conf_code'] == $confcode == null){
blah blah blah
}
 
 

Re: MySQL

Posted: Wed Jan 20, 2010 7:32 pm
by JakeJ
Try this, notice the Else statement at the bottom:

Code: Select all

 
<?php
while($info = mysql_fetch_array( $data ))
{
    $username = $info['username'];
    $password = $info['password'];
    $siteurl = $info['siteurl'];
    $email = $info['email'];
    $sitename = $info['sitename'];
    $shortdetails = $info['shortdetails'];
    $conf_code = $info['conf_code'];
    $details = $info['details'];
   
    if($info['conf_code'] == $confcode){
 
        mysql_query("INSERT INTO site (username, password, siteurl, email, sitename, shortdetails, conf_code, details) VALUES ('$username', '$password', '$siteurl', '$email', '$sitename', '$shortdetails', '$conf_code', $details)")
or die(mysql_error());
        mysql_query("DELETE FROM tempsite WHERE conf_code = '$confcode'")
or die(mysql_error());
        echo "
            <html>
    <link rel=\"stylesheet\" href=\"./style.css\" type=\"text/css\"/>
    <title>Online Servers | Home</title>
 
    <body>
";
include './includes/menu.php';
include './includes/banner.php';
echo "
<div id=\"content\">
<table id=\"content\">
    <tr>
        <td><h1>Added!</h1><p>
        Your website has been successfully added!
        </td>
    </tr>
</table>
</div>
    </body>
</html>
";
    }
    
    Else {
    header('Location: otherpage.php');
    #Assuming other page has error information
    }
 
}
?>