| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Feb 2005
Posts: 578
![]() ![]() ![]() | update the database with a php file. 100np$ I have a little database like this and sometime i need to edit the quotes/author. I tried it with the code below, but it doesn't seem to work when I submitted. Could anyone please help? rep and 100np$ will be sent over to you as soon as this is working. Thanks Code: CREATE TABLE IF NOT EXISTS `quotes` ( `id` int(10) unsigned NOT NULL auto_increment, `author` varchar(255) NOT NULL default '', `quote` mediumtext NOT NULL, `live` int(1) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=100 ; -- -- Dumping data for table `quotes` -- INSERT INTO `quotes` (`id`, `author`, `quote`, `live`) VALUES (1, 'xxx', 'yyyyyy', '1'), (2, 'aaa', 'zzzz', '1'), (3, 'bbb', 'cccc', '1'), PHP Code:
__________________ Freebies and Giveaways - Printable Coupons - Hot Deals - Coupons - Deal of the Day |
| | |
| | #2 (permalink) |
| NamePros Regular Join Date: May 2008 Location: England
Posts: 771
![]() ![]() ![]() ![]() ![]() ![]() | Getting any mysql error? or blank page? whats the result when you click Sumbit?
__________________ pixelhero Web Development Studios UK |
| | |
| | #3 (permalink) |
| NamePros Member Join Date: Aug 2008 Location: poland
Posts: 94
![]() | You probably would get an error because the $quote and $author are a string in such case you sould surround them with " ' " before writing in the database. "UPDATE quotes SET quote='$quote' author='$author' WHERE id=$id";
__________________ |
| | |
| | THREAD STARTER #4 (permalink) |
| NamePros Regular Join Date: Feb 2005
Posts: 578
![]() ![]() ![]() | It doesn't give any error. It just doesn't change after I edited. demo: http://tienganh.net/ese/quote-new/admin/edit.php
__________________ Freebies and Giveaways - Printable Coupons - Hot Deals - Coupons - Deal of the Day |
| | |
| | #5 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | at a glance, change: if ($_POST["$submit"]) to: if ($_POST["submit"]) also, change: "UPDATE quotes SET quote=$quote author=$author WHERE id=$id"; to: "UPDATE quotes SET quote='".mysql_escape_real($quote)."', author='".mysql_escape_real($author)."' WHERE id=$id";
__________________ NameCooler.com
Last edited by -NC-; 11-09-2009 at 12:31 AM.
|
| | |
| | THREAD STARTER #6 (permalink) |
| NamePros Regular Join Date: Feb 2005
Posts: 578
![]() ![]() ![]() | -NC-, Thanks, but when I replace the update query, i got this error. Fatal error: Call to undefined function mysql_escape_real() in /home/******/public_html/ese/quote-new/admin/edit.php
__________________ Freebies and Giveaways - Printable Coupons - Hot Deals - Coupons - Deal of the Day |
| | |
| | #7 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | odd. well, at least the query is running now. you could try mysql_real_escape_string(), just put the query back to the way you had it or use adamos suggestion for the query code. "UPDATE quotes SET quote='$quote' author='$author' WHERE id=$id";
__________________ NameCooler.com
Last edited by -NC-; 11-09-2009 at 08:18 PM.
|
| | |
| | #8 (permalink) |
| NamePros Regular Join Date: Jul 2007 Location: UK
Posts: 394
![]() ![]() ![]() ![]() ![]() ![]() ![]() | The correct query should be: PHP Code: PHP Code:
__________________ |
| | |