Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    97
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Insert Msg Error

    Im getting error when trying to insert something into my database
    heres my error

    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 'To See If Im Pro At Coding )' at line 1
    and heres my code

    PHP Code:
    <?php
    include 'connection.php';
    ?>

    <html>
    <head>
        <title>Insert Into Blog</title>
    </head>
    <body>
        <form action = "<?php $_SERVER['PHP_SELF']; ?>" method="POST" name="insert">
            <table>
                <tr>
                <td>Post Title : <input type="text" name="pTitle" /> </td>
                <tr>
                <tr>
                <td>Post Author : <input type="text" name="pAuth" /> </td>
                <tr>
                <td>Post Content : <br/> <input type="text" name="pContent"/> </td>
                <tr>
                <td><input type="submit" name="Submit" value="Done" /> </td>
            </table>
        </form>
    </body>
    </html>

    <?php
    $title 
    $_POST['pTitle'];
    $author $_POST['pAuth'];
    $content $_POST['pContent'];

    if(isset(
    $_POST['Submit'])) {
        
    $insertData "INSERT INTO `test` (title,author,content) VALUES ($title, $author, $content)";
        
    $query mysql_query($insertData) or die(mysql_error());
    }else {
        echo 
    "Error";
    }
    ?>
    Kevin

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    SQL error, not a PHP one. I'll move it to the mysql forum.
    Code:
        $insertData = "INSERT INTO `test` (title,author,content) VALUES ('$title', '$author', '$content')";
    Those variables look to be strings. Therefore, you must wrap them in quotations to be treated as strings, otherwise DBMS will attempt to cast them to a double and fail.
    Make sure you're properly escaping you're input data with mysql_real_escape_strings, and stripslashing any of the magic_quotes that may or may not be added.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •