View Full Version : php-mysql data update

06-20-2006, 11:12 PM

i'h developed code where the user will give the table name and the quary will fetch the data from that table and display the each field value in text box. but when the user see the table data he can make the value of any text box and then press update. then the table will updated with the new and old field value. the main problem is tht we make a script where the table structure is dynamic and different user can input different table which can have different number of fields.

please help me. :confused:

06-21-2006, 05:50 AM
What is your question?

06-21-2006, 08:25 AM

well my question was i need a script which will update data for any table at a time.. so far what i have done is given below ..

please notice tht the code is for one given table, but i want the user to input the table so that he/she can do all the modification at a time .. the below is only the code to fetch the data and put it in the text box .. but when this user click update all the data will be updated into the database.


$db = mysql_connect("localhost", "root", "");
if (!$db) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
$user_tablename = "student_info";

if(!isset($query)|| empty($query))
$query="select *from $table";
$result = mysql_query($query);
if(!$result) error_message(sql_error());

echo "<BODY >";
echo "<form method=POST >";
echo "<TABLE width=90%>";
echo "<tr align=center >";
$j = 1 ;
echo "<th> <FONT size=2>". mysql_field_name($result,$i)."</font></th>\n";
echo "</tr>\n";

echo "<tr align=center onMouseOver=\"this.style.backgroundColor='#336699'\" onMouseOut=\"this.style.backgroundColor='white'\">\n";
for($i=0;$i<$number_cols; $i++)
echo "<td><FONT size=2>-</font></td>";
$t_d= "t".$i.$j;
<td><input type="text" name="<? $t_d ?>" size=10 value = "<? echo $row[$i]; ?>"></td>

echo $t_d ;

echo "</tr>";
echo "</table>";
echo "</body>";



-- phpMyAdmin SQL Dump
-- version
-- http://www.phpmyadmin.net
-- Host: localhost
-- Generation Time: May 28, 2006 at 10:53 AM
-- Server version: 5.0.20
-- PHP Version: 5.1.2
-- Database: `test1`

-- --------------------------------------------------------

-- Table structure for table `student_info`

CREATE TABLE `student_info` (
`ID` varchar(7) collate latin1_general_ci NOT NULL,
`Name` varchar(50) collate latin1_general_ci NOT NULL,
`Address` varchar(75) collate latin1_general_ci NOT NULL,
`email` varchar(25) collate latin1_general_ci NOT NULL,
`phone` varchar(10) collate latin1_general_ci NOT NULL,
`blood_group` varchar(3) collate latin1_general_ci NOT NULL,
`Gender` varchar(1) collate latin1_general_ci NOT NULL,
`D_o_b` date NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

-- Dumping data for table `student_info`

INSERT INTO `student_info` VALUES ('0110031', 'Nafees Mansoor', 'flat 7/I, Aziz Housing Society, Shahbagh, Dhaka', 'nafees@iub.edu.bd', '0189412860', 'O-', 'M', '1983-12-31');
INSERT INTO `student_info` VALUES ('0110001', 'test', 'test', 'test', 'test', 'XX', 'X', '2006-05-15');

06-21-2006, 01:17 PM
Please use CODE tags when pasting code.

You obviously get the table data via a query to the database. It's quite easy to build a form based on the structure of that data. If you include simple <input type = "hidden" /> elements, you should be able to emulate the table structure properly in order that it can be interpreted.

06-21-2006, 07:37 PM
thanks for the advice .. but i'm a it confused where to put the hidden tag and how it gonna help me ... and can u plz tell me how to update data when user insert the new data in any field ..