12 Replies - 870 Views - Last Post: 26 June 2009 - 12:37 AM Rate Topic: -----

#1 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

if statement giving blank answer

Posted 25 June 2009 - 02:48 PM

Hey I'm trying to do an if statement which should be easybut it gives me no outcome...I'm trying to make a feature where if they start it, they have to invite someone else before the can do it...

So obviously once they've first begun the feature they get sent to a new page where they can invite another player...however at the moment when they go and do other things and try to come back to the page it puts them at the first page again and therefore have to repay etc...

here's what I've got so far:
<? 
$user ="SELECT username, id FROM login WHERE id= '".$_SESSION["userid"]."'"; 
$result = mysql_query($user);
while ($row = mysql_fetch_assoc ($result)){
	$username = $row['username']; 

$heist="SELECT player1, player2 FROM heist WHERE player1 = '".$username."'";
$heistresult = mysql_query($heist);
while($rowi = mysql_fetch_array($heistresult)){
	$player1 = $rowi['player1'];
	$player2 = $rowi['player2'];

if ($player1 == $username){
	if($player2 == ''){
		header ('Location: heistinvite.php');
	}else{ ?>
(You must be at least rank 2 to attempt a Heist)<br><br>

To perform a Getaway, you and your partner must be in the same state. You must use a stabled animal of your choice as well as your partner purchasing extra equipment.
It will cost you $5,000 to start a Getaway. Please be advised that once started you will not be able to cancel unless you wish to lose your deposit.<br><br>
<form action="startheist.php" method="post">
<input type="submit" value="Begin Heist">

<? }}}} ?>


Is This A Good Question/Topic? 0
  • +

Replies To: if statement giving blank answer

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,594
  • Joined: 08-August 08

Re: if statement giving blank answer

Posted 25 June 2009 - 03:30 PM

By using the two while loops, you create a situation where either the form will be output and then the header will be called, which will produce an error, or the header will be called, which will bring you to another page.

Try doing it without the while statements since userid should be unique and so should username:
<?php
$user ="SELECT username, id FROM login WHERE id= '".$_SESSION["userid"]."'"; 
$result = mysql_query($user);
$row = mysql_fetch_assoc ($result)

$username = $row['username']; 

$heist="SELECT player1, player2 FROM heist WHERE player1 = '".$username."'";
$heistresult = mysql_query($heist);
$rowi = mysql_fetch_array($heistresult)
  $player1 = $rowi['player1'];
  $player2 = $rowi['player2'];

if ($player1 == $username){
  if($player2 == ''){
    header ('Location: heistinvite.php');
  }else{ 
?>
(You must be at least rank 2 to attempt a Heist)<br><br>

To perform a Getaway, you and your partner must be in the same state. You must use a stabled animal of your choice as well as your partner purchasing extra equipment.
It will cost you $5,000 to start a Getaway. Please be advised that once started you will not be able to cancel unless you wish to lose your deposit.<br><br>
<form action="startheist.php" method="post">
<input type="submit" value="Begin Heist">

<?php }} ?>

Was This Post Helpful? 0
  • +
  • -

#3 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: if statement giving blank answer

Posted 25 June 2009 - 03:45 PM

nope still get a blank page...could it have something to do with the if statements?

so far there's no data in the heist table
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,594
  • Joined: 08-August 08

Re: if statement giving blank answer

Posted 25 June 2009 - 03:49 PM

Is this a different file than heistinvite.php?
If so, what does heistinvite.php do?

This post has been edited by CTphpnwb: 25 June 2009 - 03:49 PM

Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: if statement giving blank answer

Posted 25 June 2009 - 03:51 PM

From looking at your query I think that's the problem. If no data is returned then this statement if ($player1 == $username) will never be true (Think about it, if nothing is returned then $player1 will always be empty). I would put some test data into the table to see if that changes the outcome :)
Was This Post Helpful? 0
  • +
  • -

#6 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: if statement giving blank answer

Posted 25 June 2009 - 03:54 PM

View PostPsychoCoder, on 25 Jun, 2009 - 02:51 PM, said:

From looking at your query I think that's the problem. If no data is returned then this statement if ($player1 == $username) will never be true (Think about it, if nothing is returned then $player1 will always be empty). I would put some test data into the table to see if that changes the outcome :)


it has no data at the moment but it will do eventually...but if it has no data it should show the text below...

View PostCTphpnwb, on 25 Jun, 2009 - 02:49 PM, said:

Is this a different file than heistinvite.php?
If so, what does heistinvite.php do?


Invite another player to commit the heist with you. Remember they must be level 2 or above.<br><br>
<table border="1" bordercolor="#000000">
<tr><td>Player Invitation</td><td>(checkbox)$Player2</td>
<td><form action="heistkick.php" method="post">
<input type="submit" value="Kick!"></form></td></tr></table>
<br><br>

<form action="Heistinvitation.php" method="post">
<input type="text" name="Username"><br>
<input type="submit" value="Invite PLayer"></form>

<form action="cancelheist.php" method="post">
<input type="submit" value="Cancel Heist!"></form>


But it stays on the original page, it actually doesn't come to this page



[edit] Got it to work I think it had something to do with the if statement. so i changed it to this:

	if ($player1 == $username && $player2 == ''){
		header ('Location: heistinvite.php');
	}else{

and it seems to work for now...

thanks for the help

This post has been edited by Decypher: 25 June 2009 - 04:02 PM

Was This Post Helpful? 0
  • +
  • -

#7 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: if statement giving blank answer

Posted 25 June 2009 - 05:11 PM

didn't want to make another topic for somethin so simple I bet but I'm gettin an error with this:
$message = You have been invited to do a heist by $sender Go to the heist page to accept.; 


I know the error is due to the variable $sender within the $message variable but how do I get it so it'll work?
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,594
  • Joined: 08-August 08

Re: if statement giving blank answer

Posted 25 June 2009 - 05:12 PM

Put quotes around it:
$message = "You have been invited to do a heist by $sender Go to the heist page to accept.";

Was This Post Helpful? 0
  • +
  • -

#9 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: if statement giving blank answer

Posted 25 June 2009 - 05:17 PM

Wouldnt it have to be like this:

$message = "You have been invited to do a heist by " . $sender . "Go to the heist page to accept.";


Was This Post Helpful? 0
  • +
  • -

#10 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: if statement giving blank answer

Posted 25 June 2009 - 05:34 PM

View PostPsychoCoder, on 25 Jun, 2009 - 04:17 PM, said:

Wouldnt it have to be like this:

$message = "You have been invited to do a heist by " . $sender . "Go to the heist page to accept.";


Nope, double quotes allow you to put variables in there :)

Single quotes do not however.
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,594
  • Joined: 08-August 08

Re: if statement giving blank answer

Posted 25 June 2009 - 05:35 PM

Not with double quotes around a normal variable. If you used single quotes you'd have to do it that way, or if it were an object or an associative array I'm pretty sure you'd need to do it that way too.
Was This Post Helpful? 0
  • +
  • -

#12 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: if statement giving blank answer

Posted 25 June 2009 - 05:38 PM

cheers
Was This Post Helpful? 0
  • +
  • -

#13 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: if statement giving blank answer

Posted 26 June 2009 - 12:37 AM

View PostCTphpnwb, on 25 Jun, 2009 - 07:35 PM, said:

or if it were an object or an associative array I'm pretty sure you'd need to do it that way too.


Yeap, you would. You could also use curly braces around it, I believe, even if it's an object or associative array.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1