Jump to content

Select FROM WHERE Help


Bradley99

Recommended Posts

Hi guys, I'm trying to do make this code so that IF a user owns a property (in this code a bulletfactory) then the BF CP Shows up... Here's the code so far.....

 

<?php session_start();
include_once"includes/db_connect.php";
include_once"includes/functions.php";
logincheck();
$username=$_SESSION['username'];
$query=mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch=mysql_fetch_object($query);

$query_bf=mysql_query("SELECT * FROM bf WHERE location='England, Japan, Colombia, USA, Russia, Italy, Turkey'");
$fetch_bf=mysql_fetch_object($query_bf);

if (strtolower($fetch_bf->owner) == (strtolower($fetch->username))){
require_once"bulletCP.php";
exit();
}

?>

Link to comment
https://forums.phpfreaks.com/topic/226009-select-from-where-help/
Share on other sites

$query=mysql_query("SELECT * FROM users WHERE username='$username'") or die (mysql_error());

 

lets see what error it gives you, if any.

 

Also do you understand that in location the text has to exactly look like this spaces and all or it will return 0:

 

England, Japan, Colombia, USA, Russia, Italy, Turkey

Neither of them helped sorry, maybe i should try -

 

$query_bf=mysql_query
("
   SELECT * 
   FROM bf 
   WHERE location IN ('England', 'Japan', 'Colombia', 'USA', 'Russia', 'Italy', 'Turkey')    
   AND owner = '$username'
");

if (strtolower($fetch_bf->owner) == (strtolower($fetch->username))){
echo "The BF CP Code here? Or not?

Can you try this:

 

$query_bf=mysql_query
("
   SELECT * 
   FROM bf 
   WHERE location IN ('England', 'Japan', 'Colombia', 'USA', 'Russia', 'Italy', 'Turkey')    
   AND owner = '$username'
") or die("Query failure: " . mysql_error());

$num_rows = mysql_num_rows($query_bf);
die("We got $num_rows results");

 

If it says "We got 0 results", then your query is not matching anything.  If it says 1 or more, then your fetching code should work.

  • 2 weeks later...

This is all fixed now, I'll post the working code and mark as Solved :)!!

Thanks

 

<?php session_start();
include_once"includes/db_connect.php";
include_once"includes/functions.php";
logincheck();
$username=$_SESSION['username'];
$query=mysql_query("SELECT * FROM users WHERE username='$username'") or die (mysql_error());
$fetch=mysql_fetch_object($query);

$query_bf=mysql_query
("
   SELECT * 
   FROM bf 
   WHERE location IN ('England', 'Japan', 'Colombia', 'USA', 'Russia', 'Italy', 'Turkey')    
   AND owner = '$username'
") or die("Query failure: " . mysql_error());

$num_rows = mysql_num_rows($query_bf);
require_once"bulletCP.php";

$query_airport=mysql_query
("
   SELECT * 
   FROM airport 
   WHERE location IN ('England', 'Japan', 'Colombia', 'USA', 'Russia', 'Italy', 'Turkey')    
   AND owner = '$username'
") or die("Query failure: " . mysql_error());

$num_rows = mysql_num_rows($query_airport);
require_once"airportCP.php";
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.