PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Okay so when i run this script I get the following error: "You have an error in your SQL syntax near 'key = xxx' at line 1" It does everything it is supposed to do but update the keymail table used value to "5". Anyone know what is wrong?
<?php
$email=$_POST['email'];
//Connect to database with connection script file
require 'includes/db_connect.php';
//used is not equal to zero
$sql="SELECT * FROM keymail WHERE used != '0' LIMIT 1";
$query=mysql_query($sql);
$result=mysql_fetch_object($query);
echo ("Thank you for purchasing a CD key your key is $result->key . You will also recieve an e-mail with this cd key, thank you again.");
$message="Your cd key is $result->key . Thank you again.";
$headers='From: myself@now.com'."\r\n" . ' Reply-To: stillme@now.com' ."\r\n";
$subject="Thank you for your purchase.";
mail($email,$subject,$message,$headers);
$secondsql="UPDATE keymail SET used='5' WHERE key = $result->key";
$secondquery=mysql_query($secondsql)
or die(mysql_error());
?>
surround $result->key with ' ', i.e. '$result->key' , also if 5 represents used you need to make used != 0 read used !=5 , and you need to change the myself@my.com to your actual e-mail address, did you even read the script man?:-D I posted tha tfor you a few days ago telling you it needed to be modified;)
yea I read it, but I have not changed the email address yet, i first want it working before I got into doing all of that. I have been concentrating on getting it going.
<?php
$email=$_POST['email'];
//Connect to database with connection script file
require 'includes/db_connect.php';
//used is not equal to zero
$sql="SELECT * FROM keymail WHERE used != '0' LIMIT 1";
$query=mysql_query($sql);
$result=mysql_fetch_object($query);
echo ("Thank you for purchasing a CD key your key is $result->key . You will also recieve an e-mail with this cd key, thank you again.");
$message="Your cd key is $result->key . Thank you again.";
$headers='From: mmanning@nexgentec.com'."\r\n" . ' Reply-To: mmanning@nexgentec.com' ."\r\n";
$subject="Thank you for your purchase.";
mail($email,$subject,$message,$headers);
$secondsql="UPDATE keymail SET used=0 WHERE key = '$result->key'";
$secondquery=mysql_query($secondsql)
or die(mysql_error());
?>
Thank you for purchasing a CD key your key is xxx . You will also recieve an e-mail with this cd key, thank you again.You have an error in your SQL syntax near 'key = 'xxx'' at line 1
<?php
$email=$_POST['email'];
//Connect to database with connection script file
require 'includes/db_connect.php';
//used is not equal to zero
$sql="SELECT * FROM `keymail` WHERE `used` != '0' LIMIT 1";
$query=mysql_query($sql);
$result=mysql_fetch_object($query);
echo ("Thank you for purchasing a CD key your key is {$result->key} . You will also recieve an e-mail with this cd key, thank you again.");
$message="Your cd key is {$result->key} . Thank you again.";
$headers='From: mmanning@nexgentec.com'."\r\n" . ' Reply-To: mmanning@nexgentec.com' ."\r\n";
$subject="Thank you for your purchase.";
mail($email,$subject,$message,$headers);
$secondsql="UPDATE `keymail` SET `used`=0 WHERE `key` = '{$result->key}'";
$secondquery=mysql_query($secondsql)
or die(mysql_error());
?>