Jump to content

Basic MySql / PHP question


skygremlin
Go to solution Solved by skygremlin,

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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..:(

Link to comment
Share on other sites

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..:(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.