vinpkl Posted April 5, 2011 Share Posted April 5, 2011 hi i m adding the last field to my query but getting unexpected t_string error $order_detail="insert into detail_table(unique_id,order_id, customer_name, customer_login_id, order_date, product_name, quantity, shipping, price,total_cost,compatibility) values('$unique_id',$order_id,'$username','$log_id','$shop_date','".$row['product_name'] . "' , " . $row['quantity'] . "," . $row['shipping_cost'] . ",". $row['price'] .",". $row['total_cost']. ",". '". $row['compatibility'] . "'. ")"; mysql_query($order_detail); help me remove it vineet Link to comment https://forums.phpfreaks.com/topic/232783-remove-unexpected-t_string-error/ Share on other sites More sharing options...
kanikilu Posted April 5, 2011 Share Posted April 5, 2011 Not positive on this, but try: $order_detail="INSERT INTO detail_table (`unique_id`, `order_id`, `customer_name`, `customer_login_id`, `order_date`, `product_name`, `quantity`, `shipping`, `price`, `total_cost`, `compatibility`) VALUES ('" . $unique_id . "', '" . $order_id . "', '" . $username . "', '" . $log_id . "', '" . $shop_date . "', '" . $row['product_name'] . "', '" . $row['quantity'] . "', '" . $row['shipping_cost'] . "', '" . $row['price'] . "', '" . $row['total_cost'] . "', '" . $row['compatibility'] . "')"; I'd think you could just escape those quotes instead of concatenating, but, it probably doesn't make much difference... Link to comment https://forums.phpfreaks.com/topic/232783-remove-unexpected-t_string-error/#findComment-1197397 Share on other sites More sharing options...
Pikachu2000 Posted April 5, 2011 Share Posted April 5, 2011 There's no need to use all of that string concatenation, it just leads to typo errors, as you've seen. $order_detail="insert into detail_table(unique_id,order_id, customer_name, customer_login_id, order_date, product_name, quantity, shipping, price,total_cost,compatibility) VALUES ('$unique_id', $order_id, '$username', '$log_id', '$shop_date', '{$row['product_name']}', {$row['quantity']}, {$row['shipping_cost']}, {$row['price']}, {$row['total_cost']},'{$row['compatibility']}' )"; mysql_query($order_detail); Link to comment https://forums.phpfreaks.com/topic/232783-remove-unexpected-t_string-error/#findComment-1197498 Share on other sites More sharing options...
spiderwell Posted April 6, 2011 Share Posted April 6, 2011 So the curly brackets around the $row['something'] variables are an alternative to the concatenation? I not seen this before so am curious to how & why that works. Link to comment https://forums.phpfreaks.com/topic/232783-remove-unexpected-t_string-error/#findComment-1197511 Share on other sites More sharing options...
ttocskcaj Posted April 6, 2011 Share Posted April 6, 2011 I've always found it works best if you assign array values to a seperate variable first. eg $product_name = $row['product_name']; $quantity = $row['quantity']; That way you don't have problems with typos etc. Are you using the correct version of php? When I upload my files to my host (1and1) and I don't set it to use php5 it will show T_String erros. Also are you using an IDE. It should find any errors you have. Link to comment https://forums.phpfreaks.com/topic/232783-remove-unexpected-t_string-error/#findComment-1197529 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.