Jump to content

Insert into DB problems


VinceGledhill

Recommended Posts

Hi People.

 

Thanks for all the help with my ongoing project.

 

Please can you tell me what my problem is with this error?

 

Error During Insert :

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 ') VALUES ('test', 'tesast', 'tesat','tear', 'sest', 'none whatsoever', '', 'ter'' at line 1

 

Error occured running the following code :

INSERT INTO HelperFormData (surname, firstname, phone1, phone2, location, qualifications, expertise, assistance, languages, e_mail, consent, published, comments, other_info,) VALUES ('test', 'tesast', 'tesat','tear', 'sest', 'none whatsoever', '', 'ter', 'my language', 'vince@vince.com', 'No', 'No', 'ateaglea', 'ttaelgae')

 

Here is the code to my insert form

 

<!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=iso-8859-1" />
<title>Stranded Flyer</title>
</head>

<body>

<?php

$host = 'localhost';
$usr = "username";
$password = 'password';
$db_name = 'stranded';

//connect to database
mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error());
mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error());

$surname = mysql_real_escape_string($_POST['surname']);
$firstname = mysql_real_escape_string($_POST['firstname']);
$phone1 = mysql_real_escape_string($_POST['phone1']);
$phone2 = mysql_real_escape_string($_POST['phone2']);
$location = mysql_real_escape_string($_POST['location']);
$qualifications = mysql_real_escape_string($_POST['qualifications']); 
$expertise = mysql_real_escape_string($_POST['expertise']);
$assistance = mysql_real_escape_string($_POST['assistance']);
$languages = mysql_real_escape_string($_POST['languages']);
$e_mail = mysql_real_escape_string($_POST['e_mail']);
$consent = mysql_real_escape_string($_POST['consent']);
$published = mysql_real_escape_string($_POST['published']);
$comments = mysql_real_escape_string($_POST['comments']); 
$other_info = mysql_real_escape_string($_POST['other_info']);



$errorstring = ""; // default value of errorstring

function makeSafe($value)
{
    if (get_magic_quotes_gpc())
    {
        $value = stripslashes($value); 
    }
    
    $value = mysql_real_escape_string($value);
    
    return $value;
}

if(isset($_POST['submit'])) {
// Validate all the code inputs

// Captcha Validation


require_once('recaptchalib.php');
$privatekey = "MyPrivateKeyRemovedForTheForumPost";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                             $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
   $errorstring = $errorstring. "Invalid CAPTCHA, please try again";
  } else {

if ($surname =="")
$errorstring = $errorstring. "Surname<br>";
if ($phone1 =="")
$errorstring = $errorstring. "phone1<br>";	
if ($phone2 =="")
$errorstring = $errorstring. "phone2<br>";
if ($location =="")
$errorstring = $errorstring. "location<br>";
if	($qualifications =="")
$errorstring = $errorstring. "qualifications<br>";
if ($assistance =="")
$errorstring = $errorstring. "assistance<br>";
if ($languages =="")
$errorstring = $errorstring. "languages<br>";
if ($e_mail =="")
$errorstring = $errorstring. "e_mail<br>";
if ($consent =="")
$errorstring = $errorstring. "consent<br>";
if ($published =="")
$errorstring = $errorstring. "published<br>";
if ($comments =="")
$errorstring = $errorstring. "comments<br>";	
if ($other_info =="")
$errorstring = $errorstring. "other info<br>";

// does the errorstring = "nothing"?

}
// Figure out which error message to show i.e. field validation or CAPTCHA
if ($errorstring !="")
   if (strstr($errorstring,"CAPTCHA")) echo $errorstring;
  else echo "You have not put anything in the following fields: <br><br> $errorstring";
//echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\"";
//die ("Please try again, ensuring that you fill out all the fields!");
else 
{


//echo "Your data has been saved";


$insert_query = "INSERT INTO HelperFormData (surname, firstname, phone1, phone2, location, qualifications, expertise, assistance, languages, e_mail, consent, published, comments, other_info,) VALUES ('$surname', '$firstname', '$phone1','$phone2', '$location', '$qualifications', '$expertise', '$assistance', '$languages', '$e_mail', '$consent', '$published', '$comments', '$other_info')";
$insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query);

$id = mysql_insert_id();

echo "Thank you, Your details have been submitted.";
//include "resultcard.php";

// Output what the form looks like

// End of how the form looks 

}
}

