Jump to content


Photo

Input Form Problem


  • Please log in to reply
1 reply to this topic

#1 billshackle

billshackle
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 28 February 2006 - 08:52 AM

I am having trouble with this form. I have a table called "survey" which has the fields name,q1,q2,q3,q4,q5,q6 - i am trying to get the data into the table but it doesn't seem to work, i get the error. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]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 '1','1','1','1','1','1')' at line 1[/quote]
      <form action="rating.php" method="post" class="style1">
<body>
<table width="604" border="0">
  <tr>
    <td colspan="3">Name:
      <br>
      <input name="name" type="text" />
      <br />
  <tr>    </tr><tr>
    <td colspan="3">What?</td>
  </tr>
  <tr>
    <td width="137">
    <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 width="57" colspan="2"><label></label></td>
  </tr>
  <tr>
    <td colspan="3">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="214">&nbsp;</td>
    <td width="165">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">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>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">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>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">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>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">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>&nbsp;</td>
  </tr>
</table>
<p>
<? $username="!";
$password="!";
$database="!";

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

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

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

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

        mysql_query($query) or die (mysql_error());
}
?></p>
</body>
</html>


#2 klpang

klpang
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 01 March 2006 - 10:40 AM

you are missing single quote in your insert statement

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

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users