PDA

View Full Version : You have an error in your SQL syntax...


dniwebdesign
01-10-2004, 10:05 AM
<?php
////////////////////////////////////////////
// Online Application V1.0
// Author: DNI Web Design
// http://www.dniwebdesign.ca.tt
// dniwebdesign@sasktel.net
//
// SEND APPLICATION
// © 2004 DNI Web Design
////////////////////////////////////////////
session_start();
// If you change the paths please edit this.
include ("inc/config.php");



// Convert Form to PHP Variables, DO NOT EDIT!
$id=mysql_insert_id();
$fullname=$_POST["fullname"];
$address=$_POST["address"];
$telephone=$_POST["telephone"];
$applyingfor=$_POST["applyingfor"];
$dateavailable=$_POST["dateavailable"];
$email=$_POST["email"];

$highestgrade=$_POST["highestgrade"];
$university=$_POST["university"];
$major=$_POST["major"];
$yearstaken=$_POST["yearstaken"];

$medicaldefects=$_POST["medicaldefects"];
$medicalexplaination=$_POST["medicalexplanation"];

$criminaloffence=$_POST["criminaloffence"];
$criminalexplain=$_POST["criminalexplain"];
// Past Employment
$employer1=$_POST["employer1"];
$employedfrom1=$_POST["employedfrom1"];
$employedto1=$_POST["employedto1"];
$address1=$_POST["address1"];
$address1_1=$_POST["address1_1"];
$phone1=$_POST["phone1"];
$duties1=$_POST["duties1"];

$employer2=$_POST["employer2"];
$employedfrom2=$_POST["employedfrom2"];
$employedto2=$_POST["employedto2"];
$address2=$_POST["address2"];
$address2_1=$_POST["address2_1"];
$phone2=$_POST["phone2"];
$duties2=$_POST["duties2"];

$employer3=$_POST["employer3"];
$employedfrom3=$_POST["employedfrom3"];
$employedto3=$_POST["employedto3"];
$address3=$_POST["address3"];
$address3_1=$_POST["address3_1"];
$phone3=$_POST["phone3"];
$duties3=$_POST["duties3"];
// References
$reference1=$_POST["reference1"];
$refoccupation1=$_POST["refoccupation1"];
$refphone1=$_POST["refphone1"];

$reference2=$_POST["reference2"];
$refoccupation2=$_POST["refoccupation2"];
$refphone2=$_POST["refphone2"];

$reference3=$_POST["reference3"];
$refoccupation3=$_POST["refoccupation3"];
$refphone3=$_POST["refphone3"];
// Date
$date=$_POST["date"];

// ADD INFO TO DATABASE, DO NOT EDIT!!!

$result=mysql_query("INSERT into app_application ($id,$fullname,$address,$telephone,$applyingfor,$dateavailable,$email,$highestgrade,$university,$maj or,$yearstaken,$medicaldefects,$medicalexplaination,$criminaloffence,$criminalexplain,$employer1,$em ployedfrom1,$employedto1,$address1,$address1_1,$phone1,$duties1,$employer2,$employedfrom2,$employedt o2,$address2,$address2_1,$phone2,$duties2,$employer3,$employedfrom3,$employedto3,$address3,$address3 _1,$phone3,$duties3,$reference1,$refoccupation1,$refphone1,$reference2,$refoccupation2,$refphone2,$r eference3,$refoccupation3,$refphone3,$date") or print mysql_error();

if ($result)
{
mail("$admin_mail", "There was an online application submitted from ".$fullname." on ".$date.".", "The application can be viewed at ".$appsite." is waiting for approval at ".$site_title."", "From: ".$admin_name."");
echo "<p><font face='Arial' size=6><center>DONE!</center></font>";
}
else
{
echo "<p><font face='Arial' size='2'>There was an error in processing your request. Please contact the site administrator ".$admin_name." at <a href='".$admin_mail."'>".$admin_mail."</a>. Thanks and sorry for the inconvenience.</font>";
}
?>



There is the code....

Here is the 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 '0,Dawson Irvine,1501 Cumberland Ave. S.,(306) 665-8115,Webmaste

There was an error in processing your request. Please contact the site administrator Dawson Irvine at webmaster@akennstrucking.ca. Thanks and sorry for the inconvenience.

---
The last paragraph is printed by the program which is fine, just the syntax isn't.

Dylan Leblanc
01-10-2004, 10:35 AM
Those variable names which are split across two lines don't look like they are helping any

dniwebdesign
01-10-2004, 10:46 AM
Removed by DNI Web Design. Please read last post.

raf
01-10-2004, 11:53 AM
3 problems:

1 --> you need to include VALEUS in fron tof the valuelist (this is what causes the error)
valeus for string-columns need to be enclosed in quotes.
2 --> values for string-columns need to be enclosed in quotes. (this will cause your next error if you fix 1)
3 --> $id=mysql_insert_id(); --> this is probably wrong. mysql_insert_id() returns the auto-num variable of the last inserted record. (check the sticky at the top of this forum) In your case you get 0 which tels me that there wasn't a previous insert.
I don't know why you include it, but i think that you have an autonumber column in that table, and that $id is supposed to be the value for that autonumber column --> if your first column is indead an autonumber column, then you don't need to specify a value for it, sinde mySQL automatically computes and inserts it.

---> read my second post in this thread about a more secure and simply a better way to write inserts

http://www.codingforums.com/showthread.php?s=&threadid=31219
(i recon that even if you fix 1-3, that you would still would get error because the valuelist doesn't meet (the number of columns-1 ) (-1 for the autonum-column) or because the values aren't in the right order.

---> i would also fiw the broken up variablenames

dniwebdesign
01-10-2004, 07:09 PM
How would I fix it. Could you happen to give me an example of each one fixed. Thanks.

Nightfire
01-10-2004, 07:27 PM
INSERT INTO table_name ('fieldname1','fieldname2','fieldname3') VALUES ('$valueforfield1','$valueforfield2','$valueforfield3')

dniwebdesign
01-10-2004, 07:32 PM
Okay, so I need to include what column the data is going into? I though it was just how the order was in on the INSERT command. I'll give that one a shot. How about the other things raf said? So I don't need to do anything with ID? There shoulnd't be anything there?

dniwebdesign
01-11-2004, 08:10 AM
Nevermind. I decided to start over using some code I used from a different program. It adds them to the database now. However I think the problems I may have been having was that the value "date" is a keyword in PHP.