SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Doesn't update?

Hybrid View

  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <!-- editarticles.php -->
    <HTML>
    <HEAD>
    <TITLE> Edit article </TITLE>
    </HEAD>
    <BODY>



    <?php
    include("articles.inc");
    mysql_select_db("petesmc_articles");

    if ($submit): // The article's details have
    // been updated.

    $sql = "UPDATE articles SET " .
    "CatID='$catid', " .
    "SubID='$subid', " .
    "Status='$status', " .
    "TID='$tid', " .
    "SubTitle='$subtitle', " .
    "AuthorID='$authorid', " .
    "Description='$description', " .
    "Text='$text' " .
    "WHERE AID='$aid' AND PID='$pid'";

    if (mysql_query($sql)) {
    echo("<P>article details updated.</P>");
    } else {
    echo("<P>Error updating article details: " .
    mysql_error() . "</P>");
    }

    ?>

    <P><A HREF="articles.php">Return to article list</A></P>

    <?php
    else: // Allow the user to edit the article
    // with ID=$id



    $article=mysql_query("SELECT CatID, SubID, Status, TID, SubTitle, AuthorID, Description, Text " .
    "FROM articles WHERE AID='$aid' AND PID='$pid' ");

    if (!$article) {
    echo("<P>Error fetching article details: " .
    mysql_error() . "</P>");
    exit();
    }

    $article= mysql_fetch_array($article);

    $catid = $article["CatID"];
    $subid = $article["SubID"];
    $status = $article["Status"];
    $tid = $article["TID"];
    $subtitle = $article["SubTitle"];
    $authorid = $article["AuthorID"];
    $description = $article["Description"];
    $text = $article["Text"];




    ?>

    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
    <P>Edit ArticleBR>
    AuthorID: <INPUT TYPE=TEXT NAME="authorid" SIZE=5 MAXLENGTH=100 value="<?php echo($authorid); ?>"><BR>
    TitleID: <INPUT TYPE=TEXT NAME="tid" SIZE=5 MAXLENGTH=100 value="<?php echo($tid); ?>"><BR>
    CategoryID: <INPUT TYPE=TEXT NAME="catid" SIZE=5 MAXLENGTH=100 value="<?php echo($catid); ?>"><BR>
    SubcategoryID: <INPUT TYPE=TEXT NAME="subid" SIZE=5 MAXLENGTH=100 value="<?php echo($subid); ?>"><BR>
    Statusselect name="status" value="<?php echo($status); ?>">
    <option value="active">Active</option>
    <option value="featured">Featured</option>
    <option value="hidden">Hidden</option></select>
    SubTitle: <INPUT TYPE=TEXT NAME="subtitle" SIZE=25 MAXLENGTH=100 value="<?php echo($subtitle); ?>"><BR>
    Descriptionbr> <TEXTAREA name="description" ROWS=6 COLS=45 WRAP><?php echo($description); ?></textarea><br><br>
    Textbr> <TEXTAREA name="text" ROWS=25 COLS=60 WRAP><?php echo($text); ?></textarea><br>
    <INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
    </FORM>

    <?php endif; ?>

    <table width="100%" border="1"><tr><td><b>Category List/b><br><br>

    <?php
    // STARRT LISTING

    include("articles.inc");
    mysql_select_db('petesmc_articles');

    $category = mysql_query("SELECT ID, Cat FROM category");
    if (!$category) {
    echo("<P>Error retrieving categories from database!<BR>".
    "Error: " . mysql_error());
    exit();
    }

    while ($cats = mysql_fetch_array($category)) {
    $ccatid = $cats["ID"];
    $ccat = $cats["Cat"];
    echo("$ccatid. $ccat <br>");
    }

    ?>

    </td><td><b>SubCategory List/b><br><br>

    <?php

    include("articles.inc");
    mysql_select_db('petesmc_articles');

    $subcategory = mysql_query("SELECT ID, CID, SubCat FROM subcategory");
    if (!$subcategory) {
    echo("<P>Error retrieving subcategories from database!<BR>".
    "Error: " . mysql_error());
    exit();
    }

    while ($ssubcats = mysql_fetch_array($subcategory)) {
    $ssubid = $ssubcats["ID"];
    $ssubcatid = $ssubcats["CID"];
    $ssubcat = $ssubcats["SubCat"];
    echo("$ssubid - $ssubcatid. $ssubcat <br>");
    }

    ?>

    </td><td><b>Authors List/b><br><br>

    <?php

    include("articles.inc");
    mysql_select_db('petesmc_articles');

    $authors = mysql_query("SELECT ID, Name FROM authors");
    if (!$authors) {
    echo("<P>Error retrieving authors from database!<BR>".
    "Error: " . mysql_error());
    exit();
    }

    while ($author = mysql_fetch_array($authors)) {
    $aauthorid = $author["ID"];
    $aauthorname = $author["Name"];
    echo("$aauthorid. $aauthorname <br>");
    }

    ?>

    </td><td><b>Title List/b><br><br>

    <?php

    include("articles.inc");
    mysql_select_db('petesmc_articles');

    $gettitle = mysql_query("SELECT ID, Title FROM title");
    if (!$gettitle) {
    echo("<P>Error retrieving titles from database!<BR>".
    "Error: " . mysql_error());
    exit();
    }

    while ($gottitle = mysql_fetch_array($gettitle)) {
    $ttitleid = $gottitle["ID"];
    $ttilename = $gottitle["Title"];
    echo("$ttitleid. $ttilename <br>");
    }

    ?>
    </tr></table>


    <!-- END OF LiSTING -->
    </BODY>
    </HTML>

    Any idea why this won't update the table?

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forogt to mention that i don't get an error, it just doesn't update

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry that I don't provide a solution but so that petesmc and everybody knows, petesmc is not the only one with this problem.

    I had opened another thread at http://www.sitepointforums.com/showt...threadid=13788 a while ago. I haven't got any useful response but I feel better that some other people have similar problem.

    Petesmc, could you please also check if you can delete any rows? I have both problems, not able to update and delete according to the primary key. I can delete or update according to other fields.

    petesmc, please check my problem, too. they are very similar. It might help us to figure out the problem.

    http://www.sitepointforums.com/showt...threadid=13788

    thanks

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pete where do you assign values to $aid and $pid you are trying to update a record based on what have you tried printing the sql statement to the screen

    like

    print $sql;

    then copy and paste what you see on the screen to the commmand line mysql or into phpmyadmin since I know you love it. and see what errors it comes up with, this is a very useful debugging method.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, i did that, and pid and aid are undefined. How would i define them. THey are AID = article ID and pid = page id:

    They are in the URL

    http://www.blah.com/editarticle.php?aid=1&pid=4

    I tried doing thiss:

    $article= mysql_fetch_array($article);

    $catid = $article["CatID"];
    $subid = $article["SubID"];
    $status = $article["Status"];
    $tid = $article["TID"];
    $subtitle = $article["SubTitle"];
    $authorid = $article["AuthorID"];
    $description = $article["Description"];
    $text = $article["Text"];
    $aid = $article["AID"];
    $pid = $article["PID"];

    but it doesn't update still?

    KEKO: I looked at your thread, and i am saying that it is only this table that doesn't update...now i know for the problem that freddydoesphp pointed out

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well since you create a form on the page and then submit the form your $aid and $pid are lost unless you create hidden inputs for them in your form

    <input type="hidden" name="aid" value="<? print $aid; ?>">
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I worked it out, I took the quotes off the:

    WHERE AID=$aid ......

    and added:

    <INPUT TYPE=hidden NAME="aid" VALUE="<?php echo($aid); ?>">
    <INPUT TYPE=hidden NAME="pid" VALUE="<?php echo($pid); ?>">

    In the form.


    *I replied 1 second after you*

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx to everyond that has helped me through my first go a MySQL and PHP. I have nearly finished the content management for my site, and already have others things done.


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
  •