SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot JonathanS's Avatar
    Join Date
    Jun 2004
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Updating a mysql record

    PHP Code:
    <?php
    session_start
    ();

    // Set the page title
    $title "Last Entry.com - Add Comment";

    // Set the Description Meta Data
    $dmeta "Description Meta Data";

    // Set the Keyword Meta Data
    $kmeta "Keyword Meta Data";

    // Require the class file
    require_once('rf/class.php');

    // Require the news paging file
    require_once('rf/nps.php');

    // Require the header file
    require_once('rf/head.php');

    // Set variables to a common vars
    $cookie_site $_COOKIE['lastentry'];
    $cookie_name $_COOKIE['lastentry_fname'];
    $cookie_blog $_COOKIE['lastentry_blog'];
    $php_self $_SERVER['PHP_SELF'];
    $usrip getenv("REMOTE_ADDR");
    $editReply $_GET['edit'];

    // Connect to MySQL
    $db = & new MySQL($host,$dbUser,$dbPass,$dbName);
    $dataClean = & new data();

    // Check to see if there is a session
    if(!isset($_COOKIE['lastentry'])) {
        echo 
    "<div class=\"title\">Error!</div>";
        echo 
    "<div class=\"normal\">You are not logged in!</div>";
    } else {

    // send a query to the mySQL database
    $gdnps "SELECT id, author, title, msg, email, DATE_FORMAT(date, '%h:%i - %m.%d.%y') AS fdate, blog";
    $gdnps .= " FROM gdnps WHERE id='$id' ";

    $result $db->query($gdnps);
    while (
    $row $result->fetch()) {

    $id $row['id'];
    $entryauthor $row['author'];
    $entrytitle $row['title'];
    $entrytext $row['msg'];
    $entryemail $row['email'];
    $date $row['fate'];
    $blog $row['blog'];


        
    // Run the script if submitted
    if ($_POST['submit']) {

    $id $row['id'];
    $entryauthor $row['author'];
    $entrytitle $row['title'];
    $entrytext $row['msg'];
    $entryemail $row['email'];
    $date $row['fate'];
    $blog $row['blog'];

    if (! 
    $entrytitle) {
        echo 
    "<div class=\"title\">Error!</div>";
        echo 
    "<div class=\"normal\">You did not fill out the title fields! <br /> Please go back!</div>";
            exit();
    }

    if (! 
    $entrytext) {
        echo 
    "<div class=\"title\">Error!</div>";
        echo 
    "<div class=\"normal\">You did not fill out the message field! <br /> Please go back and correct this!</div>";
            exit();
    }

        
    // Sanitize the data! Implement BBCode!
    $entryauthor $dataClean->clean($entryauthor); // Clean the author
    $entryemail $dataClean->clean($entryemail);   // Clean the email
    $entrytitle $dataClean->clean($entrytitle);   // Clean the title
    $entrytext $dataClean->clean($entrytext);     // Clean the text

    $entrytitle $dataClean->bbcode($entrytitle);  // Add BBcode!
    $entrytext $dataClean->bbcode($entrytext);    // Add BBCode!

        // SQL query...
    $gdnps2 "UPDATE gdnps SET author='$entryauthor', title='$entrytitle', msg='$entrytext', ";
    $gdnps2 .= "ip='$ip', blog='$entryblog' WHERE id='$editReply'";

        
    // Process said query
    $db->query($gdnps2);

    if (! 
    $db->isError())
        echo 
    "<div class=\"title\">Success!</div><div class=\"normal\"><a href=\"blog.php?blog=$cookie_blog\" "
        
    "class=\"doc\">Click here to return to the home of $cookie_blog</a></div>";
    else
        echo 
    "<div class=\"title\">Error!</div><div class=\"normal\">This was NOT posted!</div>";

    } else {

    echo 
    "<div class=\"title\">Edit your Entry</div>";
    echo 
    "<div class=\"normal\">";

    echo 
    "<a href=\"javascript:bbcode()\" class=\"doc\">BB Code</a>";
    echo 
    "<form method=\"post\" action=\"$php_self\">";

    echo 
    "<p> <input type=\"hidden\" name=\"id\" value=\"$id\" /> </p>";
    echo 
    "<p> <input type=\"hidden\" name=\"entryauthor\" value=\"$cookie_name\" /> </p>";
    echo 
    "<p> <input type=\"hidden\" name=\"ip\" value=\"$usrip\" /> </p>";

    echo 
    "<p> Title </p>";
    echo 
    "<p> <input type=\"text\" name=\"entrytitle\" value=\"$entrytitle\" /> </p>";

    echo 
    "<p> Message </p>";
    echo 
    "<p> <textarea cols=\"40\" rows=\"10\" name=\"entrytext\">$entrytext</textarea>";

    echo 
    "<p> <input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /> </p>";

    echo 
    "</form>";
    echo 
    "</div>";

            }
        }
    }

    // Require footer
    require_once('rf/foot.php');

    ?>
    Abit messy... anyways, this is my first time I've tried to make a update/edit
    page, but as you can see... eh; not very good. When I tried it, I get this error:

    Notice: Query failed: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 's try it again!', ip='127.0.0.1', blog='' WHERE id=''' at line SQL: UPDATE gdnps SET author='Jonathan', title='', msg='Let's try it again!', ip='127.0.0.1', blog='' WHERE id='' in E:\xampp\xampp\htdocs\actual\Last Entry\rf\class.php on line 49
    Error!
    This was NOT posted!
    Its nearly 3AM, and I can't figure it out for the life of me.

  2. #2
    SitePoint Addict loadx's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne, VIC, Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is NOT an advanced topic

    are u escaping the quotes on (let's) ?

    otherwise write the damn query on one line, cos that looks horrible

  3. #3
    SitePoint Zealot JonathanS's Avatar
    Join Date
    Jun 2004
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought it went under here since it uses (or tries to!) OOP..
    I must've misread the "Where to post your thread" thread.

    Anyways, I realized I didn't have addslashes() in my function,
    which I borrowed from this topic here.

    It works now.. sort of. Doesn't give me a error but it won't update it


Bookmarks

Posting Permissions

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