Mythiel Posted September 21, 2010 Share Posted September 21, 2010 Ive made myself a small test form to check to see if i can get connected to my company's new database. However after I submit the form I get this error message: "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 ')' at line 11" here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>PhP Contact Form</title></head><body><?php$errors = '0';if( isset( $_POST['name']) and $errors == 0){ echo '<p>Thank you for your submission!</p>'; $to = 'graphics@softsigns.com'; $subject = 'Contact Form Submission'; $message = 'You have received a contact form submmision: First Name: '.$_POST['name'].''; $headers = 'From: Contact Form Alert <FormAlert@softsigns.com>'."\n\r"; mail( $to, $subject, $message, $headers ); $connect = mysql_connect( 'localhost','********', '********' ) or die( mysql_error() ); mysql_select_db( 'softsigns', $connect ) or die( mysql_error() ); $query = 'INSERT INTO test_db ( test_name, test_value, test_date ) VALUES ( "'.$_POST['name'].'", "'.$_POST['value'].'", "'.$_POST['date'].'", )'; mysql_query( $query, $connect ) or die( mysql_error() ); }else{ ?> <form id="contact_form" name="contact_form" method="post" action="PhpFormtest.php"> <table width="636" border="0"> <tr> <td width="111"> <div align="right">Name:</div> </td> <td width="510"> <input type="text" name="name" value="<?php echo @$_POST['name']; ?>"/> </td> <td width="1" rowspan="11"> </td> </tr> <tr> <td width="111"> <div align="right">Value:</div> </td> <td width="510"> <input type="text" name="value" value="<?php echo @$_POST['value']; ?>"/> </td> <td width="1" rowspan="11"> </td> </tr> <tr> <td> <div align="right">Date:</div> </td> <td> <input type="text" name="date" value="<?php echo @$_POST['date']; ?>"/> </td> </tr> <tr> <td> <input type="submit" name="submit" value="submit"> <input type="hidden" name="submitted" id="submitted" value="true" /> </td> <td colspan="4"> </td> </tr> </table> </form> <?php}?></body></html> Any Suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/214022-php-form-test-w-mysql-database-syntax-error/ Share on other sites More sharing options...
mikosiko Posted September 21, 2010 Share Posted September 21, 2010 check the usage of ' and " in your $query clause... Quote Link to comment https://forums.phpfreaks.com/topic/214022-php-form-test-w-mysql-database-syntax-error/#findComment-1113789 Share on other sites More sharing options...
chintansshah Posted September 21, 2010 Share Posted September 21, 2010 Error in your INSERT query. Please change your INSERT query with below string. $query = 'INSERT INTO test_db ( test_name, test_value, test_date ) VALUES ( "'.$_POST['name'].'", "'.$_POST['value'].'", "'.$_POST['date'].'" )'; You add extra comma(,) after $_POST['date']. Quote Link to comment https://forums.phpfreaks.com/topic/214022-php-form-test-w-mysql-database-syntax-error/#findComment-1113793 Share on other sites More sharing options...
Mythiel Posted September 21, 2010 Author Share Posted September 21, 2010 *FacePalm* Wow, Thanks a lot. Its always the most obvious ones that get me. Quote Link to comment https://forums.phpfreaks.com/topic/214022-php-form-test-w-mysql-database-syntax-error/#findComment-1113802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.