Namtip Posted November 1, 2010 Share Posted November 1, 2010 1: whats the point of printf? I mean can't you just make do with sprintf? 2:How do you go about putting the following table into sprintf? $query = 'INSERT INTO order_details (order_id, order_qty, product_code, buyer_id, name_id) SELECT ' . $order_id . ', qty, product_code, ' . $_SESSION['name_id'] . ', name_id FROM cart WHERE session = "' . $session . '"'; mysql_query($query, $db) or (mysql_error($db)); I've checked google for both questions. If you think I'm being cheeky could you just answer my first question and ignore my second. Quote Link to comment Share on other sites More sharing options...
trq Posted November 1, 2010 Share Posted November 1, 2010 1. sprintf is used to format a string, printf is used to format and output a formatted string. 2. Your query makes little sense as is. Quote Link to comment Share on other sites More sharing options...
Namtip Posted November 1, 2010 Author Share Posted November 1, 2010 Thanks for the response Thorpe, the query is copied directly from my text book except for the names of the column and tables, but apart from that the layout is exactly the same. It just selects the information from the users cart and enters it into orders before the cart information is deleted. It works as intended but I guess theres prolly a better way. So I guess I have to use printf too. Thanks for the information. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted November 1, 2010 Share Posted November 1, 2010 $query = sprintf("INSERT INTO order_details (order_id, order_qty, product_code, buyer_id, name_id) SELECT %d, qty, product_code, '%s', name_id FROM cart WHERE session = '%s'", $order_id, mysql_real_escape_string($_SESSION['name_id']), $session); mysql_query($query, $db) or (mysql_error($db)); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.