Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Location
    Brisbane, Australia
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with MySQL and PHP News System

    Hello Everyone,

    As you can see, I am after a bit of help with a new News System that uses MySQL Queries and of course a Rich Text Editor.

    Now, when I try to use it, I continually get parse errors, over and over again, but I think it is the RTE contributing to them.

    The news manager admin code is:

    Code:
    <? 
    ob_start(); 
    include("config.php"); 
    if ($logged[username] && $logged['level'] == "3" || $logged['level'] == "5") { 
    
    switch($_GET['view']) { 
    case "addnews" : 
    include("config.php"); 
    if(isset($_POST['add_news'])) { 
    
    $title=$_POST['title'];
    $desc=$_POST['desc']; 
    $author=$logged['username']; 
    $postdate=date("g:i A, l F j"); 
    $content=$_POST['content']; 
    
    $sql = "INSERT INTO news (title, desc, author, postdate, content) VALUES ('$title', '$desc', '$author', '$postdate', '$content')"; 
    $addnews = mysql_query($sql) 
    or die(mysql_error()); 
    header("Location:news_admin.php"); 
    } 
    else 
    { 
    echo ("
    <html>
    <head>
    	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    	<script language="JavaScript" type="text/javascript" src="html2xhtml.js"></script>
    	<script language="JavaScript" type="text/javascript" src="richtext_compressed.js"></script>
    </head>
    <body>
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    <form method=\"post\" name=\"addnews\"> 
    <tr> 
        <td height=\"20\"><font face=\"tahoma\" size=\"2\">Article Title:<br></td> 
    </tr> 
    <tr> 
        <td> <input class=\"content_box\" Type=\"text\" name=\"title\" value=\"Article's Title\"></td> 
    </tr> 
    <tr> 
        <td height=\"20\"><font face=\"tahoma\" size=\"2\"><br>Article Description:<br></td> 
    </tr> 
    <tr> 
        <td> <input class=\"content_box\" Type=\"text\" name=\"desc\" value=\"Small Description\"></td> 
    </tr>
    <tr>
    <script language="JavaScript" type="text/javascript">
    <!--
    function submitForm() {
    	//make sure hidden and iframe values are in sync for all rtes before submitting form
    	updateRTEs();
    	
    	return true;
    }
    
    //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML, encHTML)
    initRTE("./images/", "./", "", true);
    //-->
    </script>
    <noscript><p><b>Javascript must be enabled to use this form.</b></p></noscript>
    
    <script language="JavaScript" type="text/javascript">
    <!--
    //build new richTextEditor
    var rte1 = new richTextEditor('rte1');
    <?php
    //format content for preloading
    if (!(isset($_POST["rte1"]))) {
    	$content = "here's the " . chr(13) . "\"preloaded <b>content</b>\"";
    	$content = rteSafe($content);
    } else {
    	//retrieve posted value
    	$content = rteSafe($_POST["rte1"]);
    }
    ?>
    rte1.html = '<?=$content;?>';
    //rte1.toggleSrc = false;
    rte1.build();
    //-->
    </script>
    </tr>
    </form>
    </font>
    </center>
    </body>
    </html>
    "); 
    } 
    break; 
    case "editnews" : 
    include("config.php"); 
    
    $id = $_GET['id']; 
    if(!$_GET['id']) 
    { 
    header("Location:news_admin.php"); 
    } 
    $select = mysql_query("select * from news where id=$id"); 
    if (mysql_num_rows($select) == "0") { 
    echo '
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    Unable to find the news article in the database!
    </font>
    </center>
    </body>'; 
    exit(); 
    } 
    if(isset($_POST['edit_news'])) { 
    
    $title=$_POST['title']; 
    $content=$_POST['content']; 
    
    $sql = mysql_query("update news set title = '$title', content = '$content' where id = '$id'"); 
    echo ("
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    Your article has been updated!
    </font>
    </center>
    </body>");  
    exit; 
    } 
    else 
    { 
    $get = mysql_query("select * from news where id=$id"); 
    $get = mysql_fetch_array($get); 
    echo (" 
    
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    <form method=\"post\" name=\"editnews\"> 
    <tr> 
        <td height=\"20\"><font face=\"tahoma\" size=\"2\">Article Title:<br></td> 
    </tr> 
    <tr> 
        <td> <input Type=\"text\" name=\"title\" value=\"$get[title]\"></td> 
    </tr> 
    <tr> 
        <td height=\"20\"><font face=\"tahoma\" size=\"2\"><br>News Article:</td> 
    </tr> 
    <tr> 
        <td><br><textarea rows=\"15\" cols=\"50\" name=\"content\">$get[content]</textarea><br> <input type=\"submit\" name=\"edit_news\" value=\"Submit\"></td> 
    </tr> 
    </form>
    </font>
    </center>
    </body>"); 
    } 
    break; 
    case "deletenews" : 
    include("config.php"); 
    
    $id = $_GET['id']; 
    if(!$_GET['id']) 
    { 
    header("Location:news_admin.php"); 
    } 
    $select = mysql_query("select * from news where id=$id"); 
    if (mysql_num_rows($select) == "0") { 
    echo '
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    Unable to find the news article in the database!
    </font>
    </center>
    </body>'; 
    exit(); 
    } 
    $delete = mysql_query("DELETE FROM news WHERE id = '$id'") or die(mysql_error()); 
    $delete2 = mysql_query("DELETE FROM news_comments WHERE nid = '$id'") or die(mysql_error()); 
    echo("
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    Your article has been deleted!
    </font>
    </center>
    </body>"); 
    break; 
    case "deletecommet" : 
    include("config.php"); 
    
    $id = $_GET['id']; 
    if(!$_GET['id']) 
    { 
    header("Location:news_admin.php"); 
    } 
    $select = mysql_query("select * from news_comments where id=$id"); 
    if (mysql_num_rows($select) == "0") { 
    echo '
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    Unable to find the comment in the database!
    </font>
    </center>
    </body>'; 
    exit(); 
    } 
    $delete = mysql_query("DELETE FROM `news_comments` WHERE id = '$id'") or die(mysql_error()); 
    echo("
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    The comment has been deleted!
    </font>
    </center>
    </body>"); 
    break; 
    case "editcomment" : 
    include("config.php"); 
    
    $id = $_GET['id']; 
    if(!$_GET['id']) 
    { 
    header("Location:news_admin.php"); 
    } 
    $select = mysql_query("select * from news_comments where id=$id"); 
    if (mysql_num_rows($select) == "0") { 
    echo '
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    Unable to find the comment in the database!
    </font>
    </center>
    </body>'; 
    exit(); 
    } 
    if(isset($_POST['edit_comment'])) { 
    
    $comment=$_POST['comment']; 
    
    $sql = mysql_query("update news_comments set content = '$content' where id = '$id'"); 
    echo ("
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    The comment has been updated!
    </font>
    </center>
    </body>");  
    exit; 
    } 
    else 
    { 
    $get = mysql_query("select * from news_comments where id=$id"); 
    $get = mysql_fetch_array($get); 
    echo (" 
    
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    <form method=\"post\" name=\"editcomment\"> 
    <tr> 
        <td height=\"20\"><font face=\"tahoma\" size=\"2\">Comment:</td> 
    </tr> 
    <tr> 
        <td><br><textarea rows=\"15\" cols=\"50\" name=\"comment\">$get[content]</textarea><br> <input type=\"submit\" name=\"edit_comment\" value=\"Submit\"></td> 
    </tr> 
    </form>
    </font>
    </center>
    </body>"); 
    } 
    break; 
    default: 
    echo "
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    Welcome to the NewsManager!<br><br>
    [<a href=\"news_admin.php?view=addnews\">Add News</a>]<br><br></font>
    </center>
    </body>"; 
    
    $q = mysql_query("SELECT * FROM news ORDER BY id DESC"); 
    if (mysql_num_rows($q) == "0") { 
        echo ("
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    There is no news in the database!<br><br>[<a href=\"news_admin.php?view=addnews\">Add News</a>]</font>
    </center>
    </body>"); 
    } 
    while($r=mysql_fetch_array($q)){ 
    
        $id = $r["id"]; 
        $title = $r["title"]; 
        $author = $r["author"]; 
        $postdate = $r["postdate"]; 
    
        echo ("
    <center>
    <font face=\"tahoma\" size=\"2\" color=\"#000000\">
    <tr> 
                    <td><a href=\"news_comments.php?view=news&id=$id\">$title</a> Posted by $author [<a href=\"news_admin.php?view=editnews&id=$id\">Edit</a>] [<a href=\"news_admin.php?view=deletenews&id=$id\">Delete</a>]<br></td> 
               </tr>
    </font>
    </center>
    </body>"); 
    } 
    break; 
    } 
    }else 
    { 
    //the user's level is not 5!  They cannot view this page 
    echo("<center>
    <font face=\"tahoma\" size=\"2\">
    Sorry, but you are not allowed to view this page!
    </font>
    </center>
    </body>"); 
    } 
    
    ?>
    Some recoding or help would be very helpful. Thanks!

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    What is the actual error message and what line is it referring to in the code?

    It is beyond the scope of a Forum to find what is wrong with several hundred lines of code unless you provide as much information as possible as to where to look in it for the problem. We only see what you state in your post. No one is going to look at this unless you provide enough information about what is going on with it.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •