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

Link to comment
Share on other sites

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?

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.