Jump to content

Update


aznjay

Recommended Posts

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="id" 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="update" value="submit">
      </form>
<?php
    }


elseif ($_POST["update"])
{
if (!isset($_POST["update"]))
{
echo '<meta http-equiv="refresh" content="1;url=editlinks.php">';
      $id = $_POST["id"];
      $title = $_POST["right"];
      $tme = $_POST["left"];
      $dte = $_POST["down"];
  $message = $_POST["side"];

  
  $tabsl = $_GET["base"];
  $sql = "UPDATE $tabsl SET title='$title',time='$tme',date='$dte',article='$message', WHERE id=$id";
      //replace news with your table name above
      $result = mysql_query($sql);
}
}

    else
    {
        echo '<pre>' . print_r($_POST, true) . '</pre>';
    }
}
?>

The Update does not work.....

Link to comment
https://forums.phpfreaks.com/topic/125255-update/
Share on other sites

Can you indent your code so it is readable?

<?php
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="update" value="submit">
      </form>
<?php
    }
else {
        echo '<pre>' . print_r($_POST, true) . '</pre>';
    }
}
?>
<?
if ($_POST["update"])
{

echo '<meta http-equiv="refresh" content="1;url=editlinks.php">';
      $idd = $_POST["idd"];
      $titl = $_POST["right"];
      $tme = $_POST["left"];
      $dte = $_POST["down"];
  $mesage = $_POST["side"];
  
  $tabsl = $_GET["base"];

  $sql = "UPDATE $tabsl SET title='$titl',time='$tme',date='$dte',article='$mesage', WHERE id=$idd";
      //replace news with your table name above
      $result = mysql_query($sql);
}
?>

 

The update command doesn't work

Link to comment
https://forums.phpfreaks.com/topic/125255-update/#findComment-647491
Share on other sites

The first thing you do once the if condition to update is met is to redirect to another page, eg;

 

if ($_POST["update"])
{

echo '<meta http-equiv="refresh" content="1;url=editlinks.php">';

 

Moving that to a more logical position (like after the actual update takes place) would help.

Link to comment
https://forums.phpfreaks.com/topic/125255-update/#findComment-647536
Share on other sites

The first thing you do once the if condition to update is met is to redirect to another page, eg;

 

if ($_POST["update"])
{

echo '<meta http-equiv="refresh" content="1;url=editlinks.php">';

 

Moving that to a more logical position (like after the actual update takes place) would help.

That one is nowt really a problem i tried this in diffrent pages and it worked...

Link to comment
https://forums.phpfreaks.com/topic/125255-update/#findComment-647663
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.