+ Reply to Thread
Results 1 to 3 of 3

Thread: editing a row in mysql using php

  1. #1
    cr-designs.co.uk bandit is on a distinguished road
    Join Date
    Feb 2004
    Location
    Uk
    Age
    21
    Posts
    476
    Rep Power
    54

    editing a row in mysql using php

    hi guys, im trying to create a pretty basic cms which ive done before however for some reason the row isnt updating. Wonder if u could take a look and see whats wrong. Thanks

    <?


    mysql_connect("localhost","test","test");
    mysql_select_db("ict");

    if(!isset($cmd))
    {
    $result = mysql_query("select * from policies order by id");
    while($r=mysql_fetch_array($result))
    {
    $title=$r["title"];
    $id=$r["id"];
    echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
    echo "<br>";
    }
    }
    ?>

    <?
    if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
    {
    if (!isset($_POST["submit"]))
    {
    $id = $_GET["id"];
    $sql = "SELECT * FROM policies WHERE id=$id";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);
    ?>

    <form action="edit.php" method="post">
    <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">

    Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
    Content:<TEXTAREA NAME="content" ROWS=20 COLS=60><? echo $myrow["content"] ?></TEXTAREA><br>
    Date:<INPUT TYPE="TEXT" NAME="content" VALUE="<?php echo $myrow["date"] ?>" SIZE=30><br>

    <input type="hidden" name="cmd" value="edit">

    <input type="submit" name="submit" value="submit">

    </form>

    <? } ?>
    <?
    if ($_POST["$submit"])
    {
    $title = $_POST["title"];
    $content = $_POST["content"];
    $date = $_POST["date"];

    $sql = "UPDATE policies SET title='$title',date='$date',content='$content' WHERE id=$id";


    $result = mysql_query($sql);
    echo "Information updated.";
    }
    }
    ?>
    It displays the data fine, however when i click submit i get taken back to the edit.php page and i dont get "information updated" so i dont know whats up.

    Just in case your wondering the database im using is called: ict, and the table is: policies.

    thanks in advance
    mike
    #freelancers @ qnet
    attended WCG 2005 with teamuk
    8-10 Eurocup XIII

  2. #2
    cr-designs.co.uk bandit is on a distinguished road
    Join Date
    Feb 2004
    Location
    Uk
    Age
    21
    Posts
    476
    Rep Power
    54

    Re: editing a row in mysql using php

    just in case any1 was wondering
    if ($_POST["$submit"]) needed to be if ($_POST["submit"])

    and i got my form name element wrong lol!
    #freelancers @ qnet
    attended WCG 2005 with teamuk
    8-10 Eurocup XIII

  3. #3
    Fire Starter admin Sean is a splendid one to behold Sean is a splendid one to behold Sean is a splendid one to behold Sean's Avatar
    Join Date
    Aug 2003
    Location
    Chicago, IL
    Age
    23
    Posts
    2,841
    Rep Power
    10

    Re: editing a row in mysql using php

    hehe good job
    sd // SPRING 2010

+ Reply to Thread

Similar Threads

  1. Php n' MySQL Online PDF.
    By sickone in forum Programming
    Replies: 1
    Last Post: 05-08-2005, 06:43 AM

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27