Jump to content

[SOLVED] Mysql not pulling data.


Lamez

Recommended Posts

The script below is suppose to find the user's pick, as in a football team, then take that info and pull the who the team is playing.

 

so like, say the user chose, Texas Tech, then it finds who they are playing, so it would be Ole Miss.

 

Well, it is not finding who the other team is. It does find who the user picked. Here is the script:

 

<?php
ob_start();
$path = "../../";
$title = "Choose your Teams!";
$rank = "yes";
$u_login = "yes";
$ban = "yes";
include ($path."main/include/cons/head.php");

if(siteStat() !== "Football"){ header ("Location: ../index.php"); }

	    $ck = mysql_query("SELECT `user` FROM `foot_picks` WHERE `user` = '".$user_."' LIMIT 1");
	$ck = mysql_num_rows($ck);

	if($ck == 0){
	 header("Location: ../index.php");
	}
	$v = mysql_query("SELECT * FROM `foot_picks` WHERE `user` = '".$user_."'")or die(mysql_error());
	while($n = mysql_fetch_array($v)){
	  $nt = $n['team'];

	  $a = mysql_query("SELECT * FROM `foot_bowls` WHERE `team_a` OR `team_b` = '".$nt."'")or die(mysql_error());
	  $b = mysql_fetch_array($a);
	  $team_a = $b['team_a'];
	  $team_b = $b['team_b'];
	  echo $team_a." VS ".$team_b."<br>";
  }
include ($path."main/include/cons/foot.php");		
?>

Link to comment
https://forums.phpfreaks.com/topic/137149-solved-mysql-not-pulling-data/
Share on other sites

Just a quick run over of your code:

 

SELECT * FROM `foot_bowls` WHERE `team_a` OR `team_b` = '".$nt."'

should be

SELECT * FROM `foot_bowls` WHERE `team_a` = '".$nt".' OR `team_b` = '".$nt."'

 

 

<?php
if($ck == 0){
    header("Location: ../index.php");
}
?>

should be

<?php
if($ck == 0){
    header("Location: ../index.php");
    die();
}
?>

 

and add "or die(mysql_error());"

 

to the first query as you did in your other queries for debugging purposes.

Just a quick run over of your code:

 

SELECT * FROM `foot_bowls` WHERE `team_a` OR `team_b` = '".$nt."'

should be

SELECT * FROM `foot_bowls` WHERE `team_a` = '".$nt".' OR `team_b` = '".$nt."'

 

 

<?php
if($ck == 0){
    header("Location: ../index.php");
}
?>

should be

<?php
if($ck == 0){
    header("Location: ../index.php");
    die();
}
?>

 

and add "or die(mysql_error());"

 

to the first query as you did in your other queries for debugging purposes.

 

It's bad practise to place die() and kill execution.

 

Use "or trigger_error(mysql_error())"

 

Lamez:

In my opinion:

 

$ck = mysql_query("SELECT `user` FROM `foot_picks` WHERE `user` = '".$user_."' LIMIT 1");
$ck = mysql_num_rows($ck);
      
      if($ck == 0){
       header("Location: ../index.php");
      }

 

Should be

 

$ck = mysql_query("SELECT COUNT(*) FROM foot_picks WHERE user = '".$user_."'") or trigger_error(mysql_error());
$row = mysql_fetch_row($ck);

if($row[0] == 0){
//redirect
}

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.