Jump to content


PHP & SQL help

  • Please log in to reply
1 reply to this topic

#1 martinhynd

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 01 August 2006 - 04:48 PM

I'm "helping" a friend make a lot of changes to a website which is full of PHP and has a SQL database. I'm out of my depth here but learning fast. Everything is working now except one thing...the thing I thought would be most simple.

What I am trying to to in a PHP file is to read an entry from a database, compare what comes back to a set value and, depending if it matches that value or is different, go to one page or another.

In basic language:

look at database and get result
if result = value
go to page 1
go to page 2

The code I have in the PHP file at the moment is:

mysql_select_db(DB_DATABASE) or die("database not available");

$sql="select question from DATABASE where usernumber='$uname'";
$res=mysql_query($sql) or die(mysql_error());
if(mysql_result($res) == Premier)
header("Location: thispage.htm");
header("Location: thatpage.htm");

When it says Premier that is the value I am looking for from the database...simply the word Premier. That value is definitely in the database. I've tried it with and without quotes ... with = and == ... etc ... and I've run out of ideas.

Can someone put me out of my misery?

#2 bpops

  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 01 August 2006 - 05:17 PM

I'm not exactly sure what Premier is.. is this a variable? If not, it needs to be in quotation marks..

Otherwise, I'd recommend doing  extract($res); right after the $res=.... line.
This will take the result, and the column names will become variable names, so you can just check the condition of $usernumber against something for that if statement.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users