melting_dog Posted March 4, 2012 Share Posted March 4, 2012 Hi guys, I have a simple INSERT code. It does not throw any errors and all seems ok but the data is just not appearing in the DB. I've spent ages looking over it but perhaps a 2nd set of eyes could help? Thanks! $con = mysql_connect("localhost","posturep",""); $tablename = 'product'; if (!$con) { die('Could not connect: ' . mysql_error()); } //Form data sent $product_name = $_POST['product_name']; $product_active = $_POST['product_active']; $product_cat = $_POST['product_cat']; $product_desc = $_POST['product_desc']; $prod_inoutdoor = $_POST['prod_inoutdoor']; $prod_stackable = $_POST['prod_stackable']; $prod_discounted = $_POST['prod_discounted']; echo $product_name; $sql = "INSERT INTO $tablename (name) VALUES ($product_name)"; mysql_query($sql); echo "<p>Product Saved!</p>"; echo $sql; mysql_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/258220-probably-easy-solution-but-its-got-me-stumped/ Share on other sites More sharing options...
scootstah Posted March 4, 2012 Share Posted March 4, 2012 What does the query look like when you print it out? Quote Link to comment https://forums.phpfreaks.com/topic/258220-probably-easy-solution-but-its-got-me-stumped/#findComment-1323638 Share on other sites More sharing options...
litebearer Posted March 4, 2012 Share Posted March 4, 2012 in your query you need single quotes around $product_name ie '$product_name' Quote Link to comment https://forums.phpfreaks.com/topic/258220-probably-easy-solution-but-its-got-me-stumped/#findComment-1323641 Share on other sites More sharing options...
melting_dog Posted March 4, 2012 Author Share Posted March 4, 2012 in your query you need single quotes around $product_name ie '$product_name' Yep that was it! Thanks! - just having one of those days! Quote Link to comment https://forums.phpfreaks.com/topic/258220-probably-easy-solution-but-its-got-me-stumped/#findComment-1323643 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.