DrMTR
DrMTR

Reputation: 509

Data is not inserting into database, no error showed

I have this code into my php script that i test:

mysql_query("INSERT INTO te_sales(uid,s_credit,s_price,s_date) VALUES ('$user_info[id]','$cPack[t_credit]','$cPack[t_price]',time())");

but when purchase something, data about buyer are not inserted into te_sales table into database. What is wrong with that?

This is entire code:

if(isset($_POST['te_package'])){
// Lets get the data....
 $sP = intval($_POST['te_package']);
// Lets check in DB either it is there or not.
$chk = mysql_query("SELECT * FROM te_pack WHERE id='$sP' LIMIT 1");
 if(mysql_num_rows($chk)== 1){ // Founded go ahead
// Fetch the sP pack
$cPack = mysql_fetch_array($chk);
// Check user balance...
if($user_info['purchase_balance'] >= $cPack['t_price']){ // Proceed as user 
have enough balance to make purchase.
// Lets Cut out the user balance... And give the TE Credits
mysql_query("UPDATE members SET purchase_balance = purchase_balance - 
'$cPack[t_price]' , te_credit = te_credit + '$cPack[t_credit]' 
WHERE id='$user_info[id]'");
// Insert the logs of sales...
//mysql_query("INSERT INTO te_sales(uid,s_credit,s_price,s_date) VALUES 
('$user_info[id]','$cPack[t_credit]','$cPack[t_price]',time())");
 $result = mysql_real_escape_string("
INSERT INTO te_sales(uid,s_credit,s_price,s_date) 
VALUES ('$user_info[id]','$cPack[t_credit]','$cPack[t_price]',time())
");

if (!$result) {
die('Invalid request : ' . mysql_error());
}

enter image description here

Upvotes: 0

Views: 87

Answers (2)

Sébastian Guesdon
Sébastian Guesdon

Reputation: 221

Have you look if there was an error?

<?php
$result_data = mysql_query('
    INSERT INTO te_sales(uid,s_credit,s_price,s_date) 
    VALUES (
        "'.mysql_real_escape_string($user_info['id']).'",
        "'.mysql_real_escape_string($cPack['t_credit']).'",
        "'.mysql_real_escape_string($cPack['t_price']).'",
        now()
    )
');

if (!$result_data) {
  die('Invalid query request: ' . mysql_error());
}
?>

Upvotes: 2

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

You insert syntax is wrong, try like this

$result_data = mysql_query("
  INSERT INTO te_sales(uid,s_credit,s_price,s_date) VALUES ('".$user_info['id']."','".$cPack['t_credit']."','".$cPack['t_price']."',time()     )
");

if (!$result_data) {
  die('Invalid query request: ' . mysql_error());
}

Upvotes: 0

Related Questions