MySQL / PHP problem

Status
Not open for further replies.

Mike

New member
Jun 27, 2006
6,777
116
0
51
On the firing line
I'm trying to update the database when I get a postback from my affiliate company. Here's the script I'm using:

Code:
<?php

include("db.php");

$email = $_GET['email'];

$query = "UPDATE `table_name`.`info` SET `incentive` = \'1\', WHERE `info`.`email` = '.$email.';";

mysql_query($query) or die('Error, query failed');

mysql_close($database);
?>

I keep getting "Error, query failed", but I'm too tired - and apparently too stupid - to figure out why.

Help.
 


What are the periods doing in the `table_name`.`info` part of the query? Doesn't look like legal query syntax.

Also... you are escaping single quotes when the whole string in already in double quotes. That's not needed.

You also have a comma after the SET values before the WHERE clause starts.

Should be something like this:

$query = "UPDATE table_name SET incentive = 1 WHERE email = '$email'";
 
change the error reporting part to
PHP:
or die(mysql_error());
so you can figure out where the error is in your syntax and fix it.
 
man... so much wrong there... drop the stupid single quotes from phpmyadmin, and the semi at the end of the query, either drop the .'s around $email, or break the string w/ "'s, and you don't need quotes around numeric values. also, if the db isn't seleced w/ mysql_select_db('dbname'); in db.php, then do that too.
Code:
$query = "UPDATE table_name SET incentive=1 WHERE email='".$email."'";
 
You really don't need the periods at all:

$query = "UPDATE table_name SET incentive=1 WHERE email='$email'";
Should work just fine. I use that all of the time.
 
Code:
$query = "UPDATE table_name SET incentive=1 WHERE email='".$email."'";

Add some security to the query:
Code:
$query = "UPDATE table_name SET incentive=1 WHERE email='" . mysql_real_escape_string(stripslashes($email)) . "'";

This will take the slashes off of $email (if magic quotes is enabled) and then make it MySQL-safe.

After your query, you can also add in:
Code:
if (mysql_error()) {
    mail('you@yourdomain.com', 'MySQL Error', "$query\n" . mysql_error(), "From:you@yourdomain.com");
}
 
Esnagel, you don't need stripslashes() with mysql_real_escape_string. MRES is all you need.
 
Esnagel, you don't need stripslashes() with mysql_real_escape_string. MRES is all you need.

I should just try this out, but...

IF magic quotes is enabled, then "She's there" would be "She\'s there" in $_GET['whatever']

so if I ran that through MRES, it'd turn into "She\\\'s there", wouldn't it?

So put it through stripslashes, first, to get "She\'s there" back to "She's there" then MRES to get "She\'s there" again (plus any other security holes plugged)
 
well i was assuming magic gay wasn't enabled, because its the dumbest shit ever and should be disabled immediately upon php installation
 
Status
Not open for further replies.