| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 57927 | 2005-05-16 10:39:00 | GGRRRRR php problem | Morgenmuffel (187) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 355731 | 2005-05-16 10:39:00 | Hi all I am getting the following 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 '' at line 1 I can't see anything wrong with my syntax so help is required how the code works product_option_3 . php is called from another page, it uses the product_ID variable (from the previous page) to ensure relevant data is displayed, and puts up a data entry form, when the data is entered correctly and the submit button is pressed it calls product_option_4 . php which post the data to the database, and displays a success message as well as a couple of links, up to here it works fine, if i click on the main menu link I go to the main menu, if however I click on the add new option link I get taken to product_option_3 . php and the error message is displayed product_option_3 . php <?php header ("Cache-Control: no-store, no-cache"); //HTTP/1 . 1 header ("pragma: no-cache"); include(' . . /protector . php'); require_once('include2 . php'); include('functions . php'); $valid = TRUE; if (isset ($_POST['submit'])) { foreach($_POST as $key=>$value) { $$key = $value; } $option_name =trim($option_name); $valid = $on = checkLength($option_name, 1, 30); if ($valid) { include("product_option_4 . php"); exit; } } else { $on = TRUE; $option_name = ''; } ?> <html> <head><body> <h1>Add options</h1> <?php if (!$valid) { ?> <style type="text/css"> td . error {color:C03; font-weight:bold; } </style> Please correct the items in red and resubmit . <br /><br /> <?php } ?> <?php $cat_ID=$HTTP_POST_VARS['product_ID']; $cat_ID=addslashes($product_ID); include('find_product_info . php'); echo '<br>'; include('find_product_options . php'); ?> <form action="product_option_3 . php" method="post"> <table> <input type="hidden" name="product_ID" value="<?= $product_ID ?>"/> <tr valign="top"> <td <?php if(!$on) echo 'class="error"'; ?>>option (eg blue, red, winnie the pooh print )</td> <td><input type="text" name="option_name" size="30" value="<?= $option_name ?>"></td> </tr> <tr valign="top"> <td> </td> <td><input type="submit" Value="Add" name="submit"></td> </tr> </table></form> </body> </head> </html> product_option_4 . php <?php include(' . . /protector . php'); echo '<H1>Posting Information . . . . . </h1>'; $option_name=$HTTP_POST_VARS['option_name']; $product_ID=$HTTP_POST_VARS['product_ID']; $option_name=addslashes($option_name); $product_ID=addslashes($product_ID); require_once('include2 . php'); mysql_select_db($dbname, $conn); mysql_select_db('a_option'); $query = "insert into a_option values ( NULL,'" . $product_ID . "', '" . $option_name . "')"; $result = mysql_query($query); if ($result){ //echo mysql_affected_rows() . ' Success . '; echo 'The option has been successfully added'; echo '<br>'; echo '<a href="product_option_3 . php">Add another option/colour</a><br>'; //after the above is clicked the error is generated echo '<br>'; echo '<a href="index . php">Return to Main Menu</a><br>'; //This works fine } ?> |
Morgenmuffel (187) | ||
| 355732 | 2005-05-16 11:04:00 | Ok I have got around it with a Kludge I used a form submit and that seemed to work, if anyone knows a better way please let me know Thanks You know I wonder if I'm the only person who after posting a problem finds the answer, about half the time when writing about a problem, I'll preview it and think "what if I did ..." and it seems to work, yet without going to PF1 I can spend another hour or two figureing it out product_option_4.php <?php include('../protector.php'); echo '<H1>Posting Information.....</h1><br><br><br><br>'; $option_name=$HTTP_POST_VARS['option_name']; $product_ID=$HTTP_POST_VARS['product_ID']; $option_name=addslashes($option_name); $product_ID=addslashes($product_ID); require_once('include2.php'); mysql_select_db($dbname, $conn); mysql_select_db('a_option'); $query = "insert into a_option values ( NULL,'".$product_ID."', '".$option_name."')"; //echo $query; $result = mysql_query($query); if ($result){ //echo mysql_affected_rows().' Success.'; ?> <form action="product_option_3.php" method="post"> <input type="hidden" name="product_ID" value="<?= $product_ID ?> "/> <input type="submit" Value="Add another Option" name="jack"></td> </form> <?php echo 'The option has been successfully added'; // echo '<br>'; //echo '<a href="product_option_3.php">Add another option/colour</a><br>'; echo '<br>'; echo '<a href="index.php">Return to Main Menu</a><br>'; //echo 'The option has been successfully added'; } ?> |
Morgenmuffel (187) | ||
| 1 | |||||