gevo12321 Posted June 24, 2007 Share Posted June 24, 2007 ok Im very new tp php and i have a code that updates my database but i can find anything wrong with it. can someone plz tell me why it isnt working? here is my code: <?php require_once('../connect.php'); $articleID=$_GET['newsnumber']; $query = mysql_query("SELECT * FROM news WHERE newsnumber = '".$articleID."'") or die(mysql_error()); $row=mysql_fetch_object($query); $date1=$row->date; $titlea=$row->title; $newsa=$row->news; echo " <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> <html> <head> <title>Edit News</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> </head> <body> <form action=\"esubmiteditnews.php\" method=\"post\"> <table width=\"100%\" border=\"0\"> <tr> <td width=\"10%\">Title (Max 300):</td> <td><input type=\"text\" name=\"title\" size=\"50\" value=\""; echo $titlea; echo" \"/></td> </tr> <tr> <td width=\"10%\">Date (yyyy-mm-dd):</td> <td><input type=\"text\" name=\"date1\" value=\""; echo $date1; echo " \"/></td> </tr> <tr> <td width=\"10%\" valign=\"top\">News:</td> <td><textarea cols=\"100\" rows=\"25\" name=\"news\"/>"; echo $newsa; echo " </textarea></td> </tr> <tr> <td width=\"10%\">News Number:</td> <td><input type=\"text\" name=\"newsnumber\" size=\"10\" disabled value=\" "; echo $articleID; echo " \"/> </table> <input type=\"submit\" value=\"Edit\"> </form> </body> </html> "; mysql_close($link) ?> the above code is the form <?php require_once('../connect.php'); $newsnumber = $_POST[newsnumber]; $date1 = $_POST[date1]; $title = $_POST[title]; $news = $_POST[news]; mysql_query("UPDATE news SET date = '$date1', title = '$title', news = '$news' WHERE newsnumber = '$newsnumber'") or die(mysql_error()); echo "News Archive has been edited"; mysql_close($link) ?> the above code is what the "edit" button should do plz someone help me i have no idea what im doing wrong ur help is greatly appreciated thank you Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 24, 2007 Share Posted June 24, 2007 try this stuff mysql_query("UPDATE news SET date = '".$date1."', title = '".$title."', news = '".$news."' WHERE newsnumber = '".$newsnumber."'") \\hope that helps Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 24, 2007 Author Share Posted June 24, 2007 nop still doesnt work Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 ok pls give me the error message Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 thats the thing it doesn't give an error message but just gives the echo and i know that it doesn't work because i check my database and the info hasn't been changed Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 if you declare the field in the db as date or time thats not gonna work your date has a prob try this date = $date1 remove the quote Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 still no luck Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 tips to debug!! 1. echo the query for update then check the data 2. if you use the phpmyadmin update certain file there and get the query result then compare the no step or if you cant still fixed show me the echoed first step Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 ok so when i echo the query i used this code: <?php require_once('../connect.php'); $newsnumber = $_POST[newsnumber]; $date1 = $_POST[date1]; $title = $_POST[title]; $news = $_POST[news]; $query=mysql_query("UPDATE news SET date = $date1, title = '".$title."', news = '".$news."' WHERE newsnumber = '".$newsnumber."'") or die(mysql_error()); echo $query; echo "<br>News Archive has been edited"; mysql_close($link) ?> and the result tat it gives me is: 1 News Archive has been edited Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 no do this echo UPDATE news SET date = $date1, title = '".$title."', news = '".$news."' WHERE newsnumber = '".$newsnumber."'"; then if u r using phpmyadmin edit some file there and compare the output you have from above and if still you cant have it fixed show me the echoed result Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 25, 2007 Share Posted June 25, 2007 change your code to this... <?php require_once('../connect.php'); $newsnumber = $_POST[newsnumber]; $date1 = $_POST[date1]; $title = $_POST[title]; $news = $_POST[news]; $query="UPDATE `news` SET `date` = '". $date1 . "', `title` = '".$title."', `news` = '".$news."' WHERE newsnumber = '" . `$newsnumber` . "'"; echo $query; $query = mysql_query($query) or die(mysql_error()); if ( mysql_affected_rows() > 0 ) { echo "<br>News Archive has been edited"; } mysql_close($link) ?> run teh page - check you db table if teh update still do not work then copy the query string (that is now eching out) and run teh direct in phpmyadmin (or what ever app you sue to administer your database) and see what it throws out. Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 when i do what tango84 said the update file doesn't show anything for the newsnumber so thats the problem right now il try what toonmariner said Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 but that was im trying to say Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 when i use toonmariner's code i get the same thing as i did with tango84 so i guess the problem is that it is blank where its supposed to put the newsnumber so maybe its not linked correctly or something can someone plz check to see that i linked it properly? thank you very much Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 ok so the reason i guess that this doesn't work is because i used $_get to get the newsnumber for the form in the first place and than when i try to use the newsnumber form the form and it becomes blank does anyone have an idea on how i could make this work? Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 bump Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 give as the result of what you echo remember the query and i check it out for you "UPDATE `news` SET `date` = '". $date1 . "', `title` = '".$title."', `news` = '".$news."' WHERE newsnumber = '" . `$newsnumber` . "'"; echo that and ill chek it out Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 the result of that echo is: UPDATE `news` SET `date` = '2007-06-22', `title` = 'Created a News Archive for the Website', `news` = 'All the news about this website is stored in the archive from the start of the project to this point. the Archive can be accessed by clicking the Archive button on the right. ' WHERE newsnumber = '' Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 bump Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 date` = '2007-06-22', ==== this maybe the prob i gues it should be date` = 2007-06-22, if you declare it to your db as date newsnumber = and where do you expect to have that value for where $newsnumber = $_POST[newsnumber]; // check the form where you get that post and practice doing this for string $_POST['newsnumber'] Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted June 25, 2007 Author Share Posted June 25, 2007 omg thank you sooooooooooooooooooooooooooooooooooooooooooooooooooooooo sooooooooooooooooooooooooooooooooooooooooooooooo soooooooooooooooooooooooooooooooooooooo much u rock oh wow im soooooooooooooooooo happy lol thank you thank you it works!!!! Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 tel me whats wrong with your code im wondering which one i gave you makes your prob solve Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.