Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2009, 03:03 AM   PM User | #1
Kev0121
New Coder

 
Join Date: Mar 2009
Posts: 97
Thanks: 10
Thanked 0 Times in 0 Posts
Kev0121 is an unknown quantity at this point
Insert Msg Error

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

Quote:
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
Kev0121 is offline   Reply With Quote
Old 03-07-2009, 04:08 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:57 AM.


Advertisement
Log in to turn off these ads.