arhg why wont my php script work??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Ralle
Forum Commoner
Posts: 38
Joined: Mon Oct 17, 2005 5:05 am

Post by Ralle »

can you write it?? I am not very good at messing with actions in IF-stuff
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Post by dallasx »

Code: Select all

if($num != FALSE)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

mysql_num_rows() only returns FALSE if it couldn't connect to the database, or similar such errors.

For that circumstance, the if challenge should read (in my opinion):

Code: Select all

if ($num < 1)
EDIT: You should also read up on security, in particular, SQL Injection prevention.
Ralle
Forum Commoner
Posts: 38
Joined: Mon Oct 17, 2005 5:05 am

Post by Ralle »

but $num ALWAYS output NOTHING.. I can't understand it.. $num is not less than 1, it's less than nothing at all.. know how to fix it???
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Post by dallasx »

Jenk wrote:mysql_num_rows() only returns FALSE if it couldn't connect to the database, or similar such errors.

For that circumstance, the if challenge should read (in my opinion):

Code: Select all

if ($num < 1)
EDIT: You should also read up on security, in particular, SQL Injection prevention.
Maybe his db connection string is flatlined.
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Post by dallasx »

Ralle wrote:but $num ALWAYS output NOTHING.. I can't understand it.. $num is not less than 1, it's less than nothing at all.. know how to fix it???
After your mysql_connect() and mysql_select_db() put this to see if the error is with your db connection:

Code: Select all

$link = mysql_connect("localhost", $username, $password) or die('Could not connect: ' . mysql_error());
mysql_select_db("yourDB") or die('Could not select database': . mysql_error());
Ralle
Forum Commoner
Posts: 38
Joined: Mon Oct 17, 2005 5:05 am

Post by Ralle »

I found 2 bugs that made your telling work.

Code: Select all

=<
should be

Code: Select all

<=
and

Code: Select all

$id
should be

Code: Select all

'$id'
it works perfect now!
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Post by dallasx »

Ralle wrote:I found 2 bugs that made your telling work.

Code: Select all

=<
should be

Code: Select all

<=
and

Code: Select all

$id
should be

Code: Select all

'$id'
it works perfect now!
Sweet! Where were those "bugs" at?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Theres only 1 instance of the above mentioned "bugs" in your code..
I don't see why you can't do it yourself :evil:
Ralle
Forum Commoner
Posts: 38
Joined: Mon Oct 17, 2005 5:05 am

Post by Ralle »

dallasx wrote:
Ralle wrote:I found 2 bugs that made your telling work.

Code: Select all

=<
should be

Code: Select all

<=
and

Code: Select all

$id
should be

Code: Select all

'$id'
it works perfect now!
Sweet! Where were those "bugs" at?
Just around the script. It's cool now..
Post Reply