Jump to content

Quick UPDATE and SET question


timmyj

Recommended Posts

Hi guys/girls,

any pointers on this would be greatly appreciated.

basically i have a table called HORSES with 2 fields: HORSE_ID and HORSE_NAME.

I want to create a page which dynamically shows all the horse ID's, then a checkbox, then the horse names which can be edited.

You can then edit a horse name, click the edit checkbox, and post the form to edit the database.

The Form shows the fields easily enough, but doesnt update the database for some reason.

Anyone got any ideas?

 

<?php

      include("..\connection\connection.php");

    $conn = oci_connect($UName,$PWord,$DB)

      or die("Couldn't logon.");

  if(empty($_POST["check"]))

  {

    $query = "SELECT * FROM HORSE ORDER BY HORSE_NAME";

    $stmt = oci_parse($conn,$query);

    oci_execute($stmt);

 

?>

    <form method="post" action="horsemultiple.php">

      <table border="1" cellpadding="5">

      <tr>

        <th>Horse_ID</th>

        <th>Edit</th>

        <th>Horse Name</th>

      </tr>

<?php

      while ($namearray = oci_fetch_array ($stmt))

      {

?>

        <tr>

          <td><?php echo $namearray["HORSE_ID"]; ?></td>

          <td align="center">

            <input type="checkbox" name="check[]"

              value="<?php echo $namearray["HORSE_ID"]; ?>">

          </td>

          <td align="center">

 

<input type="text" size="5"

            name="<?php echo $namearray["HORSE_ID"]; ?>"

            value="<?php echo $namearray["HORSE_NAME"]; ?>">

 

          </td>

        </tr>

<?php

      }

?>

      </table><p />

      <center>

        <input type="submit"

          value="Update Selected Horses">

      </center>

    </form>

<?php

    oci_free_statement($stmt);

  }

  else

  {

    foreach($_POST["check"] as $id)

  {

 

$query = "UPDATE HORSE

      set HORSE_NAME = ".$_POST[$id].

      " WHERE HORSE_ID ='".$id."'";

    $stmt = oci_parse($conn,$query);

    oci_execute($stmt);

    header("location: ../horse.php");

 

  }

  }

  oci_close($conn);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.