Jump to content


Error in SQL Syntax


2 replies to this topic

#1 Supreme Hobo

    Young Padawan

  • Members
  • Pip
  • 42 posts
  • Location:United Kingdom

Posted 18 August 2006 - 03:00 PM

Hi All

I'm working on an Escrow payments system for a Project I'm working on. I keep getting errors with it, and I can't see where I've gone wrong. When a user wishes to make an escrow payment, they type in the name of the recipient, the amount, and they select a reason from a listmenu. When they click submit, the form goes to the following script:

<?php require_once('Connections/pbmddb.php'); ?>
<?php
$colname_userfrom = "-1";
if (isset($_POST['from'])) {
  $colname_userfrom = (get_magic_quotes_gpc()) ? $_POST['from'] : addslashes($_POST['from']);
}
mysql_select_db($database_pbmddb, $pbmddb);
$query_userfrom = sprintf("SELECT * FROM `user` WHERE username = '%s'", $colname_userfrom);
$userfrom = mysql_query($query_userfrom, $pbmddb) or die(mysql_error());
$row_userfrom = mysql_fetch_assoc($userfrom);
$totalRows_userfrom = mysql_num_rows($userfrom);

$userto = $_POST['payto'];
$amount = $_POST['amount'];
$reason = $_POST['reason'];
$from = $_POST['from'];
$commission = ceil($amount * 1.1);
$money = $row_userfrom['money'];
$deduct = $money - $commission;
$id = $row_userfrom['genid'];

if ($commission > $money) {
  echo "You do not have enough money in your account to make this payment.";
}
if (($userto !== "") && ($amount !== "") && ($from !== "") && ($commission <= $money)) {
  $newpay = "INSERT INTO escrow (id, from, to, amount, reason) VALUES ('', '$from', '$userto', '$amount', '$reason')";
  mysql_query($newpay) or die(mysql_error());

  $takepay = "UPDATE `user` SET `money`='$amount' WHERE `id`='$id' LIMIT 1;";
  mysql_query($takepay) or die(mysql_error());
  include("escrow_skip.php");
}

mysql_free_result($userfrom);
?>

When I tested this, I get the following error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, amount, reason) VALUES ('', 'AndyMills', 'mruser', '2

Can anyone spot where I've gone wrong. I can't figure it out. Thanks!

#2 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 18 August 2006 - 03:21 PM

 $newpay = "INSERT INTO escrow (`id`, `from`, `to`, `amount`, `reason`) //.......

try that ^_^

#3 Supreme Hobo

    Young Padawan

  • Members
  • Pip
  • 42 posts
  • Location:United Kingdom

Posted 18 August 2006 - 03:40 PM

View Post.Matt, on Aug 18 2006, 09:20 PM, said:

 $newpay = "INSERT INTO escrow (`id`, `from`, `to`, `amount`, `reason`) //.......

try that :beat:

Ahh thank you! I can't believe I made such a silly error ^_^ . Cheers again!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users