...

View Full Version : If then else (may be a stupid question?)



westmatrix99
06-04-2007, 12:59 PM
This may be a stupid question but it's not working!
I have this:

if(($row_rsvote['vercode'] != 'voted') ||($row_rsvote['vercode'] != NULL)){
$MM_redirectLoginSuccess = "result.php"; //if empty
}else{
$MM_redirectLoginSuccess = "booksubmit.php"; //not empty
}
Now the objective is to go to the correct page if the field is NULL or empty.
It's just not working, any ideas WHY?
I have tried about 3 different ways no luck!

rafiki
06-04-2007, 03:19 PM
did you try


if ($row_rsvote['vercode'] == 'voted'){
$MM_redirectLoginSuccess = "booksubmit.php";
}else{
$MM_redirectLoginSuccess = "result.php";
}

also in your code you had 2 open ( on an if, which i believe is not correct


if($row_rsvote['vercode'] != 'voted' ||$row_rsvote['vercode'] != NULL){ // taken out 2 pairs of ()
$MM_redirectLoginSuccess = "result.php"; //if empty
}else{
$MM_redirectLoginSuccess = "booksubmit.php"; //not empty
}

westmatrix99
06-04-2007, 03:41 PM
Hi how are things?

The first one takes me to booksubmit.

The second one takes me to result.php, even if the field has "voted" in it?

mr e
06-04-2007, 03:49 PM
Try this


if(empty($row_rsvote['vercode'])) || ($row_rsvote['vercode'] == NULL))
{
// Empty
$MM_redirectLoginSuccess = "booksubmit.php";
}
else
{
// Not empty
$MM_redirectLoginSuccess = "result.php";
}

westmatrix99
06-04-2007, 03:56 PM
Tried that one about an hour ago.
Sorry man there must be something strange going on here.

I even tried:

header("location:booksubmit.php");

mr e
06-04-2007, 03:57 PM
Have you tried echoing out something to make sure the logic is correct?

westmatrix99
06-04-2007, 03:58 PM
Entire PHP part:


<?php
session_start();
?>
<?php require_once('Connections/cnstu2stu.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_cnstu2stu, $cnstu2stu);
$query_rsvote = "SELECT * FROM stulogin";
$rsvote = mysql_query($query_rsvote, $cnstu2stu) or die(mysql_error());
$row_rsvote = mysql_fetch_assoc($rsvote);
$totalRows_rsvote = mysql_num_rows($rsvote);
?>
<?php
// *** Validate request to login to this site.
session_start();

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}

if (isset($_POST['userid'])) {
$loginUsername=$_POST['userid'];
$password=$_POST['passid'];
$MM_fldUserAuthorization = "levelid";
// CHANGES NEEDED HERE
// if
$MM_redirectLoginSuccess = "result.php"; //if empty result
//}else{
$MM_redirectLoginSuccess = "booksubmit.php"; //not empty booksubmit
//}
///////// CHANGES END HERE
$MM_redirectLoginFailed = "loginfailed.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_cnstu2stu, $cnstu2stu);

$LoginRS__query=sprintf("SELECT StuEmail, StuPassword, levelid FROM stulogin WHERE StuEmail='%s' AND StuPassword='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $cnstu2stu) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {

$loginStrGroup = mysql_result($LoginRS,0,'levelid');

//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;

//register the session variables
session_register("MM_Username");
session_register("MM_UserGroup");

if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>

westmatrix99
06-04-2007, 03:59 PM
Have you tried echoing out something to make sure the logic is correct?
Yes; no info in echo?

westmatrix99
06-04-2007, 04:47 PM
Thank you all for your help.

Thanks again.
Cheers

mr e
06-04-2007, 07:39 PM
Try something like this to debug it, if $row_rsvote['vercode'] is empty, then it could possibly be a problem with the query or what it's returning


echo 'vercode: '. $row_rsvote['vercode'] .'<br />';

if(empty($row_rsvote['vercode']) || ($row_rsvote['vercode'] == NULL))
{
// Empty
$MM_redirectLoginSuccess = "booksubmit.php";
}
else
{
// Not empty
$MM_redirectLoginSuccess = "result.php";
}

echo $MM_redirectLoginSuccess;

aedrin
06-04-2007, 07:47 PM
But it seems that I have to fix this issue myself.

Imagine that. You have to do your own work.

You wait, what, 50 minutes? And then respond with that?

Perhaps if your code was properly formatted and not generated by Dreamweaver I would consider reading it. And perhaps others think the same.

westmatrix99
06-04-2007, 07:47 PM
I have it sorted, something I thought of which I should have thought in the beginning.
Leave the login as is and redirect to a page that can solve the query.

<?php
if ($row_rsvote['vercode'] == 'voted'){
header("Location: booksubmit.php");
}else{
header("Location: result.php");
}
?>
Problem solved.
Thank you all for your help!

westmatrix99
06-04-2007, 08:01 PM
You wait, what, 50 minutes? And then respond with that?No I do actually have a life that involves going out and meeting other people also eating 'n stuff.:D

Perhaps if your code was properly formatted and not generated by Dreamweaver I would consider reading it. And perhaps others think the same.I use dreamweaver as it is a program that I am used to working on and in.
I don't need to hand code unless needed when a program can actually do it for you.
Sorry my interpretation of a forum might be different to yours but does that mean that you and others can have the right to rag me or others just because we use a program like dreamweaver?

Don't hate the player, hate the game.:thumbsup:

aedrin
06-04-2007, 09:40 PM
No I do actually have a life that involves going out and seeing other people.

When you post a topic here, you sit and wait for an answer? You don't keep trying different solutions? You don't go do something else? That seems more like not having a life.


I use dreamweaver as it is a program that I am used to working on and in.

And that is your right, to use whatever program you want.

However, I hate generated code, because it is not formatted properly most of the time. I don't like to disect spaghetti code.


I don't need to hand code unless needed when a program can actually do it for you.

The problem is the quality of the code. If a program could do it for you, why are you solving problems with it? Why are you changing it? If it was helpful, you'd click a button and it would work.

Otherwise you're wasting your own time, as it is most likely an easy thing to do. And if you don't like recreating something others have made, then download a script (a proper one) and use that.


Sorry my interpretation of a forum might be different to yours but does that mean that you and others can have the right to rag me or others just because we use a program like dreamweaver?

I am not 'ragging' on you because of you using dreamweaver, I am 'ragging' on you because you appear impatient, and don't seem to be trying yourself. But when you use a program to code for you, how will you ever learn PHP? I don't expect it to happen any time soon. And a forum might be your only way of getting what you need.

westmatrix99
06-04-2007, 09:57 PM
PHP is not my favourite language, I prefer ASP but I am forced to use PHP as my host is the cheapest.

I do understand how to code in ASP and am learning PHP as there are always new methods to do things; I don't sit and wait for an answer, I keep trying new and other ways to solve the problem.:thumbsup:

Sorry to disappoint you but I was not brought up being spoon fed.
Why do you come afterwards to complain?:eek:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum