passing variable to update

Discussion in 'PHP' started by ducca, Oct 24, 2006.

  1. #1
    Hi,
    I,m trying to update a entry via a form but need to pass the variable into the form so the output is displayed, I can then carry out an update statement on the entry. my problem is passing the variable, The code enables a record to be deleted but I also want to update via the edit link, the delete in the code works fine but the editquizzz.php won,t pickup the variable value, the value is shown in the address bar,heres where i pass the edit

    <?php
    //deletquiz.php

    include("contentdb.php");
    $id = $_GET["id"];
    if($_GET["cmd"]=="delete")
    {
    $sql = mysql_query("DELETE FROM $table WHERE id='$id'",$db);
    //$result = mysql_query($sql);
    //echo "Row deleted!";

    }

    ?>
    <?php

    include("contentdb.php");

    $result = mysql_query("SELECT id, question FROM $table ORDER BY id",$db);

    echo "<table>";

    while ($row = mysql_fetch_array($result))
    {


    $id = $row["id"];
    $question = $row["question"];


    if ($alternate == "1") {
    $color = "#ffffff";
    $alternate = "2";
    }
    else {
    $color = "#efefef";
    $alternate = "1";
    }
    echo "<tr bgcolor=$color><td>$id:</td><td>$question</td><td>[ <a href='editquizzz.php?id=$id'>edit</a> ]</td><td>[<a href='deletequiz2.php?cmd=delete&id=$id'onClick=\"return confirm('Are you sure?')\">delete</a>]</td></tr>";
    }
    echo "</table>";
    ?>

    And heres were I should pick up the value $id which should show the data in the form

    //editquizzz.php


    include("contentdb.php");



    $result = mysql_query("SELECT * FROM $table WHERE id='$id'",$db);
    $myrow = mysql_fetch_array($result);
    ?>
    <form method="get" action= $PHP_SELF?">
    <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
    <b>Question:</b><br>
    <input type="text" name="question" value="<?php echo $myrow["question"]?>" size="50">
    <br>
    <b>Option 1:</b><br>
    <input type="Text" name="opt1" value="<?php echo $myrow["opt1"]?>" size="30">
    <br>
    <b>Option 2:</b><br>
    <input type="Text" name="opt2" value="<?php echo $myrow["opt2"]?>" size="30">
    <br>
    <b>Option 3:</b><br>
    <input type="Text" name="opt3" value="<?php echo $myrow["opt3"]?>" size="30">
    <br>
    <b>Answer</b> (must be identical to correct option):<br>
    <input type="Text" name="answer" value="<?php echo $myrow["answer"]?>" size="30">
    <br>
    <br>
    <input type="Submit" name="update" value="Update information"></form>

    Thanks in advance for any help
    Regards
     
    ducca, Oct 24, 2006 IP
  2. ducca

    ducca Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Thanks all.
    Sorted now:mad: :mad:
    staring me in the face
    Cheers
     
    ducca, Oct 24, 2006 IP