Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,676 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,195 people online right now. Registration is fast and FREE... Join Now!




Updating database records

 
Reply to this topicStart new topic

Updating database records

k0b13r
post 11 Aug, 2007 - 01:44 AM
Post #1


D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 196



Thanked 1 times

Dream Kudos: 250
My Contributions


Hi smile.gif I have this code:
CODE

$title_new = $_POST['title_new'];
$content_new = $_POST['content_new'];

if(isset($title_new) && isset($content_new))
{
    mysql_query("UPDATE note SET title = $title_new WHERE id = $edited");
    mysql_query("UPDATE note SET content = $content_new WHERE id = $edited");
    mysql_query("INSERT INTO note VALUES('', '', '', '', '$last_edit'");
}
?>


This should update note title, content and add last_edit date in database, but when I process this, nothing happens confused.gif mysql_error(); give me no info. What can be wrong? Of course $edited is set

This post has been edited by k0b13r: 11 Aug, 2007 - 01:46 AM
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 11 Aug, 2007 - 02:24 AM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 times

Dream Kudos: 250
My Contributions


Pay attention to the quotes :

CODE

    mysql_query("UPDATE note SET title = '$title_new' WHERE id = '$edited' ");
    mysql_query("UPDATE note SET content = '$content_new' WHERE id = '$edited' ");
    mysql_query("INSERT INTO note VALUES('', '', '', '', '$last_edit'");

?>


Hint : You can update the table with one query :
CODE
mysql_query("UPDATE note SET title = '$title_new', content = '$content_new' WHERE id = '$edited'");

User is offlineProfile CardPM

Go to the top of the page

k0b13r
post 11 Aug, 2007 - 02:30 AM
Post #3


D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 196



Thanked 1 times

Dream Kudos: 250
My Contributions


Thanks for hint, but this still don't work sad.gif
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 11 Aug, 2007 - 03:02 AM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 times

Dream Kudos: 250
My Contributions


QUOTE(k0b13r @ 11 Aug, 2007 - 03:30 AM) *

Thanks for hint, but this still don't work sad.gif

Do this and tell us what is printed :

CODE
$title_new = $_POST['title_new'];
$content_new = $_POST['content_new'];

$query = "UPDATE note SET title = '$title_new', content = '$content_new' WHERE id = '$edited' ";

echo $query;
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 11 Aug, 2007 - 10:26 AM
Post #5


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


Better yet, simply echo $edited to see the value. If it does not hold a valid value, the records will not be found for updating.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:27AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month