Question:
MYSQL QUERY ROW NOW INSERTING URGENT HELP!!?
unluckygirl
2010-01-04 05:48:30 UTC
hello for some reason my insert into query works but it forgets to insert one value which is the price.

I have queried the price from another database given it a variable name and then put it into my insert query. The update query works its just this insert into query please could you help?

my code is as follows:



$res = "SELECT *"."FROM love_cart,products "."WHERE love_cart.gst_id = '$sescart'&& products.cap = '$shwq'";

$reso = mysql_query($res) or die(mysql_error());

while($row = mysql_fetch_array($reso))

{
$chckp = $row['prod_name'];
$prce = $row['price'];
$lks = $row['size'];
}
if($q == $chckp && $lks = $qzqq )


$resup = mysql_query("UPDATE love_cart SET qty=qty+1,pricecrt=pricecrt+'$prce' WHERE gst_id='$sescart'&& prod_name='$shwq'&& size='$qzqq'")
or die(mysql_error());

else

mysql_query("INSERT INTO love_cart (gst_id,prod_name,pricecrt,qty,size) VALUES ('$sescart','$shwq','$prce','1','$qzqq')")
or die(mysql_error());


$req = "SELECT qty, SUM(qty) FROM love_cart WHERE gst_id='$sescart'";

$reqty = mysql_query($req) or die(mysql_error());


while($qre = mysql_fetch_array($reqty)) {

$qty = $qre['SUM(qty)'];

if($qty>0)

echo"My bag has $qty items $prce";

}
?>
Four answers:
?
2010-01-04 07:14:12 UTC
None of your queries respect the "recommended" mysql syntax...

$res = "SELECT *"."FROM love_cart,products "."WHERE love_cart.gst_id = '$sescart'&& products.cap = '$shwq'";

=>

$res = "select * from `products` where `gst_id` = '" . $sesscart . "' and `cap` = '" . $shwq . "'";

1. table and field names must be enclosed in reverse single quotes.

2. Values must be enclosed in single quotes. Expanded: `cap` = ' " . $val . " '

3. Php does not parse variable in Single quotes (MUST be double quotes).

4. In the above query, you seem to be using two tables: you must use the JOIN command in that case.

5. mysql commands in lower cases (will be a requirement in future versions, so start now!)



Similarly:

set `qty` = `qty` +1, `pricecrt` = `pricecrt` + " . $prce . "



Similarly:

INSERT INTO love_cart (gst_id,prod_name,pricecrt,qty,size) VALUES ('$sescart','$shwq','$prce','1','$qzqq')…

"insert into `love_cart` ( `gst_id`, `prod_name`, ... ) values ( '".$sescart."', '".$shwq."' ...)

expanded: ( ' " . $sescart . " ' , ...



SOME servers will work with your syntax. Most recents simply won't.
MyKidsFan
2010-01-04 06:07:26 UTC
I'm not very well versed in mysql so nothing stands out immediately to me. If I were debugging this I would create the query and assign it to a variable before the call to mysql_query and then print it. Then I would copy it into a program like phpadmin to see what error it returns. That usually tells me what I've done wrong (or at least where the error is). Sometimes just printing it out is enough for me to see what is wrong.



Could it be the single quotes around '$prce' ?
cool_dog
2010-01-04 05:58:13 UTC
You will need to debug your query step by step. I would suggest you put in some print statements to display what the values are for the variables to see if your logic is processing the way you think it should. It could be that your logic is correct, but the data is not corresponding to what you have coded.
2016-11-03 06:38:59 UTC
Grand theft automobile 3 - Grand theft automobile: San Andreas and easily Saint Row 2; Saint Row a million, 3 & 4 are terrible and ruining the sequence interior of itself. Grand theft automobile IV is organic torture, yet people act like this is nonetheless Rockstars God present to Video gaming. -The Roads are black ice - the wrestle/conceal gadget is previous broken - the missions are asinine and throw you into maximum of circumstances without an regards or care in case you already know what you're doing or not (First Race, First time on a motorbike, First time on a boat, First time in a helicopter). - The characters are forgettable - The missions, in the event that they weren't so insufferable annoying could be forgettable pointless. - you do not care approximately something or absolutely everyone - you opt to overwhelm your cellular telephone decrease than a automobile. as quickly as I reviewed this interest i attempted to attend and notice and notice what the hype grew to become into, yet to be truthful I nonetheless don't get why people overrate Grand theft automobile IV so terrible. i'm not likely on a limb by any ability by using asserting Saint Row 2 did each thing, better then Grand theft automobile IV. I doubt Grand theft automobile V would be any better then Grand theft automobile IV, specifically through fact diverse the fanbase disregarded the obtrusive crystal sparkling issues interior of Grand theft automobile IV. honestly everyone who shows honestly everyone to play the Manhunt sequence would not comprehend a rattling element approximately video games, that interest is an atrocity.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...