Jump to content

Can you put an if and an else inside of an if?


richiejones24

Recommended Posts

hello, might be a stupid question but can you put an if and else inside of if brackets like i have done in this script?


<?php
require("../include/mysqldb.php");
$uinwish = $_GET['uinwish'];
$wishrefer = $_SERVER["HTTP_referer"];
$wishdate  = mktime(0, 0, 0, date("m"), date("d")+3, date("Y"));
$rand_wish_cookie = $_COOKIE["wishtracking"];

$con = mysql_connect("$dbhost","$dbuser","$dbpass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$dbame", $con);


$sql = "select * from Wish_list_guest where usercookie='$rand_wish_cookie' and uinwish='$uinwish'";     //search db has the profile already been added to favorites
$result = mysql_query($sql);


$row = mysql_fetch_row($result);
if (mysql_num_rows($result)!= 1) {    //if 1 of more results found profile already added redirect back!


//Re-direct back script!!
if (!isset ($wishrefer)){

$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'profile.php?uin=';
header("Location: http://$host/$extra$uinwish");
exit;

}


else { header("Location: $wishrefer");
exit;
}

//end redirect script

else {

mysql_query("INSERT INTO Wish_list_guest (usercookie, date_delete, uinwish, referwish)
VALUES ('$rand_wish_cookie', '$wishdate', '$uinwish', '$wishrefer')");


mysql_close($con);

}

if (!isset ($wishrefer)){

$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'profile.php?uin=';
header("Location: http://$host/$extra$uinwish");
exit;

}


else {
header('Location: $wishrefer');
exit;

}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.