Jump to content

Recommended Posts

Here is my error:

[quote]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 '.')' at line 1[/quote]

Im not quite sure where it is here are my scripts im using:

db.php

[code]<?php

# Database connect script
# You can edit the next four lines

$db_host = 'db411.perfora.net';
$db_user = 'dbo168663394';
$db_pass = 'w.N6n7gG';
$db_name = 'db168663394';

# Under here DONT TOUCH!!!
$connection = mysql_pconnect("$db_host","$db_user","$db_pass")
or die("Couldn't connect to server");
$db = mysql_select_db("$db_name", $connection)
or die("Couldn't select database");
?>[/code]

edit_match.php
[code]
<?php
include("db.php");

# get variables
$game = $_POST['game'];
$opponent = $_POST['opponent'];
$score1 = $_POST['score1'];
$score2 = $_POST['score2'];
$date = $_POST['date'];
$league = $_POST['league'];
$map = $_POST['map'];
$description = $_POST['description'];

# out with any unwanted characters
$game = stripslashes($game);
$opponent = stripslashes($opponent);
$score1 = stripslashes($score1);
$score2 = stripslashes($score2);
$date = stripslashes($date);
$league = stripslashes($league);
$map = stripslashes($map);
$description = stripslashes($description);

if((!$opponent) || (!$map) || (!$description)){
echo "The following are required to fields:<br/>";
if(!$opponent){
echo "Opponent name<br/>";
}
if(!$map){
echo "Map<br/>";
}
if(!$desciption){
echo "Description<br/>";
}
include("edit_matches.html");
exit();
}

# insert data into database
$description2 = htmlspecialchars($description);
$sql = mysql_query("INSERT INTO matches (game, opponent, score_one, score_two, date, league, map, description) VALUES ('$game','$opponent','$score1','$score2','$date','$league','$map','$description2')") or die (mysql_error());

if(!$sql){
echo 'There has been an error entering the data. Please contact the webmaster.';
}else{
echo 'The data was entered successfully.';
}

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/13610-you-have-an-error-in-your-sql-syntax/
Share on other sites

instead of plugging your query directly into mysql_query, try setting a variable so you can report it in the error.

[code]$myquery="INSERT INTO matches (game, opponent, score_one, score_two, date, league, map, description) VALUES ('$game','$opponent','$score1','$score2','$date','$league','$map','$description2')";
$sql = mysql_query($myquery) or die (mysql_error()."\n<br>".$myquery);
[/code]

When you run it, you can now see the query and the problem.
the problem is that you have a column called [b]date[/b]. Date is a sql reserved word.  you cannot use reserved words as column/table names unless you put the funny quotes `date` around it.  But even then, it is poor practice to use reserved words as column/table names.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.