Jump to content

php file containing mysql insert query loads without error, but no data inserted


stevieontario

Recommended Posts

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!

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.