cameeob2003 Posted July 4, 2006 Share Posted July 4, 2006 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]<?phpinclude("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 More sharing options...
michaellunsford Posted July 4, 2006 Share Posted July 4, 2006 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. Link to comment https://forums.phpfreaks.com/topic/13610-you-have-an-error-in-your-sql-syntax/#findComment-52747 Share on other sites More sharing options...
.josh Posted July 4, 2006 Share Posted July 4, 2006 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. Link to comment https://forums.phpfreaks.com/topic/13610-you-have-an-error-in-your-sql-syntax/#findComment-52750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.