Jump to content

I am having problem in PHP and MYSQL Please help me ......


shanewaj

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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