treehouse : what would you like to learn today?
Web Design Web Development iOS Development

CMS + comments

  • Okay, so, this isnt exactly a comment issue, but what I'm trying to do is the same as doing somments..

    I needed to make 2 sections on my site for my news/updates and comments, so I found the post
    PHP for Beginners: Building Your First Simple CMS
    and decided to give it a shot.

    I got my comment section down no problem, but my updates wont seem to shoot.
    I've changed the names of the variables and matched them up (or so I thought,) but it's still not doing the updates..

    I went into the database, and it's not even making the table in the database, so I even tried making the table by hand, and that still didn't work, if someone could help, I would be grateful..

    btw, the link to my site is.. Makeshift Designs

    <?php
    date_default_timezone_set('MST');
    class upDate{
    var $host;
    var $username;
    var $password;
    var $table;

    public function display_update(){
    $q = \"SELECT * FROM upDate ORDER BY created DESC LIMIT 10\";
    $r = mysql_query($q);
    if($r !== false && mysql_num_rows($r) > 0){
    while($a = mysql_fetch_assoc($r)){
    $update = stripslashes($a['update']);
    $time = stripslashes($a['time']);

    $update_display .= <<<update_display
    <small>$time</small><div class=\"newup\">$update</div><br class=\"smallbr\" />\n
    update_display;
    }
    }else{
    $update_display = <<<update_display
    Coming Soon
    update_display;
    }
    return $update_display;
    }

    public function leave_update(){

    $time = date(\"M jS, Y - [g:i a]\");
    return <<<ADMIN_FORM
    <span class=\"title\">Update</span>
    <div class=\"content\">
    <form action=\"{$_SERVER['REQUEST_URI']}\" method=\"post\">
    <table align=\"center\">
    <tr valign=\"top\">
    <td align=\"right\">Time:</td>
    <td align=\"left\">$time<input type=\"hidden\" name=\"time\" id=\"time\" value=\"$time\" /></td>
    </tr>
    <tr valign=\"top\">
    <td align=\"right\">Update:</td>
    <td align=\"left\"><textarea rows=\"5\" name=\"update\" id=\"update\" cols=\"30\"></textarea><br />
    <input type=\"submit\" value=\"Submit\" /></td>
    </tr>
    </table>
    </form>
    ADMIN_FORM;
    }

    public function write($p){
    if ($_POST['update'])
    $update = mysql_real_escape_string($_POST['update']);
    if ($_POST['time'])
    $time = mysql_real_escape_string($_POST['time']);
    if ($_POST){
    $created = time();
    $ip = $_SERVER['REMOTE_ADDR'];
    $sqll = \"INSERT INTO upDate VALUES('$update','$time','$created','$ip')\";
    return mysql_query($sqll);
    }else{
    return false;
    }
    }

    public function Connect() {
    mysql_connect($this->host,$this->username,$this->password) or die(\"Could not connect. \" . mysql_error());
    mysql_select_db($this->table) or die(\"Could not select database. \" . mysql_error());

    return $this->BuildDB();
    }

    private function BuildDB() {
    $sqll = <<<MySQL_QUERY
    CREATE TABLE IF NOT EXISTS upDate (
    update TEXT,
    time TEXT,
    created VARCHAR(100),
    ip TEXT
    )
    MySQL_QUERY;
    return mysql_query($sqll);
    }
    }

    ?>
  • well i don't know how to fix your issue. but I do have some advice. Do not quote serial killers on your website. Especially if you are trying to attract customers
  • The code snippet you've posted doesn't look like it ever calls the Connect() method or the BuildDB() method. Try turning error reporting on:

    error_reporting(E_ALL);
    ini_set(\"display_errors\", \"2\");


    See if you get any errors about the script not being able to connect to the database.
  • actually, it has both.. I put in the error script, and it came up with an error of the connection resetting by peer, then after that, no errors. I tried it about 5 times.