Jump to content

editing data


Mr Chris

Recommended Posts

Hi Guys,

I have this script to edit data in the DB:

[code]<?php

//Connect to DB
include("*************");

//Gets stories from the database
if(isset($_GET['story_id']))
{
    $result = mysql_query("Select * From cms_stories where story_id=".$_GET['story_id'],$link);
    $row = mysql_fetch_array($result);
    $section = $row['section'];
    $added_by = $row['added_by'];
    $headline = $row['headline'];
    $byline_name = $row['byline_name'];
    $appeared = $row['appeared'];
    $published = $row['published'];
    $opening = $row['opening'];
    $body_text = $row['body_text'];
    $picture = $row['picture'];
    $pic_caption = $row['pic_caption'];
    $pic_ref = $row['pic_ref'];
    $notes = $row['notes'];
}

//Submit the edited data to the database
if(isset($_POST['Submit']))
{

    $section = $_POST['section'];
    $added_by = $_POST['added_by'];
    $headline = $_POST['headline'];
    $byline_name = $_POST['byline_name'];
    $appeared = $_POST['appeared'];
    $published = $_POST['published'];
    $opening = $_POST['opening'];
    $body_text = $_POST['body_text'];
    $pic_caption = $_POST['pic_caption'];
    $pic_ref = $_POST['pic_ref'];
    $notes = $_POST['notes'];
        $result = mysql_query("cms_stories set section='$section', added_by='$added_by', headline='$headline', byline_name='$byline_name', appeared='$appeared', published='$published',opening='$opening', body_text='$body_text', pic_caption='$pic_caption', pic_ref='$pic_ref', notes='$notes' where story_id=$story_id");
        $msg = "Record is updated";
}

?>
[/code]

…But I want to add these conditions if submit is hit:

[code]
       if (empty($section)){
        $error = "** You forgot to enter the section for the story! **";
    }  else if (empty($added_by)){
        $error = "** Error: You forgot to who added the story! **";
    }  else if (empty($headline)){
        $error = "** Error: You forgot to enter a headline for the story! **";
    }  else if (empty($byline_name)){
        $error = "** Error: You forgot to enter a byline name for the story! **";
    }  else if (empty($published)){
        $error = "** Error: You forgot to the date you wish to publish the story! **";
    }  else if (empty($opening)){
        $error = "** Error: You forgot to the Opening Paragraph for the Indexes! **";
    }  else if (empty($body_text)){
        $error = "** Error: You forgot to enter any body text! *";
[/code]

…But can't work out how do I do this? Can anyone advise?

Thanks

Chris
Link to comment
Share on other sites

[code]if(isset($_POST['Submit']))
{

    $section = $_POST['section'];
    $added_by = $_POST['added_by'];
    $headline = $_POST['headline'];
    $byline_name = $_POST['byline_name'];
    $appeared = $_POST['appeared'];
    $published = $_POST['published'];
    $opening = $_POST['opening'];
    $body_text = $_POST['body_text'];
    $pic_caption = $_POST['pic_caption'];
    $pic_ref = $_POST['pic_ref'];
    $notes = $_POST['notes'];

$error="";
       if (empty($section)){
        $error = "** You forgot to enter the section for the story! **<br>";
    }  else if (empty($added_by)){
        $error = "** Error: You forgot to who added the story! **<br>";
    }  else if (empty($headline)){
        $error = "** Error: You forgot to enter a headline for the story! **<br>";
    }  else if (empty($byline_name)){
        $error = "** Error: You forgot to enter a byline name for the story! **<br>";
    }  else if (empty($published)){
        $error = "** Error: You forgot to the date you wish to publish the story! **<br>";
    }  else if (empty($opening)){
        $error = "** Error: You forgot to the Opening Paragraph for the Indexes! **<br>";
    }  else if (empty($body_text)){
        $error = "** Error: You forgot to enter any body text! **<br>";};

if(strlen($error)>0){die($error);};

        $result = mysql_query("cms_stories set section='$section', added_by='$added_by', headline='$headline', byline_name='$byline_name', appeared='$appeared', published='$published',opening='$opening', body_text='$body_text', pic_caption='$pic_caption', pic_ref='$pic_ref', notes='$notes' where story_id=$story_id");
        $msg = "Record is updated";[/code]

If there's an error, stop and echo it, else continue to update [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Orio.
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.