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
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.

Link to comment
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.

 

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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.