shanewaj Posted October 10, 2006 Share Posted October 10, 2006 I am giving the code where i belive the problem is accouring .... what happend it does not insert in to the data base i have tried all the way to put in to the data base but not working .. the last line of the code echo the hole things if does not able to inset it show the perfect data .... <?php //when postback if ($_POST) { require_once ('../../mysql_connect.php'); // Connect to the database. //calculate the next product ID $query_num = mysql_query('select MAX(product_id) from TestP'); $row = mysql_fetch_row($query_num); if ($row !== false) { $product_id = $row[0] +1; //fetching data $product_category = $category; $product_title = $title; $product_name = $_POST['product_name']; $product_code = $_POST['product_code']; $product_quantity = $_POST['product_quantity']; $product_weight = (float) $_POST['postage_weight']; $product_weight = settype($product_weight, float); $product_price = (float) $_POST['product_price']; $product_price = settype($product_price, float); if(isset($_POST['product_dangerous'])) { $product_dangerous = '1'; } else { $product_dangerous = '0'; } $product_dangerous = settype($product_dangerous, int); //query to inset $query_add_product_range = "INSERT INTO TestP SET product_id = $product_id, product_category=$product_category, product_title = $product_title, product_name = $product_name, product_code =$product_code, product_quantity_description = $product_quantity product_weight=$product_weight, product_price = $product_price, product_dangerous= $product_dangerous "; $result_add_range = mysql_query($query_add_product_range); if($result_add_range) { echo'done'; } else { echo $product_id,' ---', $product_category,' ---', $product_title,' ---', $product_name,' ---', $product_code,' ---', $product_quantity,' ---' ,$product_weight, ' ---',$product_dangerous, ' ---'; } } } ?> Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 10, 2006 Share Posted October 10, 2006 Make two changes and let's see what happens:First change: make all of the statements in the INSERT query look like product_id = '$product_id', i.e. add single quotes around the value.Second change: Change:[code]$result_add_range = mysql_query($query_add_product_range);[/code]To this:[code]$result_add_range = mysql_query($query_add_product_range) or die("Error ". mysql_error(). " with query". $query_add_product_range);[/code] Quote Link to comment Share on other sites More sharing options...
printf Posted October 10, 2006 Share Posted October 10, 2006 If your doing a INSERT, then you need to change your query, because your using INSERT and UPDATE logic, which will not work....[code]$query = "INSERT INTO TestP VALUES ( '{$product_id}', '{$product_category}', '{$product_title}', '{$product_name}', '{$product_code}', '{$product_quantity}', '{$product_weight}', '{$product_price}', '{$product_dangerous}' );";[/code]It might not be the right order because I do not know your database scheme, but use this as an example of what a INSERT should look like! Also please take the time to validate your $_POST array, if you don't your asking for trouble...me! Quote Link to comment Share on other sites More sharing options...
Firemankurt Posted October 10, 2006 Share Posted October 10, 2006 Her try this:[code] $query_add_product_range ="INSERT INTO TestP (product_id,product_category,product_title,product_name,product_code,product_quantity_description,product_weight,product_price,product_dangerous)VALUES ($product_id,$product_category,$product_title,$product_name,$product_code,$product_quantity,$product_weight,$product_price,$product_dangerous )";[/code] 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.