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, ' ---'; } } } ?> Link to comment https://forums.phpfreaks.com/topic/23613-i-am-having-problem-in-php-and-mysql-please-help-me/ 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] Link to comment https://forums.phpfreaks.com/topic/23613-i-am-having-problem-in-php-and-mysql-please-help-me/#findComment-107215 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! Link to comment https://forums.phpfreaks.com/topic/23613-i-am-having-problem-in-php-and-mysql-please-help-me/#findComment-107218 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] Link to comment https://forums.phpfreaks.com/topic/23613-i-am-having-problem-in-php-and-mysql-please-help-me/#findComment-107223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.