JAVA N WEB TECH SYLLABUS

Thursday, December 23, 2010

Program to insert new name and age information entered by the user into the database.

cust.html


    <html>

    <body>
    Enter the Customer details to add a  record in Customer table
    <br>
    <form action="http://192.168.8.3/naveen/cust.php" method="get">
    Name:<input type="text" name="uname">
    Age:<input type="text" name="uage">
    <input type="submit" >
    <input type="reset">
    </form>

    
    </body>
    </html>


output:
-----------------------------------------------------------------------------------------------------------------------------------
Enter the Customer details to add a record in Customer table

Name: Age:
-------------------------------------------------------------------------------------------------------------
cust.php


             <?
                $name=$_GET["uname"];
                $age=$_GET["uage"];
                $query1="Insert into customer values('$name',$age)";
                echo "$query1";
                
                
                // connect to the mysql server on localhost 
                $mysql = mysql_connect("192.168.8.3", "naveen", "a") 
                    or die("could not connect to mysql"); 

                    
                // execute the MySQL query, grab the result in $result 
                $result1 = mysql_db_query("naveen", $query1) 
                    or die("query failed  ");
                    $query2="select * from customer";
                echo "$query2";
                $result = mysql_db_query("studentinfo", $query2) 
                    or die("query failed  ");
                

            ?> 
            <html> 
            <head> 
            <title>PHP and MySQL</title> 
            </head> 
            <body bgcolor="CYAN"> 
            We Added the Record: 
            <hr> 
            We found <b> <?echo mysql_num_rows($result); ?></b> rows. 

            <h3>Query result</h3> 
            <br>
            <table border=2>
            <tr>
                
                <td>NAME</td>
                <td>AGE</td>
                
            </tr>

                
             <?
                //loop through each row 
                while ($array = mysql_fetch_row($result)) 
                { 
                    echo "<tr>";

                    echo "<td>$array[0]</td>";
                    echo "<td>$array[1]</td>";
                    
                echo "</tr>";
             
                } 
            ?> 
            </table>
            </body> 
            </html> 
             <?
                // we are all done, so close the MySQL connection 
                mysql_close($mysql); 
            ?> 
-------------------------------------------------------------------------------------------------------------
OUTPUT:
Insert into customer values('naveen11',27)   
We Added the Record:
We found rows.

Query result select * from customer


NAME AGE
jhonny 22
bravo 22
naveen 27
xyz 27
abc27

No comments:

Post a Comment