Page 1 of 1
help me in sql queries
Posted: Fri Mar 04, 2005 8:47 am
by elle_girl
Code: Select all
if ($result) {
$data = "SELECT itemId, qty, price, cartId FROM cart ";
$result1 = @mysql_query($data) or die (mysql_error());
if ($row = mysql_fetch_array($result1)) {
$itemId = $rowї'itemId'];
$qty = $rowї'qty'];
$price = $rowї'price'];
$cartId = $rowї'cartId'];
$query1 = "INSERT INTO view (itemId, price, qty, cartId) VALUES ('$itemId','$price','$qty','$cartId' )";
$result2 = mysql_query($query1) or die(mysql_error());// Run the query.
if ($result2) {
$insert = "UPDATE view SET account_no = '$aa', token_id = '$t', name = '$n', address = '$ad', state = '$s', country = '$c' WHERE cartId = '$cartId'";
$result_insert = mysql_query ($insert) or die(mysql_error());
} else {
echo '<p><font color="red" size="+1">Cannot update to the database</font></p>';
}
// Successful add the new customer.
echo '<h3>Successful the transaction</h3>';
include ('includes/header_bank.html');
exit();
} else {
echo '<p><font color="red" size="+1">Unsucessful transaction</font></p>';
}
} else { // The account number does not match with token ID.
echo '<p><font color="red" size="+1">The account number does not match with the reference ID in the database</font></p>';
}
My syntax is correct. No error encountered. The problem is that ..
in my cart table it has 2 data but when I want to insert the cart table to view table it just appear 1 data... it does not insert all the data. Can you please help me in the sql queries to solve my problem? I really appreciated your help.
Posted: Fri Mar 04, 2005 8:58 am
by feyd
you only ask for 1 record. You need a loop.
Posted: Fri Mar 04, 2005 2:44 pm
by calcop
To get all the records from a mysql query use this example:
Code: Select all
$query = "select * from records where cust_id=$cust_id;";
$result = mysql_query( $query );
while ($rows = mysql_fetch_array( $result )) {
// Enter your code here for each record.
}
Posted: Sun Mar 06, 2005 12:40 am
by elle_girl
I make a little modification.
Code: Select all
// Make sure the token available.
$query = "SELECT * FROM customer_bank WHERE token_id = '$t' AND account_no = '$aa' ";
$result = @mysql_query ($query);
if ($result) {
$data = "SELECT itemId, price, qty FROM cart ";
$result1 = @mysql_query($data) or die (mysql_error());
while($row = mysql_fetch_row($result1)) {
$comp = "SELECT COUNT (*) FROM cart ";
$comparison = @mysql_query($data) or die (mysql_error());
$itemId = $rowї'itemId']; // line 93
$price = $rowї'price']; // line 94
$qty = $rowї'qty']; // line 95
$cartId = $rowї'cartId']; // line 96
if ($comparison == "1") {
$query1 = "INSERT INTO view (itemId, price, qty, cartId) VALUES ('$itemId','$price','$qty','$cartId' )";
$result2 = mysql_query($query1) or die(mysql_error());// Run the query.
if ($result2) {
$insert = "UPDATE view SET account_no = '$aa', token_id = '$t', name = '$n', address = '$ad', state = '$s', country = '$c' WHERE cartId = '$cartId'";
$result_insert = mysql_query ($insert) or die(mysql_error());
// Successful add the new customer.
echo '<h3>Successful the transaction</h3>';
include ('includes/header_bank.html');
exit();
} else {
echo '<p><font color="red" size="+1">Cannot update to the database</font></p>';
}
} else if ($comparison == "2"){
$query2 = "INSERT INTO view (itemId, price, qty, cartId) VALUES ('$itemId','$price','$qty','$cartId' )";
$result3 = mysql_query($query2) or die(mysql_error());// Run the query.
if ($result3) {
$insert1 = "UPDATE view SET account_no = '$aa', token_id = '$t', name = '$n', address = '$ad', state = '$s', country = '$c' WHERE cartId = '$cartId'";
$result_insert1 = mysql_query ($insert1) or die(mysql_error());
} else {
echo '<p><font color="red" size="+1">Cannot update to the database</font></p>';
}
$query3 = "INSERT INTO view (itemId, price, qty, cartId) VALUES ('$itemId','$price','$qty','$cartId' )";
$result4 = mysql_query($query3) or die(mysql_error());// Run the query.
if ($result4) {
$insert2 = "UPDATE view SET account_no = '$aa', token_id = '$t', name = '$n', address = '$ad', state = '$s', country = '$c' WHERE cartId = '$cartId'";
$result_insert2 = mysql_query ($insert2) or die(mysql_error());
// Successful add the new customer.
echo '<h3>Successful the transaction</h3>';
include ('includes/header_bank.html');
exit();
} else {
echo '<p><font color="red" size="+1">Cannot update to the database</font></p>';
It appear this error
Notice: Undefined index: itemId in C:\Program Files\Apache Group\Apache2\htdocs\change_checkout.php on line 93
Notice: Undefined index: price in C:\Program Files\Apache Group\Apache2\htdocs\change_checkout.php on line 94
Notice: Undefined index: qty in C:\Program Files\Apache Group\Apache2\htdocs\change_checkout.php on line 95
Notice: Undefined index: cartId in C:\Program Files\Apache Group\Apache2\htdocs\change_checkout.php on line 96
can you please help me to solve this problem? I really appreciated your help?
Posted: Sun Mar 06, 2005 6:54 am
by JAM
Try replacing...
Code: Select all
while($row = mysql_fetch_row($result1)) {
with...
Code: Select all
while($row = mysql_fetch_assoc($result1)) {
...or...
Code: Select all
while($row = mysql_fetch_array($result1)) {
Posted: Sun Mar 06, 2005 6:35 pm
by elle_girl
i try to do with
Code: Select all
while($row = mysql_fetch_array($result1)) {
It does not appear the error. But it appear the result
Cannot purchase more than 2 product for each transaction
Is this because the way I do the coding for the comparison is wrong?In the comparison I want to count how many row are there in the table so that I can insert all the data to the other table?Pleasehelp me? I really appreciate your help.