skygremlin Posted September 4, 2013 Share Posted September 4, 2013 Insert function not working like the select functions are.. :~ I have a functions file that contains a number of mysqli_query query's that other php pages successfully call, including the page in question. For round numbers I have 10 functions total. Of the 10, 9 are select query's, 1 is an insert. All of the select query's work including 2 on the page in question. These 2 query's populate 2 drop down menus in a form. When I submit the form I am $_POST ing all the fields to another PHP file that parses the data, calls the insert function -> sends the values, then sends an e-mail using PHPMailer.. When I call the Insert query (submit the form), I am returned "Error updating databaseNo database selected" Error. All of the php pages have an include statement on top pointing to a connection file. IF I put a DB connection string inside the insert function, per below, the insert function works when called.. There's gotta be something basic I'm missing with how I have my stuff setup.. Does anybody have advice? Or I guess I could have everything on one page / file.... mysql_connect("server", "user", "pass") or die('Can\'t connect because:' .mysql_error()); mysql_select_db ("database"); thanx Quote Link to comment https://forums.phpfreaks.com/topic/281857-basic-mysql-php-question/ Share on other sites More sharing options...
Psycho Posted September 4, 2013 Share Posted September 4, 2013 You first state that you are using mysqli_, but the connection code you have uses just mysql_. So, something isn't adding up. But, assuming you are using the right connection code for the database queries you are running, then the connection code isn't running on the page that does the insert. Put an echo in the include file that does the connection and go through the process that should insert a record to verify that page is getting called. Quote Link to comment https://forums.phpfreaks.com/topic/281857-basic-mysql-php-question/#findComment-1448174 Share on other sites More sharing options...
Solution skygremlin Posted September 4, 2013 Author Solution Share Posted September 4, 2013 grrrr - As i was editing my reply I saw a stupid error... thanx for pointing out the mysql_ line... first off I didn't catch that.. I am using mysqli (well converting all my mysql -> mysqli) and my insert statement was still using mysql_query and that syntax.. I changed to mysqli_query ($connection, $query) and it works... thanx for the extra pair of eyes and the quick response...... Who knows how long I would have looked (overlooked) that.. Quote Link to comment https://forums.phpfreaks.com/topic/281857-basic-mysql-php-question/#findComment-1448177 Share on other sites More sharing options...
skygremlin Posted September 4, 2013 Author Share Posted September 4, 2013 grrrr - As i was editing my reply I saw a stupid error... thanx for pointing out the mysql_ line... first off I didn't catch that.. I am using mysqli (well converting all my mysql -> mysqli) and my insert statement was still using mysql_query and that syntax.. I changed to mysqli_query ($connection, $query) and it works... thanx for the extra pair of eyes and the quick response...... Who knows how long I would have looked (overlooked) that.. Quote Link to comment https://forums.phpfreaks.com/topic/281857-basic-mysql-php-question/#findComment-1448178 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.