Re: another php question
- From: Schraalhans Keukenmeester <nomail@xxxxxxxxxx>
- Date: Mon, 26 Sep 2005 14:02:15 +0200
needaticker@xxxxxxxx wrote:
It's metacode. title isn't a var, use $sql (if you use above example).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!
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. .
- References:
- another php question
- From: needaticker
- Re: another php question
- From: ZeldorBlat
- Re: another php question
- From: needaticker
- another php question
- Prev by Date: Re: help needed - installation, debuging and variables
- Next by Date: Re: Opening page in other frame
- Previous by thread: Re: another php question
- Next by thread: Re: KARAOKE SINGERS WANTED - the world is listening!
- Index(es):
Relevant Pages
|