Jump to content

MySQL INSERT INTO Issue


rj.alaskan

Recommended Posts

I am a fairly decent PHP coder, and I have a sufficient knowledge of MySQL to be considered competent. However, I have run across an issue I have never seen before, and after hours of troubleshooting, I still cannot figure out what is the issue. I am writing a script to monitor server status and log uptime. I have everything working except the logging part. Here is my code and query:

 

mysql_connect ('localhost', 'root', 'm@t$u33');
mysql_select_db ('servers');

//update log with statistics
$logquery = 'INSERT INTO server_log (uid, datetime, icmp_lat, tcp_lat, net_stat, tcp_stat) VALUES ("'.$UID.'", NOW(), "'.$icmp_lat.'", "'.$tcp_lat.'", "'.$net_stat.'", "'.$tcp_stat.'")';
mysql_query ($logquery);
echo $logquery;
echo mysql_error();

 

The echo echoes the query like this:

 

INSERT INTO server_log (uid, datetime, icmp_lat, tcp_lat, net_stat, tcp_stat) VALUES ("1", NOW(), "6.5088272094727E-5", "0.0003809928894043", "UP", "UP")

 

And the echo for the mysql_error() does not echo anything. All is well, right? I check phpMyAdmin to see if the log is really getting updated, and there are zero rows inserted. Weird, I thought. So I copy the echoed query and paste it into a mysql client prompt:

 

mysql> use servers;
Database changed
mysql> INSERT INTO server_log (uid, datetime, icmp_lat, tcp_lat, net_stat, tcp_s
tat) VALUES ("2", NOW(), "0.00050783157348633", "0.00083398818969727", "UP", "UP
");
Query OK, 1 row affected (0.00 sec)

mysql>

 

The query worked just fine, verified by phpMyAdmin. I have tried changing the database engine, I am currently using MyISAM. I am completely clueless as to why it is not working.

 

Table structure:

 

mysql> show create table server_log\g
+------------+------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
| Table      | Create Table


                         |
+------------+------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
| server_log | CREATE TABLE `server_log` (
  `uid` int(3) NOT NULL,
  `datetime` datetime NOT NULL,
  `icmp_lat` int(4) NOT NULL,
  `tcp_lat` int(4) NOT NULL,
  `net_stat` varchar(4) NOT NULL,
  `tcp_stat` varchar(4) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+------------+------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
1 row in set (0.02 sec)

mysql>

 

MySQL version: 5.5.16

 

Any help will be greatly appreciated! Let me know if you need more of my code!

 

Thanks in advance!

Link to comment
Share on other sites

Thanks for the reply, sorry for wasting your time, I found out what was wrong. I have several places where the logic tree could terminate and log results, and when I went to insert the code you specified, I saw that the place the logic was leading to did not have the line

 

mysql_query($logquery);

 

So thank you for having me reevaluate my code, I will be much more careful about posting next time. It seems like it is always the smallest, dumbest things. I love your sig tag line by the way

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.