#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to yo


    My php process file is


    <?php
    if (isset($_POST['submit'])) {
    $userName = $_POST["username"];
    $fullName = $_POST["fullname"];
    $email = $_POST["email"];
    $password = $_POST["password"];
    $con = mysql_connect("localhost", "root", "");
    if (!$con) {
    die('could not connect:' . mysql_error());
    }
    mysql_select_db("alhera", $con);

    mysql_query("INSERT INTO form('user name', 'full name', 'e-mail', 'password') VALUES('$userName','$fullName','$email','$password ')");
    echo "Your record successfully added";
    mysql_select_db("alhera", $con);

    $result=mysql_query("SELECT*FROM form");

    echo"<table border='1'>
    <tr>
    <th>user name</th>
    <th>full name</th>
    </tr>";

    while($row=mysql_fetch_array($result))
    {
    echo"<tr>";
    echo"<td>" .$row['user name']. "</td>";
    echo"<td>" .$row['full name']. "</td>";
    echo"</tr>";
    }
    echo"</table>";

    mysql_close($con);
    }
    ?>



    And

    Local host table is
    1 user name varchar(15) latin1_swedish_ci No None Change Drop More
    2 full name varchar(15) latin1_swedish_ci No None Change Drop More
    3 e-mail varchar(25) latin1_swedish_ci No None Change Drop More
    4 password varchar(15) latin1_swedish_ci No None Change Drop more

    Please Help me to solution
  2. #2
  3. Hockey face
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    St. Catharines, Canada
    Posts
    8,144
    Rep Power
    1316
    First step, when asking for mysql help, get rid of all of the rest of the php code and just show us the relevant part.

    Second when you enclose a column name in single quotes mysql recognizes it as a string and not a column name. Remove those around the column names.

    Third don't use spaces in column names.

    when you've cleaned second and third points up you should be fine.
  4. #3
  5. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,095
    Rep Power
    1990
    This is a PHP question, not a HTML question (one of the mods might want to move this).

    Your query is wrong. It's a pretty basic SQL syntax problem. When you use database, table or column names in a query, you use back-ticks (`) round them, not quotes ('). So, your query would need to be something like:
    PHP Code:
    mysql_query("INSERT INTO form(`user name`, `full name`, `e-mail`, `password`) VALUES('$userName','$fullName','$email','$password ')"); 
    One other thing that's a recommendation: your column names are going to cause you problems somewhere down the line. As a general rule, you should not use spaces, dashes or special characters. Stick to letters, numbers and underscores only as these are a lot easier to work with and will ensure no issues later on.
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,124
    Rep Power
    4303
    Welcome to DevShed Forums, bakul123.

    Please don't post the same question in multiple forums. Pick the one that you feel is best. (If it turns out another is better, a moderator can move your thread for you.) (Cross-post in MySQL forum.)

    P.S. It would be helpful if you put your code between [code][/code] tags in the future.

    *** Thread Moved to MySQL Forum ***
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo