Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question php-mysql data update

    hello,

    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.

  • #2
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    What is your question?

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    hello,

    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>" );
    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 >";
    echo "<form method=POST >";
    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 ;
    }

    }
    $j=$j+1;
    echo "</tr>";
    }
    echo "</table>";
    echo "</body>";

    ?>


    Table

    -- phpMyAdmin SQL Dump
    -- version 2.8.0.3
    -- 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,
    PRIMARY KEY (`ID`)
    ) 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');

  • #4
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •