sabinmash Posted December 2, 2011 Share Posted December 2, 2011 An insert function is not inserting. I keep getting "Could not store data, please try again." After some probing, it seems that "$result = $conn->query($user_degree_insert_query); " is where the problem is. Variables before it seem to pass testing. I can't figure out why this line is messing thins up though. Any idea? Thank you in advance for your help! The "//$degree_id = mysql_fetch_array($degree_id_query, MYSQL_BOTH) ;" is commented out because it was giving me trouble, i replaced it with the line above that $conn = db_connect(); $arraycount = count($degree_Array); //loop through the categories chosen and add them each into member-category for($i =0; $i < $arraycount; $i++){ $degree_id_query = "SELECT degree_id FROM degree WHERE degree_type ='".$degree_Array[$i]."'"; $result = $conn->query($degree_id_query); //place the id found into the array, which automatically cancatonates it. $degree_id = $result->fetch_array(); //$degree_id = mysql_fetch_array($degree_id_query, MYSQL_BOTH) ; $user_degree_insert_query = "INSERT INTO user-degree ( `user_id` , `degree_id` ) VALUES ( '".$user_id."', '".$degree_id[0]."' )"; $result = $conn->query($user_degree_insert_query); if($result) { header("Location: survey2.php"); }else { echo "<p>Could not store data, please try again.</p>"; exit; Quote Link to comment Share on other sites More sharing options...
sabinmash Posted December 2, 2011 Author Share Posted December 2, 2011 Gosh, i just figured it out. $user_degree_insert_query = "INSERT INTO `user-degree`( user-degree didn't have the surrounding ``. Why is it that sometimes it seems i need these and sometimes not. Quote Link to comment Share on other sites More sharing options...
Drongo_III Posted December 2, 2011 Share Posted December 2, 2011 Does this line in your code work? $degree_id_query = "SELECT degree_id FROM degree WHERE degree_type ='".$degree_Array[$i]."'"; Surely if you wrap a double quoted variable in single quotes it will be taken as a literal and not the value it represents? Gosh, i just figured it out. $user_degree_insert_query = "INSERT INTO `user-degree`( user-degree didn't have the surrounding ``. Why is it that sometimes it seems i need these and sometimes not. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 2, 2011 Share Posted December 2, 2011 Database, table, and column names may only contain alphanumeric characters and the under_score character. Using any other characters in the name, having an all numeric name, or a name that is a reserved mysql keyword requires special handling. The use of back-ticks `` around the name identifies it as a database, table, or column name that requires special handling. We generally suggest using a different name that doesn't require special handling so that you don't need to use any extra syntax to make them work. 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.