SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot maffp's Avatar
    Join Date
    Jun 2005
    Location
    UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Please can somebody tell me what I've done wrong here?

    Hi!

    I have written this piece of PHP to check and update a mysql table but it's just not working. It is retrieving the information fine and showing it in the inputs/textareas but it is not updating the table when I click submit. It just shows my message for when the sql hasn;t worked (i.e. "Page not saved...") Any ideas? Please help!

    Code PHP:
    <?php
        $getSql = @mysql_query("SELECT * FROM site_settings LIMIT 4");
        if (!$getSql) {
            exit ("<p>Error retrieving site settings:" . mysql_error() . "</p>\n\n");
        }
        while ($siteSettings = @mysql_fetch_array($getSql)) {
            $pageId = $siteSettings['id'];
            $pageRef = $siteSettings['ref'];
            $pageTitle = $siteSettings['pagetitle'];
            $pageDescription = $siteSettings['pagedescription'];
            $pageKeywords = $siteSettings['pagekeywords'];
     
            if (isset($_POST['submit'.$pageId])) {
                $pageId = $_POST['pageId'];
                $pageTitle = $_POST['pageTitle'];
                $pageDescription = $_POST['pageDescription'];
                $pageKeywords = $_POST['pageKeywords'];
                $updateSql = mysql_query("UPDATE site_settings SET pagetitle='$pageTitle', pagedescription='$pageDescription', pagekeywords='$pageKeywords') WHERE id='$pageId' LIMIT 1");
                if (!$updateSql) {
                    echo ("<p class='notify'><b>Page editing not saved!</b>\n".
                        "Please <a href='javascript:history.go(-1)'>try again</a> or notify the webmaster\n\n</p>");
                } else {
                    echo "<p class='notify'><b>Page updated!</b></p>\n";
                }
            }
     
            echo "<h3>$pageRef</h3><form method='post' action='".$_SERVER[PHP_SELF]."'>".
                "<label for='pageTitle'>Page Title</label><input name='pageTitle' type='text' value='$pageTitle' size='53' />".
                "<label for='pageDescription'>Page Description</label><textarea name='pageDescription' cols='40' rows='3'>$pageDescription</textarea>".
                "<label for='pageKeywords'>Page Keywords</label><textarea name='pageKeywords' cols='40' rows='3'>$pageKeywords</textarea>".
                "<input type='hidden' name='pageId' value='$pageId' />".
                "<input type='submit' value='Save $pageRef Settings' name='submit$pageId' class='submit' /><hr class='hr1' /></form>";
     
        }
     
    ?>

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    try echoing mysql_error():
    PHP Code:
    $updateSql mysql_query("UPDATE site_settings SET pagetitle='$pageTitle', pagedescription='$pageDescription', pagekeywords='$pageKeywords') WHERE id='$pageId' LIMIT 1");
    if (!
    $updateSql) {
                    echo 
    "<p class='notify'><b>Page editing not saved!</b>\nPlease <a href='javascript:history.go(-1)'>try again</a> or notify the webmaster\n\n</p>";
                    echo 
    "The error: ".mysql_error();
    }else{
                    echo 
    "<p class='notify'><b>Page updated!</b></p>\n";

    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Zealot maffp's Avatar
    Join Date
    Jun 2005
    Location
    UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the quick reply! The error said "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 ') WHERE id='1' LIMIT 1' at line 1"

    I'm a silly bugger... I left a bracket in the sql.

    Thank you! I would probably have spent all day going back and forth going through that code and missing it every time!

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's alright - happens to all of us.

    Lucky post count btw.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •