Jump to content

Archived

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

desithugg

php "if" not working

Recommended Posts

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
________________
[code]<?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];
?>[/code]
and btw. in the next peice the $user_currently_loged variables outputs my username
[code]
<?PHP
if ($owner != "$user_currently_loged"){
echo "<center>Sorry the item you specified to use does not belong to you.";
exit();
}
?>[/code]

Share this post


Link to post
Share on other sites
What exactly is happening?  Is the query failing, but it's skipping the if statement?

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
Try this please ok.

[code]
<?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];

}
?>

[/code]

[code]
<?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();
}
}
?>
[/code]

Share this post


Link to post
Share on other sites
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:

[code=php]
$result = mysql_query("SELECT owner FROM pokeballs where id = '1'") or die (mysql_error());
[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
If the include isn't working (or require doesn't work) why aren't you seeing the error messages???

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[code]<?php
error_reporting(E_ALL);
$reqlevel = 1;
include("membersonly.inc.php");
?>[/code]

Save that as test.php and run it. Tell us exactly what you see.

Share this post


Link to post
Share on other sites

×

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.