Daney11 Posted February 2, 2008 Share Posted February 2, 2008 Hey guys, Im using this bit of code... if (isset($_POST['submitted'])) { $errors = array(); if (eregi ('^[[:alpha:]\.\'\-]{2,35}$', stripslashes(trim($_POST['news_title'])))) { $news_title = escape_data($_POST['news_title']); } else { $news_title = FALSE; $errors[] = 'Please Enter A News Title'; } if (strlen($_POST['news_body']) > 3 && (strlen($_POST['news_body']) < 10000)) { // Strip News Body For Bad Data $news_body = escape_data($_POST['news_body']); } else { $news_body = FALSE; $errors[] = 'News Needs To Be More Than 3 Characters and Less Than 10000'; } if (eregi ('^[[:alpha:]\.\'\-]{6,8}$', stripslashes(trim($_POST['news_active'])))) { $news_active = escape_data($_POST['news_active']); } else { $news_active = FALSE; $errors[] = 'Please Enter Yes or No For News Active'; } if (empty($errors)) { $query = "UPDATE `news` SET"; $query .= "`news_id` = '".$_GET['news_id']."',"; $query .= "`news_teamid` = '$team_url',"; $query .= "`news_title` = '".$_POST['news_title']."',"; $query .= "`news_image` = '".$_POST['news_image']."',"; $query .= "`news_body` = '".$_POST['news_body']."',"; $query .= "`news_author` = '".$_SESSION[member_username]."',"; $query .= "`news_date` = '$date',"; $query .= "`news_active` = '".$_POST['active']."',"; $query .= "WHERE `news_id` = '".$_GET['news_id']."'"; $result = mysql_query($query); if ($result) { } else { $errors[] = 'It Went Wrong'; echo $query; } } } else { $errors = NULL; } if ($result) { echo " <table width=\"508\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" class=\"abouttable\"> <tr> <td class=\"text\" height=\"19\"> <table width=\"500\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\"> <tr> <td width=\"500\" height=\"21\"><b> Your news post was successful.</b> </td> </tr> </table> </td> </tr> </table> <table width=\"508\" height=\"1\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\"> <tr> <td><img src=\"images/spacer.gif\" height=\"1\"></td> </tr> </table>"; } if (!empty($errors)) { foreach ($errors as $msg) { echo " <table width=\"508\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" class=\"abouttable\"> <tr> <td class=\"text\" height=\"19\"> $msg<br />\n </td> </tr> </table> <table width=\"508\" height=\"1\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\"> <tr> <td><img src=\"images/spacer.gif\" height=\"1\"></td> </tr> </table> "; } echo " <table width=\"508\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" class=\"abouttable\"> <tr> <td class=\"text\" height=\"19\"> Make Sure All Information Is Correct</td> </tr> </table> <table width=\"508\" height=\"1\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\"> <tr> <td><img src=\"images/spacer.gif\" height=\"1\"></td> </tr> </table>"; } Now im using the same bit of code to add news... and it adds the news perfect... however when i change it to UPDATE the news, it always gives me the error message "It Went Wrong".. I cannot figure out why. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/89043-solved-php-update/ Share on other sites More sharing options...
budimir Posted February 2, 2008 Share Posted February 2, 2008 Try to use: echo "$variable"; To see if you are passing any data to database. But it seems to me, that you are sending an empty query. Try to do it in one query, or use different names for varibales. Hope, this helps a little. Quote Link to comment https://forums.phpfreaks.com/topic/89043-solved-php-update/#findComment-456026 Share on other sites More sharing options...
Daney11 Posted February 2, 2008 Author Share Posted February 2, 2008 Im using echo $query. And it is working, all the values are fine. UPDATE `news` SET`news_id` = '9',`news_teamid` = '1',`news_title` = 'Hi',`news_image` = '',`news_body` = 'This is a long news post. Hahahaha [b]bold[/b] lol. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',`news_author` = 'Vixen',`news_date` = '2008/02/02 10:02:39',`news_active` = 'Yes',WHERE `news_id` = '9' Quote Link to comment https://forums.phpfreaks.com/topic/89043-solved-php-update/#findComment-456030 Share on other sites More sharing options...
budimir Posted February 2, 2008 Share Posted February 2, 2008 OK, so it seems that you need to dig deeper. Try using error reporting like: $result = mysql_query($sql) or die(mysql_error()); And see the error message you get! Quote Link to comment https://forums.phpfreaks.com/topic/89043-solved-php-update/#findComment-456035 Share on other sites More sharing options...
Daney11 Posted February 2, 2008 Author Share Posted February 2, 2008 I dont understand why i didnt put "or die" myself. Little mistakes all the time hey Thanks a lot for your time budimir. The error was $query .= "`news_active` = '".$_POST['active'].",'"; Needed the , removing at the end Thanks Quote Link to comment https://forums.phpfreaks.com/topic/89043-solved-php-update/#findComment-456038 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.