Re: another php question



needaticker@xxxxxxxx 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.
.



Relevant Pages

  • PHP+informix -922, -25582 errors
    ... User apache ... I have simple script i.php with simple query to database: ... Unable to connect to Informix Database ...
    (alt.php)
  • Re: i love php but php loves mysql and mysql hates me
    ... // This script adds a entry to the database. ... // Execute the query. ... // This script retrieves header and body text from the database. ...
    (php.general)
  • Re: [PHP] Newbie question, Which way is best?
    ... When the form calls the script it passes all the parameters that the script ... SELECT query, as is, back to the same script with a way to change just the ... As a relative newbie my self I think I understand what you are trying to do. ... If potental attackers have access to your field names they can much easier try and insert stuff into your database. ...
    (php.general)
  • Re: Query Help
    ... > objects in any database. ... that parcitular script is executed, I somehow tought that it shouln't put it ... Unless I misunderstand your tables and query, ... I have seen execution plans where the subquery gets ...
    (microsoft.public.sqlserver.programming)
  • Re: Automatic Scheduled Import
    ... query to import the data I'd write a script using the DAO library to ... create and execute the query without using Access itself; ... trouble of installing Access on the server). ... >I have a database on a shared server. ...
    (microsoft.public.access.externaldata)