Hello,

I am trying to fit a news script into my page, but cannot get the correct one. Since I am new at PHP, I looked around for open source scripts, but all of them are too complicated or don't fit my needs.

They don't fit my needs. What I am looking for is:

for the front office:
Show all news titles in bold
If a title is clicked, the news is shown below the title, with a "back" link at the end or the news is shown in a pop up window with just that article.

for the back office:
type a title
type the story
possibility to add images to the story (images are uploaded by the script, so dont have to be on the server)

the script "Cutenews" comes close, but there is a short story there that has to be gone from the script, I dont want the possibility to make comments and I just want the title shown, no date added etc.

Can anyone help me?

    It seems that you want a pretty specific script, I doubt that you will find it already done. Your best bet (and a good way to learn how to code PHP) is to do it yourself. Because this is, as you say, not that complicated it is a golden opportunity to learn PHP.

      Yep as Piranha said, best bet as it isn't too hard a project, is to code it yourself, that way you learn and can re-use that knowledge in the future.

      A few points you may wish to consider though (general pointers):

      You will need a database to store the news stories.
      You will need three webpages. One for people to write the news on, one for the system to process the news and store it, and lastly the third page where people view the news.

      I suggest, if you havent chosen to do so already, that you consider using MySQL to store the data, because it is very easy to use, so beginners find it easier to learn.

      The page where people will submit the data will be written in html, using a form to submit the data.

      The process page will obviously be php, will validate the data and store it in the database.

      Lastly, the viewing page, will be a mix of html and php, and might benefit from some Javascript to dynamically display news items on the webpage.

      Hope this helps cobain.

        (Untested) First lets create a Mysql database,table. If you have php enabled and a mysql database capability the below script can be ran in phpmyadmin or see the link below to create a database.

        upload this file and call the page

        createdatabasenews.php

        <?php
                //Create database news
                $host = "yourhost";
                $username = "yourusername";
                $password = "yourpassword";
        
        
        $link = mysql_connect($host,$username,$password);
        if (!$link) {
            die('Could not connect: ' . mysql_error());
        }
        
        $sql = 'CREATE DATABASE news';
        if (mysql_query($sql, $link)) {
            echo "Database news created successfully\n";
        } else {
            echo 'Error creating database: ' . mysql_error() . "\n";
        }
        ?>
        

        Next you need tables within that database, upload this file and call the page,

        createnewsstory.php

        <?PHP
                 //Create table news story
                $host = "yourhost";
                $username = "yourusername";
                $password = "yourpassword";
                $database = "news";
        mysql_connect($host,$username,$password);
        mysql_select_db($database) or die( "Unable to select database");
        
        $query="CREATE TABLE news story (id int(6) NOT NULL auto_increment,headline VARCHAR(60) NOT NULL,story text NOT NULL,photo_id VARCHAR(60) NOT NULL,date date NOT NULL default '0000-00-00',PRIMARY KEY (id),UNIQUE id (id)";
        mysql_query($query);
        if (mysql_query($query) {
            echo "Table news story created successfully\n";
        } else {
            echo 'Error creating table news: ' . mysql_error() . "\n";
        }
        ?>
        

        We now have the structure of our database to which we can add to if we wish.

        For the photo ID you will need to create a folder on your server named uploaded_files or something similar, you will see the upload link later.

        Now lets think of a form with some basic php code to insert that data into the database.

        newsupload.php

        <style type="text/css">
        .list_left{
        background-color:#4486BB;
        font-weight:bold;
        font-size:11px;
        font-family:Verdana, Arial, Helvetica, sans-serif;
        }
        .list_right{
        background-color:#C6ECFF;
        color:#333333;
        font-family:Verdana, Arial, Helvetica, sans-serif;
        font-size:11px;
        }
        
        .NewClass { }
        .NewClass { }
        
        </style>
        
        </head>
        
        <?PHP
        if($_POST['submit']=="send") {
           $errcount = 0;
           //can set errors with css
           $error1="<font face='Verdana' size='1'><span style='color:red'>";
           $error2="<font face='Verdana' size='1'><span style='color:red'>";
           $error3="<font face='Verdana' size='1'><span style='color:red'>";
           $error4="<font face='Verdana' size='1'><span style='color:red'>";
           $error5="<font face='Verdana' size='1'><span style='color:red'>";
           //check if someone has filled out a form
        
           //validate headline
          if(preg_match('/^[a-zA-Z0-9_ -]{2,}$/i', $_POST['headline'])){
            $headline = $_POST['headline'];     
        }
            else {
            $error1 .= "&nbsp;Headline Required!";
            $errcount++;  
             }   
        
           if(empty($_POST['story'])){
            $error2 .= "&nbsp; News Story Required!";        
            $errcount++;          
        }
            else {
            $story = $_POST['story'];
        
             }
        
          $now =time();
        
        // set a max file size for the html upload form
        $max_file_size = 1048576; // size in bytes 
        $uploaddir = "uploaded_files/"; 
        $valid_types = array("image/jpeg","image/jpg","image/gif","image/png");
        $filetype = $_FILES['File']['type'];
        $photo_id = $now.'-'.$_FILES['File']['name'];
        $tmpname = $_FILES['File']['tmp_name'];
        $size = $_FILES['File']['size']; 
        
        
        
        
        if (is_uploaded_file($_FILES['File']['tmp_name']))
            {
            //Get the Size of the File
            $size = $_FILES['File']['size'];
            //Make sure that $size is less than $size_byte
            if ($size > $max_file_size)
            {
                $error3 .= "File Too Large!.";
                $errcount++;
                }
        
                 //check file type
              if (in_array($filetype,$valid_types)) {
        
              } 
              else
              {
               $error4 .= "&nbsp;&nbsp;Valid Image Types Only!";   
            @unlink($_FILES['File']['tmp_name']);     
            $errcount++;
               }
        
                 if ($errcount !=0) {
             //displays errors in form boxes
             }
             else {
        
        
         move_uploaded_file($tmpname, $uploaddir . $photo_id);
        
        
            // databse connection info
            $host = "yourhost";
            $username = "yourusername";
            $password = "yourpassword";
            $database = "News";
        
        
            $story = htmlspecialchars($story);
            $story = nl2br($story);
            $story = trim($_POST['story']);
            $story = wordwrap($story, 65);
        
        
            //make the connection and show errors if you cant connect
            $conn = mysql_connect($host, $username, $password) or die(mysql_error());
            mysql_select_db($database,$conn) or die(mysql_error());
        
             //Insert into our table or everyrthing from table
            $query = "INSERT INTO news story VALUES('','$headline','$story','$photo_id',NOW())";
             mysql_query($query);
        
            $headline = mysql_real_escape_string($_POST['headline']);
            $story = mysql_real_escape_string($_POST['story']);
            $photo_id = mysql_real_escape_string($_POST['photo_id']);
        
        
        
            //redirect if the code runs OK to newsheadlines.php
            echo '<meta http-equiv="refresh" content="0;url=http://www.oursite.co.uk/newsheadlines.php">';
            }
        }
        }
        ?>
        
        
        <form id="Upload" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <table cellpadding="3" cellspacing="1">
        
        <tr>
          <td class="list_left">Headline:</td>
          <td class="list_right"><input type="text" value="<? echo $headline; ?>" id="headline" name="headline" style="width:200px;" ><?php echo $error1; ?></td>
          </tr>      
        
        
        <tr>
          <td class="list_left">Story:*<br></td>
          <td class="list_right"><textarea name="story" id="story" rows="5" cols="45"><?php echo $story; ?></textarea></td>
        </tr>
        
        <tr>
          <td class="list_left">Photo Upload:*</td>
        <td class="list_right"><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
        <input type="file" name="File" size="20" value="<?php echo $photo_id; ?>"><?php echo $error3; ?><?php echo $error4; ?></td>
        </tr>
        
        
         <tr>
          <td colspan="2" class="list_left" align="center"><input  id="submit" name="submit" type="submit" value="send" />&nbsp;<input type='button' value='Retry'       onClick='history.go(-1)'>&nbsp;<input type="button" value="Reset Location" onclick="resetListGroup('chainedmenu')"></td>
        </tr>
        
        
        <tr>
        <td colspan="2" class="list_left" height="25" align="center"><?php echo $error2; ?>&nbsp;<?php echo $error3; ?>&nbsp;<?php echo $error4; ?></td>
        </tr>   
        </table>
           </form>
        
        
        </body>
        </html>

        newsheadlines.php

        <!--CSS HERE ETC!>
        <?PHP session_start();                      
        
            // databse connection info
            $host = "yourhost";
            $username = "yourusername";
            $password = "yourpassword";
            $database = "news";       
        
        
            //make the connection and show errors if you cant connect
            $conn = mysql_connect($host, $username, $password) or die(mysql_error());
            mysql_select_db($database,$conn) or die(mysql_error());
        
             //Insert into our table or everyrthing from table
            $query = "SELECT * FROM news story ORDER by date DESC";       
             mysql_query($query);
        
        
            $result=mysql_query($query);
            $num=mysql_num_rows($result);
            if ($num==0) {
           $empty = "No News Storys Today";
           }
           else {
          $num_rows = mysql_num_rows($result);
           }
        
         $i=0;
        
          //create a while loop of all records on from our result
           while ($row = mysql_fetch_array($result)) {
        
        $id = $row["id"];
        $headline = $row["headline"];
        $photo_id = $row["photo_id"];
        $date = $row["date"];
        $story = nl2br($story);
        
        //if no image is available use a default image  
        if(empty($photo_id)) { $photo_id = 'default_image.JPG'; } echo "<table cellpadding='0' cellspacing='0' border='0' align='cente' width='800px'>"; echo "<tr><td valign='top' align='center' width='800px'>"; echo "<table cellpadding='0' width='800px' cellspacing='3'>"; echo "<tr><td align='left'>"; echo "<table border='0' cellpadding='0' cellspacing='0' width='800px' class='title3'>"; echo "<tr><td width='81%' style='line-height:19px;'>&nbsp;$headline</td></tr>"; echo "<td width='19%'>$date</td>"; echo "</tr>"; echo "</table>"; echo "<table border='0' cellpadding='0' cellspacing='0'>"; echo "<tr>"; echo "<td valign='top'><a href ='./uploaded_files/$photo_id' /'><img alt='$headline on $date' title='Click and View Image to see full size' border='0' style='border-color:#999999' src='./uploaded_files/$photo_id' /></a></td>"; echo "</table><br>"; echo "<table border='0' cellpadding='2' cellspacing='0' width='600px' class='box'>"; echo "<td align='center' class='body' cellpadding='2'><text name='story' id='story' rows='15' cols='45'>$story</td>"; echo "</tr>"; echo "</table>"; echo "</table>"; echo "</td></tr>"; echo "</table>"; ?> </form> </tr> <? $i++; } ?> <?PHP echo $empty; ?>

        Hope this helps!

          Cont from prev Post due to Size limits,

          You can use phpmyadmin to work your mysql database,

          CREATE DATABASE `news` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
          USE News;
          
          
          CREATE TABLE `news story` (
            `id` int(6) NOT NULL auto_increment,
            `headline` varchar(60) NOT NULL default '',
            `story` text NOT NULL default '',
            `photo_id` varchar(60) NOT NULL default '',
            `date` date NOT NULL default '0000-00-00',
            PRIMARY KEY  (`id`)
            UNIQUE KEY `id` (`id`),
          ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
          

          Some useful links

          http://uk3.php.net/manual/en/
          http://uk3.php.net/manual/en/function.mysql-create-db.php
          http://uk3.php.net/manual/en/function.mysql-connect.php
          http://uk3.php.net/manual/en/function.mysql-create-db.php
          http://uk3.php.net/manual/en/function.mysql-real-escape-string.php
          http://uk3.php.net/manual/en/function.session-start.php
          http://dev.mysql.com/doc/refman/5.0/en/
          http://dev.mysql.com/doc/refman/5.0/en/database-use.html
          http://www.w3schools.com/PHP/DEfaULT.asP
          http://pear.php.net/

            For the popup window use a javascript function

            <script language="javascript" type="text/javascript"> 
            <!--
            function myPopup1() {
            window.open( "newsheadlines.php", "myWindow", "toolbar=1, status = 1, height = 300, width = 300, resizable = 1, scrollbars = 1")
            }
            //-->
            
            </script>
            
            Then call using <a href='#' onClick="myPopup1()">News</a>. You will obviously have to have the data within that page which could be the aforementioned newsheadlines.php or something similar.
              Write a Reply...