stevieontario Posted January 9, 2011 Share Posted January 9, 2011 Afternoon Freaks, PHP Version 5.2.15 mysql server 5.1.48-log MySQL client version: 5.1.48 I loaded the following code and got no errors but also no data appears in db2.table3. <?php $db_hostname = "localhost"; $db_name = "db1"; $db_username = "user1"; $db_password = "pw1"; $cxn = mysql_connect($db_hostname,$db_username,$db_password) or die ("Could not connect: " . mysql_error()); mysql_select_db($db_name); $db_name2 = "db2"; $db_username2 = "user2"; $db_password2 = "pw2"; $cxn2 = mysql_connect($db_hostname,$db_username2,$db_password2) or die ("Could not connect: " . mysql_error()); mysql_select_db($db_name2); $sql1 = "SELECT sourceid as sourceid2, unitname, fuel, output, capability, capabilityfactor, generated, version as hour FROM table1, table2 where table1.sourceid=table2.id and fuel like 'gasoline%'"; $result = mysql_query($sql1, $cxn) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql1 . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); while ( $row = mysql_fetch_assoc($result)) { extract($row); $sql2 = "insert into db2.table3 (sourceid2, unitname, fuel, output, capability, capabilityfactor, generated, hour) values ('$sourceid2', '$unitname', '$fuel', '$output', '$capability', '$capabilityfactor', '$generated', '$hour')"; $result1 = mysql_query($sql2, $cxn2); } ?> I pre-tested it in xampp on my pc, and it worked fine. I suspect it has something to do with the fact that I'm testing it on a live server, but I'm stumped -- no errors are displayed either on the screen or on my server error log. Any ideas? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/223889-php-file-containing-mysql-insert-query-loads-without-error-but-no-data-inserted/ Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 You aren't checking if the second query was successful, or asking it to return any errors. Quote Link to comment https://forums.phpfreaks.com/topic/223889-php-file-containing-mysql-insert-query-loads-without-error-but-no-data-inserted/#findComment-1157112 Share on other sites More sharing options...
stevieontario Posted January 9, 2011 Author Share Posted January 9, 2011 Ahh, thanks Pika. okay, I put in an error statement and got the following fatal mysql error: Error: (1142) INSERT command denied to user 'user2'@'localhost' for table 'table3' Odd: I checked username and password and can't see anything wrong, plus I gave user2 -- i.e., myself -- all privileges. I'm checking with my provider, maybe this is at their end. Quote Link to comment https://forums.phpfreaks.com/topic/223889-php-file-containing-mysql-insert-query-loads-without-error-but-no-data-inserted/#findComment-1157136 Share on other sites More sharing options...
stevieontario Posted January 9, 2011 Author Share Posted January 9, 2011 Ahh, thanks Pika. okay, I put in an error statement and got the following fatal mysql error: Error: (1142) INSERT command denied to user 'user2'@'localhost' for table 'table3' Odd: I checked username and password and can't see anything wrong, plus I gave user2 -- i.e., myself -- all privileges. I'm checking with my provider, maybe this is at their end. Quote Link to comment https://forums.phpfreaks.com/topic/223889-php-file-containing-mysql-insert-query-loads-without-error-but-no-data-inserted/#findComment-1157141 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.