Jump to content

[SOLVED] Update does not occur


aznjay

Recommended Posts

<?
include "database.php";
?>
<form method="post">
<select name="base">
<option value="ps">Photoshop</option>
<option value="phptut">Php Tutorial</option>
</select>
<input type="submit" name="table" value="submit">
</form>
<?

if(isset($_POST['base']))
{
    $tabs = $_POST["base"];

   //display all the news
   $result = mysql_query("select * from $tabs 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
      $title=$r["title"];//take out the title
      $id=$r["id"];//take out the id
      $rob=$r["id"];//take out the id
 //make the title a link
      echo "<a href='editlinks.php?cmd=edit&id=$id&base=$tabs'>$title - Edit</a> | ";
      echo "<a href='editlinks.php?cmd=delete&id=$rob&base=$tabs'>DELETE</a>";
      echo "<br>";
    }
}


elseif(isset($_REQUEST["cmd"]) && $_REQUEST["cmd"] == "edit")
{
   if (!isset($_POST["submit"]))
   {
      $ids = $_GET["id"];
  $tabsl = $_GET["base"];
      $sql = "SELECT * FROM $tabsl WHERE id=$ids";
  $result = mysql_query($sql) or die('MySQL Error: ' .mysql_error());
      $myrow = mysql_fetch_array($result);

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

      Title:<INPUT TYPE="TEXT" NAME="right" VALUE="<?php echo $myrow["title"]; ?>" SIZE=30><br>
      Description:<INPUT TYPE="TEXT" NAME="left" VALUE="<?php echo $myrow["desp"]; ?>" SIZE=30><br>
      Time:<INPUT TYPE="TEXT" NAME="up" VALUE="<? echo date("g:i a"); ?>" SIZE=30><br>
      Date:<INPUT TYPE="TEXT" NAME="down" VALUE="<? echo date("M.j.y"); ?>" SIZE=30><br>
      Article:<br><TEXTAREA NAME="side" ROWS=15 COLS=40><? echo $myrow["article"] ?></TEXTAREA><br>




      <input type="submit" name="edit_update" value="submit">
      </form>
<?php
    }
elseif(isset($_REQUEST["cmd"]) && $_REQUEST["cmd"] == "edit")
{
    // perform the following when the form below is submitted
    if(isset($_POST['edit_update']))
    {
        $id = $_POST["id"];
        $title = $_POST["title"];
        $time = $_POST["time"];
        $date = $_POST["date"];
        $message = $_POST["message"];

        $tabs = $_POST["base"];

        $sql = "UPDATE $tabs SET title='$title',time='$time',date='$date',article='$message', WHERE id=$id";

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

        echo 'Table `'.$tabs.'` updated!';
    }
    // form hasn't been submitted yet, display edit form
    else
    {
        $id = $_GET["id"];
    	$tabs = $_GET["base"];
        $sql = "SELECT * FROM $tabs WHERE id=$id";
        $result = mysql_query($sql) or die('MySQL Error: ' .mysql_error());;
        $myrow = mysql_fetch_array($result);
?>
      <form method="post">
      <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">

      Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["head"] ?>" SIZE=30><br>
      Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br>
      Time:<INPUT TYPE="TEXT" NAME="time" VALUE="<?php echo date("g:i a"); ?>" SIZE=30><br>
      Date:<INPUT TYPE="TEXT" NAME="date" VALUE="<?php echo date("M.j.y"); ?>" SIZE=30><br>
      Message:<br><TEXTAREA NAME="message" ROWS=15 COLS=40><?php echo $myrow["msg"] ?></TEXTAREA><br>

      <input type="hidden" name="cmd" value="edit">
      <input type="hidden" name="base" value="<?php echo $base; ?>">

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

      </form>
<?php
    }
}
elseif(isset($_REQUEST["cmd"]) && $_REQUEST["cmd"] == "delete")
{
    echo 'Perform delete action here';
}
else {
        echo '<pre>' . print_r($_POST, true) . '</pre>';
    }
}
?>

The code UPDATe doesn't work at all..

Link to comment
https://forums.phpfreaks.com/topic/125405-solved-update-does-not-occur/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.