Jump to content

[SOLVED] PHP Update


Daney11

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/89043-solved-php-update/
Share on other sites

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'

Link to comment
https://forums.phpfreaks.com/topic/89043-solved-php-update/#findComment-456030
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.