-
February 17th, 2008, 01:00 PM
#1
insert query failed.. only when online
hi...
i've a php code which works perfectly when it's on my localhost apache server... but when i uploaded it onto my server on the internet.. it gives an error... here's the partial code:
Code:
<?PHP
$name = addslashes($_POST['name']);
$crimeType = addslashes($_POST['crimeType']);
$crimeDesc = addslashes($_POST['crimeDesc']);
$crimeLocationTown = addslashes($_POST['crimeLocationTown']);
$crimeLocationState = addslashes($_POST['crimeLocationState']);
$locationLatLng = addslashes($_POST['locationLatLng']);
echo $name;
echo $crimeType;
echo $crimeDesc;
echo $crimeLocationTown;
echo $crimeLocationState;
echo $locationLatLng;
//set the database connection variables
$dbHost = "localhost";
$dbUser = "test";
$dbPass = "testtest";
$dbDatabase = "testdb";
//$reportDate = date("Y-m-d");
//connect to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$query ="insert into userReport (reportPerson,crimeType,crimeDesc,crimeLocationTown,crimeLocationState,locationLatLng) values
('$name','$crimeType','$crimeDesc','$crimeLocationTown','$crimeLocationState','$locationLatLng')";
mysql_query($query) or die('Error, insert query failed');
echo 'data inserted';
?>
if it's on my local server, it will return 'data inserted'. but if i put it on my hosting, it will return 'insert query failed'. my other php page which also go insert query works well, but not this page. is it possible if I mis-constructed the mysqsl table on my hosting? but i've triple check the table and it's the same as the mysql table on my pc.
please help. thanks a lot
Last edited by imin; February 18th, 2008 at 01:13 AM.
-
February 17th, 2008, 05:20 PM
#2
Re: insert query failed.. only when online
Your connection string will be different on your hosted server rather than the localhost. Your mysql_connect() is most likely failing for this reason.
You might want to edit your previous post and remove the vital information (username and password).
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 18th, 2008, 01:18 AM
#3
Re: insert query failed.. only when online
Originally Posted by PeejAvery
Your connection string will be different on your hosted server rather than the localhost. Your mysql_connect() is most likely failing for this reason.
You might want to edit your previous post and remove the vital information (username and password).
Thanks for replying. But the problem is not with the connection string, as the same string works for other page. But i've found (?) the problem; it's actually because my table name supposed to be all lowercase. When I change the table name to lowercase, the query works. But one thing puzzled me, after that, I tried changing the table name to lowercase and uppercase (like beforee), it still works..huhuhu.. .anyway the good thing is the problem doesn't appear again (for the time being)
thanks for your notice on editing the crucial db information
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|