Jump to content

Recommended Posts

Hi all

I'm having a bit of trouble with this script. I should be able to read the contents of the table - display it - and then update the table when I submit the changes.

 

At the moment it can read and display the table data but it wont make any changes.

 

Here is a live preview

 

http://rsl.likeaaron.com/admin/edit.php

 

heres the code

 

<?

//connect to mysql

include("_db_conn.php");

 

//If cmd has not been initialized

if(!isset($cmd))

{

  $result = mysql_query("select * from heading order by id");

 

  //run the while loop that grabs all the news scripts

  while($r=mysql_fetch_array($result))

  {

      //grab the title and the ID of the news

      $head=$r["head"];//take out the title

      $id=$r["id"];//take out the id

   

//make the title a link

      echo "<a href='edit.php?cmd=edit&id=$id'>$head - Edit</a>";

      echo "<br>";

    }

}

?>

<?

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")

{

  if (!isset($_POST["submit"]))

  {

      $id = $_GET["id"];

      $sql = "SELECT * FROM heading 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"] ?>">

 

      heading:<INPUT TYPE="TEXT" NAME="head" VALUE="<?php echo $myrow["head"] ?>" SIZE=30><br>

      body:<TEXTAREA NAME="body" ROWS=10 COLS=30><? echo $myrow["body"] ?></TEXTAREA><br>

 

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

 

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

 

      </form>

 

<? } ?>

<?

  if ($_POST["$submit"])

  {

      $head = $_POST["head"];

  $body = $_POST["body"];

 

  $sql = "UPDATE heading SET head='$head',body='$body' WHERE id=$id";

      $result = mysql_query($sql) or die (mysql_error());

      echo "Ok";

}

}

?>

 

Thankyou in advance. Please Help

change

<?
   if ($_POST["$submit"])
   {
      $head = $_POST["head"];
     $body = $_POST["body"];
    
     $sql = "UPDATE heading SET head='$head',body='$body' WHERE id=$id";
      $result = mysql_query($sql) or die (mysql_error());
      echo "Ok";
   }
}
?>

to

<?php
   if ($_POST["$submit"])
   {
     $ip = $POST['id'];
     $head = $_POST["head"];
     $body = $_POST["body"];
    
     $sql = "UPDATE heading SET head='$head',body='$body' WHERE id=$id";
      $result = mysql_query($sql) or die (mysql_error());
      echo "Ok";
   }
}
?>

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.