Jump to content


Photo

What could this issue be?

mysql php query

  • Please log in to reply
7 replies to this topic

#1 trg86

trg86

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 31 January 2013 - 09:34 PM

Okay, I know some of you the past month or so know of the project I am working on right now. I have been pulling my hair out trying to figure out what is causing this issue today. I just got done moving my database from one server (most development) to another server (where it needs to be when its done). Now, the only thing I had to change after the move within my programming was the MySQL login/database info (i.e. username, password, database name, host). But...this is the problem. It no longer wants to insert the data from the form into the database, it's pretty much like it is not firing, even though it works fine on the other server. Does anybody have any suggestions on what could be causing this issue? Thanks ahead of time!! :)

#2 PFMaBiSmAd

PFMaBiSmAd

    Advanced Member

  • Staff Alumni
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 31 January 2013 - 09:48 PM

You need to debug exactly where your code and data are doing what you expect and exactly at what point they are not to pin down the problem.

Is the form submitting the expected $_POST data? Is the code where the query at even being executed? Is the query producing an error when it runs? Is the page blank (and if it is, what does the 'view source' in the browser show)? Are there any php detected errors in the error log? Do you have php's error_reporting set to E_ALL and display_errors set to ON or log_errors set to ON, so that all the php detected errors will be reported and displayed/logged?
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#3 trg86

trg86

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 01 February 2013 - 09:57 PM

Thanks for your reply. As I said in my original post, everything was working fine for the entire development process so far, until I moved it to the new server. All I changed within my programming, after the server move, was the connection info to the new database, none of my other programming was changed/moved.

There are no errors on the page, it still sends the $_POST data to my e-mail inbox and still loads the success page after submission, it just doesn't want to post to the new database for some reason...I can't seem to figure this out. :)

#4 DavidAM

DavidAM

    Advanced Member

  • Gurus
  • 1,976 posts
  • LocationSpring, TX USA

Posted 01 February 2013 - 11:16 PM

Are you certain the username and password are valid for the server?

Does the user have INSERT/UPDATE/DELETE/SELECT Privileges in the database?
... for the tables?

You need to echo or log the mysql_error() message if the connection fails, or a query fails. It will tell you why it failed.
-- I haven't lost my mind, it's backed up on tape ... somewhere!

#5 trg86

trg86

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 01 February 2013 - 11:32 PM

Thanks for the reply David. Yes, I am positive that the username and password are correct, after-all, I still login to phpMyAdmin successfully, which is the same username and password.

My account has full privileges, that is definitely not the issue. :)

I am using
echo mysql_error()
but I am not getting any error messages.

Additionally, I also have
error_reporting(E_ALL);
ini_set("display_errors", 1);
in use.

Edited by trg86, 01 February 2013 - 11:33 PM.


#6 Psycho

Psycho

    Advanced Member

  • Gurus
  • 10,964 posts
  • LocationCanada

Posted 02 February 2013 - 03:34 AM

Debugging is not hard - you just need to determine where the different conditions/branches are in the logic and then TEST before and after the condition to see what is actually happening.

You say that the code has not changed, you are not getting any errors, and everything is working except for the data not getting in the database.

If you are checking for errors and none are occurring there are two possible conclusions that I can think of:

1. Your script is inserting records into a different database/table than you think it is.

2. The code to do the insertion is not getting executed because of same conditions/logic in the code

So, it is simple to check to see if the insert query is being executed at all. just find where you have the insert query and create a couple of echo statements to validate

$query = "INSERT INTO table (fiel1, field2, field3)
		 VALUES ('$value1', '$value2', '$value3')";
echo "Executing query: $query<br>";

$result = mysql_query($query);
if(!$result)
{
    echo "Error: " . mysql_error();
}
else
{
    echo "Successfully inserted " . mysql_affected_rows() . " records";
}

Either you will see that text on the page and will know for certain what is happening or you won't see anything - which means that code is not getting executed and you need to look at your branching logic.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#7 trg86

trg86

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 02 February 2013 - 10:15 PM

Psycho,

Thank you very much for the reply, I looked at your example code for debugging and wrote it into mine, for testing purposes. I am beginning to think it is not being executed for some reason, as I am still receiving the data in it's e-mail form and being re-directed to the success page, basically, I am not getting any different result than I was before. Would it be helpful if I post more of my code? Is there anything specific you want to see?

Ugh, this is one of those annoying glitches, mainly because nothing was changed besides the database info for the new server...it's really odd to me how it could just stop working after working flawlessly on a different server...mind boggling I tell you!! :)

Edited by trg86, 02 February 2013 - 10:15 PM.


#8 PFMaBiSmAd

PFMaBiSmAd

    Advanced Member

  • Staff Alumni
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 03 February 2013 - 03:48 AM

and being re-directed to the success page


That implies that php's output_buffering might be turned on in your php.ini, which would discard any status or error messages being outputting on the page.

You can check the output_buffering setting by using a phpinfo statement on a page. If output_buffering is turned on, you should turn it off because all it does it hide problems and waste computer resources and human time.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com