![]() |
if data is already in database
Hi I am trying to work out the following information
Lets say I have the word apple in my database and someone wants to place another apple in the db, I don't what them to be able to. I don't want to have to use the unique key to do this, however I have already. What I want to do is in the PHP if the word is in the database it ends the php code, and does not go on. I was thinking something like this. Code:
if ($row[name] =="apple'') { |
you can try the mysql_num_rows() function like this:
php Code:
I should encourage you (me too) to use mysqli objects for security reasons, but I need to learn it myself too. |
Quote:
CPU useage apparently it takes up to much? That was the excuse my server hosting company said. After tell them I leave to go somewhere else they turned it on for my account. |
Baloney, go find yourself a better web host. Any host that doesn't support MySQLi because it is too server intensive must have really bad servers (think old dell sitting in closet)!
|
Hi I am getting this error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/example/public_html/apple.php on line 14 line 14 is where the code you gave me is. Thanks |
It seems like either your query failed, or you are not passing it the correct variable (can't accurately tell because I have no code to examine i.e. sql)
|
This is my code
PHP Code:
For some reason the if statement to stop it going on an adding the new row or copying the image, it seems to ether not be checking the DB or there is something wrong with placing if statements in side else statements? |
I think the error is here:
PHP Code:
php Code:
php Code:
I prefer the first one, easy to read in text editors plus it gains a bit of speed. |
php Code:
Updated your code to include mysql injection prevention and your SQL queries to run without causing errors. If you ran the code as you posted the SQL fails because it does not properly parse the query. When you are performing SQL queries it is always easier to use single quotes for the string. @See ;http://us.php.net/manual/en/language....syntax.single For more information AND http://us2.php.net/manual/en/functio...ape-string.php For information on SQL injection |
Quote:
PHP Code:
|
| All times are GMT. The time now is 03:56 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0