Jump to content

edit mysql table from bowser problem


moran1409

Recommended Posts

hello all, i am trying to edit a mysql table from the browser using these codes:

 

edit.php:

	      include"db.inc.php";//database connection
      $order = "SELECT * FROM prices";
      $result = mysql_query($order);
      while ($row=mysql_fetch_array($result)){
        echo ("<tr><td>$row[id_number]</td>");
        echo ("<td>$row[product]</td>");
        echo ("<td>$row[price]</td>");
        echo ("<td><a href=\"edit_form.php?id=$row[id_number]\">Edit</a></td></tr>");
      }

 

edit_form.php

	      <table>
      <?
      include "db.inc.php";//database connection
      $order = "SELECT * FROM prices where id_number='$id'";
      $result = mysql_query($order);
      $row = mysql_fetch_array($result);
      ?>
      <form method="post" action="edit_data.php">
      <input type="hidden" name="id" value="<? echo "$row[id_number]"?>">
        <tr>       
          <td>Product</td>
          <td>
            <input type="text" name="product"
        size="20" value="<? echo "$row[product]"?>">
          </td>
        </tr>
        <tr>
          <td>Price</td>
          <td>
            <input type="text" name="price" size="40"
          value="<? echo "$row[price]"?>">
          </td>
        </tr>
        <tr>
          <td align="right">
            <input type="submit"
          name="submit value" value="Edit">
          </td>
        </tr>
      </form>
      </table>

 

edit_data.php

	include "db.inc.php";
$order = "UPDATE prices SET product='$_POST[product]', price='$_POST[price]' WHERE id_number='$id'";
mysql_query($order);
header("location:edit.php");

 

the table:

CREATE TABLE IF NOT EXISTS `prices` (

  `id_number` int(3) NOT NULL,

  `product` varchar(30) DEFAULT NULL,

  `price` int(6) DEFAULT NULL,

  PRIMARY KEY (`id_number`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

 

the data is displayed correctly but i can't change the data...

Link to comment
https://forums.phpfreaks.com/topic/228926-edit-mysql-table-from-bowser-problem/
Share on other sites

I haven't been in coding for awhile and I am just getting back in it, but try this at edit_data.php

 

<?php
include ("db.inc.php");
$product = $_POST["product"];
$price = $_POST["price"];



$order = "UPDATE prices SET product='$product', price='$price' WHERE id_number='$id'";



mysql_query($order);



header("location:edit.php");
?>

 

edited this should work...

edit data (changed - but still not working...)

	include "db.inc.php";
     $order = "UPDATE prices
          SET product='$product',
              price='$price'
          WHERE
          id_number='$id'";
mysql_query($order);
echo $price;

 

 

 

 

i don't fully understand you both, all i am trying to do is update a mysql table could you tell me which part of the code should i change and how will i do that?

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.