sandbudd Posted June 27, 2008 Share Posted June 27, 2008 this works in mysql 4 but not 5. when submitted it goes to the thank you page with no errors and I receive the email but does not populate the database? Any help would be greatly appreciated. <?php $db_host = ''; $db_user = ''; $db_pwd = ''; $database = ''; $table = ''; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // This function makes usage of // $_GET, $_POST, etc... variables // completly safe in SQL queries function sql_safe($s) { if (get_magic_quotes_gpc()) $s = stripslashes($s); return mysql_real_escape_string($s); } // If user pressed submit in one of the forms if ($_SERVER['REQUEST_METHOD'] == 'POST') { // cleaning title field $title = trim(sql_safe($_POST['title'])); $customer = trim(sql_safe($_POST['customer'])); $company = trim(sql_safe($_POST['company'])); $address = trim(sql_safe($_POST['address'])); $city = trim(sql_safe($_POST['city'])); $state = trim(sql_safe($_POST['state'])); $zip = trim(sql_safe($_POST['zip'])); $email = trim(sql_safe($_POST['email'])); $phone = trim(sql_safe($_POST['phone'])); $fax = trim(sql_safe($_POST['fax'])); $type2 = trim(sql_safe($_POST['type2'])); $type3 = trim(sql_safe($_POST['type3'])); $burnish = trim(sql_safe($_POST['burnish'])); $chromate = trim(sql_safe($_POST['chromate'])); $hex = trim(sql_safe($_POST['hex'])); $impregnation = trim(sql_safe($_POST['impregnation'])); $strip = trim(sql_safe($_POST['strip'])); $part = trim(sql_safe($_POST['part'])); $description = trim(sql_safe($_POST['description'])); $alloy = trim(sql_safe($_POST['alloy'])); $quantity = trim(sql_safe($_POST['quantity'])); $spec = trim(sql_safe($_POST['spec'])); $color = trim(sql_safe($_POST['color'])); $repeat = trim(sql_safe($_POST['repeat'])); $isearch = trim(sql_safe($_POST['isearch'])); $idir = trim(sql_safe($_POST['idir'])); $referral = trim(sql_safe($_POST['referral'])); $yellow = trim(sql_safe($_POST['yellow'])); $trade = trim(sql_safe($_POST['trade'])); $other = trim(sql_safe($_POST['other'])); $notes = trim(sql_safe($_POST['notes'])); if ($title == '') // if title is not set $title = '(empty title)';// use (empty title) string if ($_POST['password'] != $password) // cheking passwors $msg = 'Error: wrong upload password'; else { if (isset($_FILES['photo'])) { @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']); // Get image type. // We use @ to omit errors if ($imtype == 3) // cheking image type $ext="png"; // to use it later in HTTP headers elseif ($imtype == 2) $ext="jpeg"; elseif ($imtype == 1) $ext="gif"; else $msg = 'Error: unknown file format'; if (!isset($msg)) // If there was no error { $data = file_get_contents($_FILES['photo']['tmp_name']); $data = mysql_real_escape_string($data); // Preparing data to be used in MySQL query mysql_query("INSERT INTO {$table} SET ext='$ext', title='$title', customer='$customer', company='$company', address='$address', city='$city', state='$state', zip='$zip', email='$email', phone='$phone', fax='$fax', type2='$type2', type3='$type3', burnish='$burnish', chromate='$chromate', hex='$hex', impregnation='$impregnation', strip='$strip', part='$part', description='$description', alloy='$alloy', quantity='$quantity', spec='$spec', color='$color', repeat='$repeat', isearch='$isearch', idir='$idir', referral='$referral', yellow='$yellow', trade='$trade', other='$other', notes='$notes', data='$data'"); $msg = 'Success: image uploaded'; } } elseif (isset($_GET['title'])) // isset(..title) needed $msg = 'Error: file not loaded';// to make sure we've using // upload form, not form // for deletion if (isset($_POST['del'])) // If used selected some photo to delete { // in 'uploaded images form'; $id = intval($_POST['del']); mysql_query("DELETE FROM {$table} WHERE id=$id"); $msg = 'Photo deleted'; } } } elseif (isset($_GET['show'])) { $id = intval($_GET['show']); $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(image_time), data FROM {$table} WHERE id=$id LIMIT 1"); if (mysql_num_rows($result) == 0) die('no image'); list($ext, $image_time, $data, $customer, $company, $address, $city, $state, $zip, $email, $phone, $fax, $type2, $type3, $burnish, $chromate, $hex, $impregnation, $strip, $part, $description, $alloy, $quantity, $spec, $color, $repeat, $isearch, $idir, $referral, $yellow, $trade, $other, $notes) = mysql_fetch_row($result); $send_304 = false; if (php_sapi_name() == 'apache') { // if our web server is apache // we get check HTTP // If-Modified-Since header // and do not send image // if there is a cached version $ar = apache_request_headers(); if (isset($ar['If-Modified-Since']) && // If-Modified-Since should exists ($ar['If-Modified-Since'] != '') && // not empty (strtotime($ar['If-Modified-Since']) >= $image_time)) // and grater than $send_304 = true; // image_time } if ($send_304) { // Sending 304 response to browser // "Browser, your cached version of image is OK // we're not sending anything new to you" header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304); exit(); // bye-bye } // outputing Last-Modified header header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT', true, 200); // Set expiration time +1 year // We do not have any photo re-uploading // so, browser may cache this photo for quite a long time header('Expires: '.gmdate('D, d M Y H:i:s', $image_time + 86400*365).' GMT', true, 200); // outputing HTTP headers header('Content-Length: '.strlen($data)); header("Content-type: image/{$ext}"); // outputing image echo $data; exit(); } ?> <?php if (phpversion() > "4.0.6") { $HTTP_POST_VARS = &$_POST; } if (isset($HTTP_POST_VARS["formSeen"])) { // create the mail information $to = "dan@sandbudd.com"; $subject = "RFQ"; $from = "From: Request For Quote\r\n"; $body = "The following information was submitted:\n\n"; while (list($key,$value) = each($HTTP_POST_VARS)) { $body.= $key . " = " . $value . "\n"; } // now send the mail mail($to,$subject,$body,$from); // then redirect to another page header("Location: thankyou.php"); } ?> <html><head> <title>FWA Request For Quote</title> <style type="text/css"> <!-- .style1 { font-size: 14px; color: #0000FF; } --> </style> </head> <body> <p style="font-weight: bold;"> </p> <form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data"> <table width="848" border="0" cellpadding="2" cellspacing="0"> <tr> <td width="58"><label for="customer">Name:</label> <label for="label"> <input name="formSeen" type="hidden" id="hiddenField"> </label></td> <td width="322"><input type="text" name="customer" id="customer" size="50"></td> <td width="62"><label for="company">Company:</label> <label for="label"></label></td> <td width="347"><input type="text" name="company" id="company" size="50"></td> </tr> <tr> <td><label for="address">Address:</label> <label for="title"><td><input type="text" name="address" id="address" size="50"></td> <td><label for="City">City:</label></td> <td><input type="text" name="city" id="city" size="50"></td> </tr> <tr> <td><label for="label">State:</label></td> <td><input type="text" name="state" id="state" size="50"></td> <td><label for="label">Zip:</label></td> <td><input type="text" name="zip" id="zip" size="50"></td> </tr> <tr> <td><label for="label">Email:</label></td> <td colspan="3"><input type="text" name="email" id="email" size="50"></td> </tr> <tr> <td><label for="label">Phone:</label></td> <td><input type="text" name="phone" id="phone" size="50"></td> <td><label for="label">Fax:</label></td> <td><input type="text" name="fax" id="fax" size="50"></td> </tr> <tr> <td colspan="4"><span class="style1">Process requested (please check all that apply):</span></td> </tr> <tr> <td colspan="2"><input type="checkbox" name="type2" id="checkbox2"> Type II (Conventional Anodize) </td> <td colspan="2"><input type="checkbox" name="type3" id="checkbox3"> Type III (Hard Coat Anodize)</td> </tr> <tr> <td colspan="2"><input type="checkbox" name="burnish" id="checkbox4"> (Burnish, Deburr)</td> <td colspan="2"><input type="checkbox" name="chromate" id="checkbox5"> Chromate Conversion</td> </tr> <tr> <td colspan="2"><input type="checkbox" name="hex" id="checkbox6"> Chromate Conversion Hex – free</td> <td colspan="2"><input type="checkbox" name="impregnation" id="checkbox7"> Impregnation</td> </tr> <tr> <td colspan="2"><input type="checkbox" name="strip" id="checkbox8"> Strip</td> <td colspan="2"> </td> </tr> <tr> <td colspan="2"><label for="label">Part Number:</label></td> <td colspan="2"><input type="text" name="part" id="part" size="50"></td> </tr> <tr> <td colspan="2"><label for="label">Part Description (part name or basic size):</label></td> <td colspan="2"><input type="text" name="description" id="description" size="50"></td> </tr> <tr> <td><label for="label">Alloy:</label></td> <td><input type="text" name="alloy" id="alloy" size="50"></td> <td><label for="label">Quantity:</label></td> <td><input type="text" name="quantity" id="quantity" size="50"></td> </tr> <tr> <td><label for="label">Specification:</label></td> <td><input type="text" name="spec" id="spec" size="50"></td> <td><label for="label">Color:</label></td> <td><input type="text" name="color" id="color" size="50"></td> </tr> <tr> <td colspan="2"><span class="style1">How did you hear about us?</span></td> <td colspan="2"> </td> </tr> <tr> <td colspan="4"><table width="100%" border="0" cellpadding="2" cellspacing="0"> <tr> <td colspan="2"><input type="checkbox" name="repeat" id="checkbox9"> I am a repeat customer</td> <td width="23%"><input type="checkbox" name="isearch" id="checkbox10"> Internet Search</td> <td width="16%"><label for="label">Internet Directory:</label></td> <td width="28%"><input type="text" name="idir" id="idir" size="30"></td> </tr> <tr> <td width="7%"><label for="label">Referral:</label></td> <td width="26%"><input type="text" name="referral" id="referral" size="30"></td> <td><input type="checkbox" name="yellow" id="checkbox"> Yellow Pages</td> <td><label for="label">Trade Show:</label></td> <td><input type="text" name="trade" id="trade" size="30"></td> </tr> </table></td> </tr> <tr> <td> </td> <td colspan="3"> </td> </tr> <tr> <td><label for="label">Other:</label></td> <td colspan="3"><textarea name="other" cols="80" id="other"></textarea></td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> </td> </tr> <tr> <td colspan="4"><table width="100%" border="0" cellpadding="2" cellspacing="0"> <tr> <td width="25%"><label for="label">Notes / Special Requests:</label></td> <td colspan="2"><textarea name="notes" cols="80" id="notes"></textarea></td> </tr> <tr> <td> </td> <td width="43%"> </td> <td width="32%"> </td> </tr> <tr> <td>Upload File Name: </td> <td colspan="2"><input type="text" name="title" id="title" size="64"></td> </tr> <tr> <td> </td> <td colspan="2"> </td> </tr> <tr> <td>Upload File:</td> <td colspan="2"><input type="file" name="photo" id="photo"></td> </tr> </table></td> </tr> <tr> <td></p> <label for="label"></label></td> <td colspan="3"> </td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> </td> </tr> <tr> <td colspan="2"><input type="submit" value="Submit"></td> <td colspan="2"> </td> </tr> </table> <label for="customer"><br> </label> <label for="company"><br> </label> <label for="address"><br> </label> <label for="City"></label> <label for="state"></label> <label for="zip"></label> <label for="email"></label> <label for="phone"></label> <label for="fax"></label> <label for="part"></label> <label for="description"></label> <label for="alloy"></label> <label for="quantity"></label> <br> <br> <label for="spec"></label> <label for="color"></label> <label for="idir"></label> <label for="referral"></label> <label for="trade"></label> <label for="other"></label> <label for="notes"></label> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 27, 2008 Author Share Posted June 27, 2008 I think my problem is here somewhere? mysql_query("INSERT INTO {$table} SET ext='$ext', title='$title', customer='$customer', company='$company', address='$address', city='$city', state='$state', zip='$zip', email='$email', phone='$phone', fax='$fax', type2='$type2', type3='$type3', burnish='$burnish', chromate='$chromate', hex='$hex', impregnation='$impregnation', strip='$strip', part='$part', description='$description', alloy='$alloy', quantity='$quantity', spec='$spec', color='$color', repeat='$repeat', isearch='$isearch', idir='$idir', referral='$referral', yellow='$yellow', trade='$trade', other='$other', notes='$notes', data='$data'"); Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted June 27, 2008 Share Posted June 27, 2008 save your query into a variable eg:$SQL, and then echo SQL and see what you get. then copy that outputed query into MySQL or phpmyadmin and check that your getting a result from it..... if you are then its not that statement. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 27, 2008 Author Share Posted June 27, 2008 changed to this and get this error: Insert 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 'repeat, isearch, idir, referral, yellow, trade, other, notes, data)VALUES (gif, ' at line 1 $querymysql = "INSERT INTO $table (ext, title, customer, company, address, city, state, zip, email, phone, fax, type2, type3, burnish, chromate, hex, impregnation, strip, part, description, alloy, quantity, spec, color, repeat, isearch, idir, referral, yellow, trade, other, notes, data)VALUES (".$ext.", ".$title.", ".$customer.", ".$company.", ".$address.", ".$city.", ".$state.", ".$zip.", ".$email.", ".$phone.", ".$fax.", ".$type2.", ".$type3.", ".$burnish.", ".$chromate.", ".$hex.", ".$impregnation.", ".$strip.", ".$part.", ".$description.", ".$alloy.", ".$quantity.", ".$spec.", ".$color.", ".$repeat.", ".$isearch.", ".$idir.", ".$referral.", ".$yellow.", ".$trade.", ".$other.", ".$notes.", ".$data.")"; if (!mysql_query($querymysql)) { die('Insert error: ' . mysql_error()); } Quote Link to comment Share on other sites More sharing options...
sandbudd Posted June 27, 2008 Author Share Posted June 27, 2008 phpadmin says the query is this but I am not sure how to use it? I am still a newbe sorry. $sql = 'INSERT INTO `anodizi_pass`.`ae_gallery` (`id`, `customer`, `company`, `address`, `city`, `state`, `zip`, `email`, `phone`, `fax`, `type2`, `type3`, `burnish`, `chromate`, `hex`, `impregnation`, `strip`, `part`, `description`, `alloy`, `quantity`, `spec`, `color`, `repeat`, `isearch`, `idir`, `referral`, `yellow`, `trade`, `other`, `notes`, `title`, `ext`, `image_time`) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 27, 2008 Share Posted June 27, 2008 The mysql error message has the answer - for the right syntax to use near 'repeat, isearch, idir, referral,... The part right after the single-quote ' is where mysql found a problem. In this case, repeat is a mysql keyword. You should rename it to something else or you can put it in back-ticks `repeat`. Quote Link to comment 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.