View Full Version : php mysql data updatation problem
nafees
06-07-2006, 04:32 AM
i would like to use a script where i can fetch the data from a table and display it into number of text boxes. and then if the user change the value of the text boxes and press update, the database will be updated. again the table name is dynamic to make the code applicable for all cases. plz help me :confused:
lavinpj1
06-07-2006, 06:20 AM
Since we do not know your table structure, all I can say is that you need SELECT and UPDATE queries.
~Phil~
nafees
06-07-2006, 06:34 AM
i can retrive data from any table of any field size. but the problem arises when to update it. The code is given below. plz help me
<?
if ($_SERVER['REQUEST_METHOD']='POST') { // if page is not submitted to itself echo the form
echo "function executed";
}
if ($_SERVER['REQUEST_METHOD']='GET'){
$db = mysql_connect("localhost", "root", "");
if (!$db) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
$database="test1";
mysql_select_db("$database",$db);
$user_tablename = "student_info";
$table=$user_tablename;
if(!isset($query)|| empty($query))
{
$query="select *from $table";
}
$query=stripslashes($query);
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$number_cols=mysql_num_fields($result);
echo "<BODY >"; ?>
<form method=POST action="<?php $_SERVER['PHP_SELF']; ?>">
<?
echo "<TABLE width=90%>";
echo "<tr align=center >";
$j = 1 ;
for($i=0;$i<$number_cols;$i++)
{
echo "<th> <FONT size=2>". mysql_field_name($result,$i)."</font></th>\n";
}
echo "</tr>\n";
while($row=mysql_fetch_row($result))
{
echo "<tr align=center onMouseOver=\"this.style.backgroundColor='#336699'\" onMouseOut=\"this.style.backgroundColor='white'\">\n";
for($i=0;$i<$number_cols; $i++)
{
if(empty($row[$i]))
echo "<td><FONT size=2>-</font></td>";
else
{
$t_d= "t".$i.$j;
?>
<td><input type="text" name="<? $t_d ?>" size=10 value = "<? echo $row[$i]; ?>"></td>
<?
// echo $t_d ;
$arr[$j][$i]=$row[$i];
}
}
$stud_id[$j]= $row[0];
// echo $stud_id[];
$j=$j+1;
echo "</tr>";
}
echo "<input type=submit value=update>";
echo "</table></form>";
echo "</body>";
}
echo $j;
for ($k=$j-1;$k>0;$k--)
{
echo $stud_id[$k];
for($f=0;$f>0;$f++){
echo $arr[$k][$f];}
}
?>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.