Jump to content


Photo

SQL Syntax Error


  • Please log in to reply
1 reply to this topic

#1 billshackle

billshackle
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 April 2006 - 06:45 AM

I get the following error: [!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]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 ''vid' , 'comname' , 'name' , 'q1' , 'q2' , 'q3' , 'q4' , 'q5' , 'comments' , 'q6' at line 1[!--colorc--][/span][!--/colorc--]

When executing this script;

If anyone could shed any light on this it would be appreciated.

Thanks in advance.

<? $username="";
$password="";
$database="test";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if (isset($_POST['Submit'])) {

        $vid = $_POST['vid'];
        $comname = $_POST['comname'];
        $name = $_POST['name'];
        $q1 = $_POST['q1'];
        $q2 = $_POST['q2'];
        $q3 = $_POST['q3'];
        $q4 = $_POST['q4'];
        $q5 = $_POST['q5'];
        $comments = $_POST['comments'];
        $q6 = $_POST['q6'];

        $query = "INSERT INTO survey ('vid' , 'comname' , 'name' , 'q1' , 'q2' , 'q3' , 'q4' , 'q5' , 'comments' , 'q6')
        VALUES ('$vid', '$name', '$comname', '$q1', '$q2', '$q3', '$q4', '$q5', '$comments', '$q6')";


        mysql_query($query) or die (mysql_error());
}
?>
      <form action="reviews/rating8.php" method="post">
<body>
<table width="604" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="4">
  <tr>
    <td>Name:
      <br>
      <input name="name" type="text" />
      <br />
    <td>
    
    <td>UID:<br>
      <input type="comname" name="comname" value="<? echo $name; ?>">
    <td>    
  <tr>    </tr><tr>
    <td colspan="4"></td>
  </tr>
  <tr>
    <td width="156">
    <select name="q1">
     <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select></form></td>
    <td colspan="3"><label></label></td>
  </tr>
  <tr>
    <td colspan="4">What?</td>
  </tr>
  <tr>
    <td>
    <select name="q2">
     <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select></form></td>
    <td width="118">&nbsp;</td>
    <td width="316" colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4">What?</td>
  </tr>
  <tr>
    <td>
    <select name="q3">
       <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select></form></td>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4">What?</td>
  </tr>
  <tr>
    <td>

    <select name="q4">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select></form></td>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4">What?</td>
  </tr>
  <tr>
    <td>
    <select name="q5">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select></form></td>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4">Comments:</td>
  </tr>
  <tr>
    <td colspan="4">
      <textarea name="comments" cols="80" rows="4"></textarea>    </td>
  </tr>
  <tr>
    <td colspan="4">What?</td>
  </tr>
  <tr>
    <td>
    <select name="q6">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select><input name="Submit" type="Submit" />
    <p>
    </form></td>
    <td></td>
    <td colspan="2">&nbsp;</td>
  </tr>
</table>
</p>
</body>
</html>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,019 posts

Posted 19 April 2006 - 07:03 AM

Don't put quotes round column names, only round values.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users