Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
can insert mysql record on localhost but not server!
Old 08-22-2007, 08:44 AM can insert mysql record on localhost but not server!
Average Talker

Posts: 27
Trades: 0
For my site, I have a page using php to insert a record into a table in my database. The problem I have come across is that it works absolutely fine when testing on my apache localhost, but when I try it live into my mysql database on my 1and1 server it will not insert the record.

I am using dreamweaver and the connection settings are fine, as there are other areas on the site that insert/update/delete records fine using the behaviours from dreamweaver. In this page though, I am hand coding the php as the data to be inserted is not from a form so I am using the simple code:

mysql_query("INSERT INTO products (product_name, product_description, product_thumb, prodcat_id, product_price, product_special)
VALUES ('football', 'a red football', 'ball.jpg', '2', '10.99', 'Y')");


Like I say, I have correctly defined the database connection but it seems very odd that it will work on my apache localhost/mysql setup but not the live server/database. I have even tried different pieces of code for inserting the record, even copying the suggested php code from phpmyadmin on the live database but to no avail.
gavrd1 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-22-2007, 09:22 AM Re: can insert mysql record on localhost but not server!
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
What is the error reported by the server when you try to run your query ?
Is there a syntax error, or any informations ?

Are you running the query directly, or through an server side language (php, asp, jsp...)?

Edit:
ok, I just saw mysql_query(), this mean you are running it through php. You should have put it there, it would had more coverage.
Anyway, try to alter your line to add an error handler:
PHP Code:
$res=mysql_query("INSERT INTO products (product_name, product_description, product_thumb, prodcat_id, product_price, product_special) 
   VALUES ('football', 'a red football', 'ball.jpg', '2', '10.99', 'Y')"
);
 if(!
$res){
  echo 
mysql_error();
  die();

This will display the error message returned by the db and stop the script.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 08-22-2007 at 09:24 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-23-2007, 03:25 PM Re: can insert mysql record on localhost but not server!
Extreme Talker

Posts: 182
Trades: 0
If you post back the error message, we should have no problem solving the problem.

Btw, a simpler way to return errors is:

$query = mysql_query ( "SELECT * FROM..." ) or die ( mysql_error ( ) );
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-23-2007, 03:57 PM Re: can insert mysql record on localhost but not server!
Super Talker

Posts: 130
Trades: 0
One thing that I do when I have an error is to run the query manually through phpmyadmin.

However, any error that gets output by bhgchris' suggestion, would most likely be the same error output my phpmyadmin.

Also, I know you said your connection string is correct, but two things.
1. phpmyadmin appends your user account name to your database name.

2. In phpmyadmin, did you add your user to the database and give it appropriate permissions?
__________________
flann

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
flann is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to can insert mysql record on localhost but not server!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19692 seconds with 12 queries