It's as if ! != !

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

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

It's as if ! != !

Post by impulse() »

I've got the simple code to insert into a DB, which inserts fine, but I want an error message to display if a numeric field isn't numeric.

Code: Select all

$valOne = $_REQUEST["valOne"];
$valTwo = $_REQUEST["valTwo"];
$valThree = $_REQUEST["valThree"];

mysql_connect("x", "x", "x");
mysql_select_db("poll");
$q = mysql_query("SELECT * FROM test");
$numRows = mysql_numrows($q);
$count = $numRows + 1;

if (!(is_numeric($valThree))) {
  echo "Please use digits for your age"; }

else {
mysql_query("INSERT into test(count, fName, sName, age) VALUES ('$count', '$valOne', '$valTwo', '$valThree')");
echo "Inserted"; }
But this always displays "Please use digits for your age" and the insert runs fine. Can anybody see what's gone wrong?
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

Post by asgerhallas »

I'm sorry, I don't really get... does it both print "Please use digits for your age" and then also run the insert?

I've tried the script, it seems ok here... but maybe I don't understand the problem?

/Asger
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Sorry, it seems OK now. I'm not sure what happened there. Just me being a tramp I think.
Post Reply