0% found this document useful (0 votes)
25 views1 page

Mike

This document is a PHP script that inserts user-selected data from a dropdown menu into a MySQL database. It connects to the database, selects the appropriate table, inserts the dropdown data into the table, and checks that the insertion was successful. The script also contains an HTML form with the dropdown for the user to select earnings data and a submit button to insert it into the database.

Uploaded by

sanku242
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Mike

This document is a PHP script that inserts user-selected data from a dropdown menu into a MySQL database. It connects to the database, selects the appropriate table, inserts the dropdown data into the table, and checks that the insertion was successful. The script also contains an HTML form with the dropdown for the user to select earnings data and a submit button to insert it into the database.

Uploaded by

sanku242
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

mike.

php — Printed on 8/3/2009, 4:02:09 PM — Page 1


1 <?
2
3 if ($_POST['addDatatoDB'])
4 {
5
6 $link = mysql_connect("127.0.0.1","root",""); //IMPORTANT!!! Change server,
username and password if necessary
7 if(!$link) {
8 die('Failed to connect to server: ' . mysql_error());
9 }
10
11 $db = mysql_select_db("mysql"); //IMPORTANT!!! Change mysql to ur DB name
12 if(!$db) {
13 die("Unable to select database");
14 }
15
16 $earnings = $_POST['dropdown'];
17
18 $query = "INSERT INTO mike (a) VALUES ('" .$earnings. "')";
19
20 $result = mysql_query($query);
21 if(mysql_errno())
22 {
23 die("failed");
24 }
25 if (mysql_affected_rows() != 1)
26 {
27 die("failed to addd");
28 }
29 }
30
31 ?>
32 <html>
33 <head><title>sub</title>
34 </head>
35 <body>
36 <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
37 <tr><td align="right">earnings:</td>
38 <td align="left">
39 <select name="dropdown">
40 <option value="default">--select an earning--</option>
41 <option value="hra">HRA</option>
42 <option value="da">DA</option>
43 </select>
44 <td><input type="text" value=""></td></tr>
45 <tr><td><input type="submit" name="addDatatoDB" value="add to database"></td></tr>
46 </form>
47 </body>
48 </html>

C:\apache2triad\htdocs\mike.php — File date: 8/3/2009 — File time: 4:01:47 PM

You might also like