Reply to Re: another php question

Your name:

Reply:


Posted by Schraalhans Keukenmeester on 09/26/05 15:02

needaticker@mail.com wrote:
> ZeldorBlat wrote:
>
>>Looks pretty good so far.
>>
>>You can check if a form variable represents a numeric string by using
>>is_numeric(). It's a little bit clearer and probably a little bit
>>faster than using ereg().
>>
>>You've already got the code in place to check that the fields are not
>>empty and that $mobile contains only numbers. So the only thing left
>>is to lookup $code in the database. The next section might look
>>something like this (pseudocode):
>>
>>$sql = "select count(*) items from code_table where code = '$code'";
>>//Run the query
>>if (items == 0) {
>>
>>}
>>
>>//Send email
>>//delete the row from the database
>
>
>
> Thanks for this but I still can't get my head around this:
>
>
> So i add:
>
>
> $username="username";
> $password="password";
> $database="databasename";
>
> mysql_connect('localhost',$username,$password);
> @mysql_select_db($database) or die( "Unable to select database");
>
>
> $sql = "select count(*) items from tablename where code = '$code'";
> //Run the query
> if (items == 0) {
> header( "Location: http://www.mysite.com/badcode.php" );
>
> }
>
>
>
>
> What do I need to add to the above to deal with the bit about checking
> that the $code value entered through the form, exists in the
> 'tablename' table. Because if I just insert as is I end up getting
> redirected to the badcode page even though the coses are in the table
> on the database.
>
>
> 1. Plus then I have the problem of deleteing the codes from the table
> on the database if there is a match!
> 2. Also even if the user gets redircted to either the badcode,
> badnumber or blanks pages, the email action keeps getting sent. How can
> I set this so that the email doesn't get sent unless noblanks, good
> mobile and good code?
>
>
> Thanks for your help. I'm learning slowly!
>
It's metacode. title isn't a var, use $sql (if you use above example).
Then I'd use the mysql_numrows() function with $sql to see if it returns
anything at all.
$sql = "Select * from yourtable where code='$code';";
mysql_query ($sql,$dbconnection);
if (0 == mysql_numrows($sql)) {
header( "Location: http://www.mysite.com/badcode.php" );
} else
{
blabla
}

Does that help?

@1: If I am right you ONLY want to delete the code and not everything
else in the record with that code it looks like this:
$sql = "delete code from yourtable where code='$code';";
// if you want to delete the entire record the query is:
// "delete from yourtable where code='$code';";
mysql_query ($sql, $dbconnection);


@2: does the script end after the redirect ? Maybe you need to insert
exit; at the proper locations to ensure the rest of the script is not
executed?

GL
SH.

[Back to original 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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация