insert data into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fatma fares
    New Member
    • May 2014
    • 2

    insert data into database

    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 'add que(quedtion_te x)VALUES('')' at line 1

    this my code

    Code:
    <html>
    <head>
    <title>
    add question
    </title>
    <meta name="keywords" content="Web Tech Template, CSS, HTML" />
    <meta name="description" content="Web Tech Template is a free CSS website provided by templatemo.com" />
    <link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
    </script>
    </head>
    <body>
    
    
    
    <?php
    error_reporting(0);
     
    $quedtion_tex=$_POST['quedtion_tex'];
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
     
    mysql_select_db("center_db", $con);
     
    $sql="INSERT INTO add que(quedtion_tex)VALUES('$quedtion_tex')";
     
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
     
    mysql_close($con)
    ?>
    
    
    
    
    <form action="add que.php" method="post">
    <p>
    <input type="text" name="quedtion_tex">
    <input type="submit" name="submit"  value="add que" >
    </p>
    
    
    
    </body>
    </html>
    Last edited by Rabbit; May 3 '14, 04:34 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    Why did you not use '[CODE/]' tags around your code?

    INSERT INTO add que(quedtion_te x)VALUES.....
    is not a valid SQL statement.
    What is the name of your database table?

    Comment

    • fatma fares
      New Member
      • May 2014
      • 2

      #3
      name of my database table(add que)

      Comment

      • Luuk
        Recognized Expert Top Contributor
        • Mar 2012
        • 1043

        #4
        You should use backquotes "`" around your tablename, when you decide to use a space in its name....

        Comment

        • koharu
          New Member
          • Apr 2014
          • 10

          #5
          Hi Fatma Fares.

          Standard MySQL Syntax for an Insert Statement goes as followed;

          Code:
          INSERT INTO `add que` VALUES ();
          For example;
          Code:
          INSERT INTO `my users` VALUES ('','Koharu',md5('myPass'),'something@towho.com');
          I suggest you do some reading on MySQL Queries here;

          Comment

          Working...