if(!isset($_POST['submit']) || (isset($_POST['submit']) && !empty($errorstring)))
{
?>

<form name = "form1" method ="post" action="">
<table width="700" border="0" cellspacing="5" cellpadding="5" bgcolor = "#dddddd">
  <caption>
    Submit Your  Details
  </caption>
  <tr>
    <td width = "50"> </td>
    <td width = "240"> </td>
    <td width = "250"> </td>
    <td width = "160"><b>Example Input</b></td>
  </tr>
  
  <tr>
    <td> </td>
    <td>Surname</td>
    <td><input type='text' name='surname' size = '40' maxlength='30' value = '<?php echo $surname; ?>'></td>
    <td>Smith</td>
  </tr>
  
  <tr>
    <td> </td>
    <td>First Name</td>
    <td><input type='text' name='firstname' size = '40' maxlength='30' value = '<?php echo $firstname; ?>'></td>
    <td>Bill</td>
  </tr>
  
  <tr>
    <td> </td>
    <td>Phone 1</td>
    <td><input type='text' name='phone1' size = '40' maxlength='30' value = '<?php echo $phone1; ?>'></td>
    <td>07777 777777</td>
  </tr>
  
  
  
  <tr>
    <td> </td>
    <td>Phone 2</td>
    <td><input type='text' name='phone2' size = '40' maxlength= '30'value = '<?php echo $phone2; ?>'></td>
    <td>0118 123 4567</td>
  </tr>
  <tr>
    <td> </td>
    <td>Location</td>
    <td><input type='text' name='location' size = '40' maxlength='40'value = '<?php echo $location; ?>'></td>
    <td>52.289071,-1.952004</td>
  </tr>
  <tr>
    <td> </td>
    <td>Qualifications</td>
    <td><input type='text' name='qualifications'  size = '40' maxlength='30' value = '<?php echo $qualifications; ?>'></td>
    <td>Electrician</td>
  </tr>
  <tr>
    <td> </td>
    <td>Expertise</td>
    <td><input type='text' name='qualifications'  size = '40' maxlength='30' value = '<?php echo $expertise; ?>'></td>
    <td>Flexwings</td>
  </tr>
  <tr>
    <td> </td>
    <td>Assistance Offered</td>
    <td><input type='text' name='assistance' size = '40' maxlength='50' value = '<?php echo $assistance; ?>' /></td>
    <td>Trailer and Tow Car</td>
  </tr>
  <tr>
    <td> </td>
    <td>Language Skills</td>
    <td><input type='text' name='languages' size = '40' maxlength='50' value = '<?php echo $languages; ?>' /></td>
    <td><p>English / Spanish</p></td>
  </tr>
  <tr>
    <td> </td>
    <td>e_mail</td>
    <td><input type='text' name='e_mail' size = '40' maxlength='50' value = '<?php echo $e_mail; ?>' /></td>
    <td><p>example@mail.net</p></td>
  </tr>
  <tr>
    <td> </td>
    <td>Consent</td>
    <td>
      <select name = "consent">
        <option value = "Yes" <?php if ($_POST['consent'] == 'Yes') { echo 'selected="selected"'; } ?>>Yes</option>
        <option value = "No" <?php if ($_POST['consent'] == 'No') { echo 'selected="selected"'; } ?>>No</option>
        
      
  </select>
      
      </td>
    <td>Yes</td>
  </tr>
  <tr>
    <td> </td>
    <td>Published</td>
    <td>
    
     <select name = "published">
     <option value = "Yes" <?php if ($_POST['published'] == 'Yes') { echo 'selected="selected"'; } ?>>Yes</option>
        <option value = "No" <?php if ($_POST['published'] == 'No') { echo 'selected="selected"'; } ?>>No</option>
</select>
    
    </td>
    <td>Yes</td>
  </tr>
  <tr>
    <td> </td>
    <td>Comments</td>
    <td><textarea name= "comments" input type = 'text' rows = "5" cols = "29" /><?php echo $comments; ?></textarea></td>
    <td>As much info as possible 500 characters max</td>
  </tr>
  <tr>
    <td> </td>
    <td>Other Info</td>
    <td><textarea name= "other_info" input="input" type = 'text' rows = "5" cols = "29" /><?php echo $other_info; ?></textarea></td>
    <td>As much info as possible 500 characters max</td>
  </tr>
  <tr>
    <td> </td>
    <td><input type='submit' name='submit' value='Submit Your Info' /></td>
    <td colspan="2">
      <? require_once('recaptchalib.php');
  $publickey = "MyPublicKeyRemovedFromTheForumPost"; // you got this from the signup page
  echo recaptcha_get_html($publickey);
  ?></td>
  </tr>
</table>
</form>


</body>
</html>
<?php } ?>

Link to comment
Share on other sites

Try taking the last comma away?

 

INSERT INTO HelperFormData (surname, firstname, phone1, phone2, location, qualifications, expertise, assistance, languages, e_mail, consent, published, comments, other_info,) VALUES ('test', 'tesast', 'tesat','tear', 'sest', 'none whatsoever', '', 'ter', 'my language', 'vince@vince.com', 'No', 'No', 'ateaglea', 'ttaelgae')

 

to

 

INSERT INTO HelperFormData (surname, firstname, phone1, phone2, location, qualifications, expertise, assistance, languages, e_mail, consent, published, comments, other_info) VALUES ('test', 'tesast', 'tesat','tear', 'sest', 'none whatsoever', '', 'ter', 'my language', 'vince@vince.com', 'No', 'No', 'ateaglea', 'ttaelgae')

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.