Jump to content

[SOLVED] Redirect and query problem


surochek

Recommended Posts

It only works if there's already a row in the table.

 

Here's the little code that has me stuck:

<?php 
session_start();
ob_start(); 
//connect with database
include("connect.php");

$user=$_SESSION['username'];
  
    $sql = "SELECT * FROM traits WHERE username = '$user'";
    $query = mysql_query($sql) or die (mysql_error(). " with query : ". $query."<br>");
	$num=mysql_num_rows($query)or die (mysql_error(). " with query : ". $num."<br>");
      
    if ($num<1){
header("Location: http://www.mashaholl.com/plotting/charactertraits_a.php");
    }
else{
header("Location: http://www.mashaholl.com/plotting/charactertraits_b.php");   
    }
    exit;
ob_end_flush(); 
?> 

 

If there are no rows that correspond to $user=$_SESSION['username'], I get this browser output:

 

with query : 0

 

Which makes sense. But not.

 

So why won't it redirect to the proper page?

Link to comment
Share on other sites

I would not do the or die on mysql_num_rows, not necessary.

 

Basically check the data in the database for the username you are entering. Also I would use $sql instead of $query in the first or die portion.

 

Give that a try and see what happens.

 

I would also print out $user to make sure it is what you expected.

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.