Jump to content


Photo

You have an error in your SQL syntax.


  • Please log in to reply
2 replies to this topic

#1 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 04 July 2006 - 02:46 AM

Here is my 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 '.')' at line 1


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

db.php

<?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");
?>

edit_match.php
<?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.';
	}

?>


#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 04 July 2006 - 03:30 AM

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

$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);

When you run it, you can now see the query and the problem.

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 04 July 2006 - 03:43 AM

the problem is that you have a column called date. 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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users