Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Connection Problem 1

Status
Not open for further replies.

dagger2002

Programmer
Nov 23, 2004
172
US
I am running a data drivin site and am writing the update portion. My add new meetings part works, now i need to b able to edit the records. It works to show the record and to edit info but it won't write to the database. If I take the query that the code creates and drop it in to phpMyAdmin it works and updates the database. any ideas?

Replace code:
Code:
REPLACE INTO meetings SET mtg_id="5", date="2005-01-01", type="M", text="Fried Green Tomatoes751", include="1"

database:
Code:
CREATE TABLE `meetings` (
  `mtg_id` int(4) NOT NULL auto_increment,
  `date` date NOT NULL default '0000-00-00',
  `type` char(1) NOT NULL default '',
  `text` text NOT NULL,
  `include` smallint(1) NOT NULL default '1',
  PRIMARY KEY  (`mtg_id`)
) TYPE=MyISAM AUTO_INCREMENT=8 ;

-- 
-- Dumping data for table `meetings`
-- 

INSERT INTO `meetings` VALUES (5, '2005-01-01', 'M', 'Fried Green Tomatoes751', 1);
INSERT INTO `meetings` VALUES (4, '2005-01-01', 'M', 'David123', 0);
INSERT INTO `meetings` VALUES (6, '0000-00-00', 'A', '50550500505464657894131498641564589784567964216746546465\r\n56465467895645796456467987613464646446465465498798464998', 1);
INSERT INTO `meetings` VALUES (7, '0000-00-00', 'A', 'Frankfooter\r\n', 1);
 

What version pof MYSQL are you using?
What error do you get if at all?
What does the query look like?
Have you tried using UPDATE instead of REPLACE?

Need more info for a meaningful answer?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
What does the query look like?
Code:
REPLACE INTO meetings SET mtg_id="5", date="2005-01-01", type="M", text="Fried Green Tomatoes751", include="1"

update dosn't work.

The string itself works if i put it in phpMyAdmin.
if i use it through my php form it doesn't work and i get my error message i wrote.
 
Part of the problem is going to be that you've used MySQL reserved words for column names: "date" and "text". I'll wager that just as a matter of course PHPMyAdmin places backticks ("`" characters) around all column names -- this is what MySQL requires if you use reserved words as identifiers. (See the listing of your CREATE TABLE query above)

I strongly recommend that you change the two column names to something that both do not collide with MySQL's reserved words and also are more descriptive.

I also strongly recommend that you use as much error-catching in your PHP code as possible.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Sleipnir is right, [red]date[/red]and[red]text[/red] are reserved words, and are most likely causing problems.

Also using [blue]mysql_error[/blue] after executing the query might give you an insight into what is actually going on.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ok guys I fixed the above. i am still getting the same error. I even tried just getting it to work with 1 field other then id

Any ideas?
 
Had not noticed this before but:

You can't change the contents of an autoincrement field the part in red.
Code:
REPLACE INTO meetings SET [red]mtg_id="5"[/red], mtgdate="2005-01-01", type="M", mtgtext="Fried Green Tomatoes751", include="1"

What happens if you don't set the ID but instead use t to set that particular record?

Code:
REPLACE INTO meetings SET mtgdate="2005-01-01", type="M", mtgtext="Fried Green Tomatoes751", include="1" WHERE [red]mtg_id="5"[/red]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
how do I put in the mysql_error command? where do I put it?
 
wherever in your PHP code where you have the mysql_query command such as:
Just add the blue part after the mysql_query command.
Code:
$res=mysql_query("REPLACE...") [blue]or die(mysql_error());[/blue]

If there was something wrong with the query it will tell you exactly what.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you that worked Perfect.

It was that I didn't have delete permission
 
Glad you sorted it out.
Its a good practice to have error checking or your query results.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top