You are here: Re: [PHP] IBM's Learning PHP Part 1 tutorial. « PHP « IT news, forums, messages
Re: [PHP] IBM's Learning PHP Part 1 tutorial.

Posted by Andrι Medeiros on 07/06/05 17:07

On Tue, 2005-07-05 at 22:36 -0400, Bill McEachran wrote:
> Newbie question.
>
> I'm working my way through IBM's PHP tutorial. Generally good ... but
> I'm stuck at an error point and have no idea what's going wrong.
> Before adding a new row to the mysql database (already opened) we do a
> query to see if a particular record already exists.
> (see $resultT).
>
> We then test, using if, to see if $resultT is true or false. If it's
> false we are then supposed to enter a new record.
> Problem: it's never false. It always evaluates true. What am I doing
> wrong? TIA
>
> /* build query to see if the record is entered already */
> $sqlT = "select * from users where username='".$_POST["name"]."'";
> $resultT = mysql_query($sqlT);
>
> /* Now test -- did we find anything ... if not add this user */
> if (! $resultT) {
> /* here we add the new record if it doesn't already exit /*
>

Although I'm not sure that will work, mysql_num_rows( $resultT ) == 1
will tell you for sure if the user exists or not.

Just remember to addslashes() to $_POST['name'] before doing that query,
so SQL can't be injected.

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация