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
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
Share on other sites

I dont understand why i didnt put "or die" myself. Little mistakes all the time hey :D

 

Thanks a lot for your time budimir. The error was

 

$query .= "`news_active` = '".$_POST['active'].",'";

 

Needed the , removing at the end

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.