Jump to content

issues $_POST email to database


Guber-X

Recommended Posts

im just making a simple contact form to submit to my database. it always comes up with this error.

 

Error, insert query failed: 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 '@hotmail.com, 'Test Msg')' at line 1

 

my form involves these input boxes in the same order and also what I entered into those boxes

 

Name: Shane

Phone: 2502501234

Email: [email protected]

Msg: Test Msg

 

for my understanding its not taking the "Email" input box correctly or something. heres my code...

 

<?php
if (isset($_POST['submit'])) {
        	
$name    = $_POST['name'];
$phone 	 = $_POST['phone'];
$email	 = $_POST['email'];
$msg	 = $_POST['msg'];
        	
$querys  = "INSERT INTO contact (name, phone, email, msg) VALUES ('$name', $phone, $email, '$msg')";
       	mysql_query($querys) or die("Error, insert query failed: " . mysql_error());

echo '<br /><br />Thank You!';
} else {
        echo '<form method="post">',
                '<table>',
                '<tr>',
                '<td>Name: </td>',
                '<td>',
                '<input type="text" name="name" id="name">',
                '</td>',
                '</tr>',
                '<tr>',
                '<td>Phone #:</td>',
                '<td>',
                '<input type="tel" name="phone" id="phone">',
                '</td>',
                '</tr>',
                '<tr>',
                '<td>Email:</td>',
                '<td>',
                '<input type="email" name="email" id="email">',
                '</td>',
                '</tr>',
                '<tr>',
                '<td class="msg">Message:</td>',
                '<td>',
                '<textarea id="msg" name="msg" rows="10" cols="40"></textarea>',
                '</td>',
                '</tr>',
                '<tr>',
                '<td rowspan="2">',
                '<input type="submit" value="Submit" id="submit" name="submit">',
                '</td>',
                '</tr>',
                '</table>',
                '</form>';
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/264779-issues-_post-email-to-database/
Share on other sites

holy hell im blind... i found my error...

 

$querys  = "INSERT INTO contact (name, phone, email, msg) VALUES ('$name', $phone, $email, '$msg')";

 

i was missing some quotations by the $phone and $email... lol. should be like this

 

$querys  = "INSERT INTO contact (name, phone, email, msg) VALUES ('$name', '$phone', '$email', '$msg')";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.