Jump to content


Photo

php "if" not working


  • Please log in to reply
9 replies to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 30 July 2006 - 04:20 PM

umm php "if" function isn't working again
my username is "desithugg" no capital
my table looks like this
________________
item | Owner | id
red  | desithugg | 1
________________
<?php
mysql_connect("localhost", $my_sql_password, $my_sql_username) or
   die("Could not connect: " . mysql_error());
mysql_select_db("tpf");

$result = mysql_query("SELECT owner FROM pokeballs where id = '1'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
$row = mysql_fetch_row($result);

$owner = $row[0];
?>
and btw. in the next peice the $user_currently_loged variables outputs my username
<?PHP
if ($owner != "$user_currently_loged"){
	echo "<center>Sorry the item you specified to use does not belong to you.";
	exit();
	}
?>


#2 para11ax

para11ax
  • Members
  • PipPip
  • Member
  • 21 posts
  • LocationColumbus, OH

Posted 30 July 2006 - 04:25 PM

What exactly is happening?  Is the query failing, but it's skipping the if statement?

#3 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 30 July 2006 - 04:32 PM

o sorry forgot to mention the username mataches the owner but it is still giving that error "Sorry the pokeball you specified to use does not belong to you."

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 04:34 PM

Try this please ok.

<?php

mysql_connect("localhost", $my_sql_password, $my_sql_username) or
   die("Could not connect: " . mysql_error());
mysql_select_db("tpf");

$query ="SELECT owner FROM pokeballs where id = '1' ";
$result=mysql_query($query) or die(mysql_problam());

if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
while($row=mysql_fetch_assoc($result)){

$owner = $row[0];

}
?>


<?PHP

mysql_connect("localhost", $my_sql_password, $my_sql_username) or
   die("Could not connect: " . mysql_error());
mysql_select_db("tpf");

$query ="SELECT * FROM pokeballs where id = '1' ";
$result=mysql_query($query)or die(mysql_problam());

while($row=mysql_fetch_assoc($result)){

$owner = $row[0];


if (! $owner) {
	echo "<center>Sorry the item you specified to use does not belong to you.";
	exit();
	}
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 para11ax

para11ax
  • Members
  • PipPip
  • Member
  • 21 posts
  • LocationColumbus, OH

Posted 30 July 2006 - 04:37 PM

You might also want to add "or die (mysql_error());" to your query to make sure it is executing correctly and to get an error if not:

$result = mysql_query("SELECT owner FROM pokeballs where id = '1'") or die (mysql_error());


#6 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 30 July 2006 - 04:39 PM

iv found the error for some reson
the include is not working so it compares the owner with "" a blank username im not sure why
<?php
$reqlevel = 1;
include("membersonly.inc.php");
?>

and its not working no matter which file i try to include

#7 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 30 July 2006 - 04:42 PM

umm im goind to try require

#8 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 July 2006 - 04:45 PM

If the include isn't working (or require doesn't work) why aren't you seeing the error messages???
Legend has it that reading the manual never killed anyone.
My site

#9 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 30 July 2006 - 04:47 PM

dont know its just a blank page the $user_currently_loged variable is set in the page i want to include and when i add include and try to echo the variable its not working so im assuming thats the reason

#10 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 July 2006 - 05:07 PM

<?php
error_reporting(E_ALL);
$reqlevel = 1;
include("membersonly.inc.php");
?>

Save that as test.php and run it. Tell us exactly what you see.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users