943,618 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1954
  • MySQL RSS
May 1st, 2009
0

Input data into the table from HTML file

Expand Post »
Azul(Hi)

i created program on php where i can output data set of any table by submitting query.
i need help to input i mean to load data into the table from the HTML file
can any one give help please
thank you.

this is the program i created, so far it work just for retrevie the information only i am looking to add from HTML

there 6 tables: clients, departments, projects, jobs, manages employees
php Syntax (Toggle Plain Text)
  1. <?php
  2. if (isset($_POST['door']) )
  3. {
  4. $door=$_POST['door'];
  5.  
  6. if(($door=="clients")||($door=="Clients")||($door=="departments")||($door=="Departements")||($door=="employees")||($door=="Employees")||($door=="jobs")||($door=="Jobs")||($door=="manages")||($door=="Manages")||($door=="projects")||($door=="Projects"))
  7. {
  8.  
  9.  
  10. if(($door =="clients")||($door =="Clients"))
  11.  
  12. {
  13. echo"you requested table Clients";
  14.  
  15. echo"we will try connect to the db<br/>\n";
  16.  
  17. $barak=mysql_connect("127.0.0.1","root","agouni2008");
  18.  
  19.  
  20.  
  21. if (!$barak)
  22.  
  23. {
  24. die("Fatal Error<br>".mysql_errno()."<br/>".mysql_error() );
  25. };
  26.  
  27.  
  28. echo "you are connect successfully to MYSQL <br/><br/>";
  29.  
  30. mysql_query("use dodgy");
  31.  
  32.  
  33.  
  34. if(mysql_errno() != 0)
  35.  
  36. {
  37. die("can't change databse");
  38. };
  39.  
  40.  
  41.  
  42. echo "Dtabase changed successfully! <br/>\n" ;
  43.  
  44.  
  45. $table = mysql_query("SELECT * FROM clients");
  46.  
  47.  
  48.  
  49.  
  50.  
  51. echo "<table border='10'>\n";
  52. echo" <tr>
  53. <tr bgcolor='red'>
  54. <th>code</th>
  55. <th>name</th>
  56. <th>adress</th>
  57. <th>telephone</th>
  58. <tr>";
  59.  
  60.  
  61.  
  62.  
  63. while($info=mysql_fetch_array($table,MYSQL_ASSOC))
  64. {
  65.  
  66. echo "<tr>
  67. <tr bgcolor='yellow'>
  68. <td bgcolor='blue'><b>".$info['Clie_ID']."<b/></td>".
  69. "<td>".$info['Clie_name']."</td>".
  70. "<td>".$info['Clie_adress']."</td>".
  71. "<td><a href='mailto:{$info['Clie_phone']}'>".$info['Clie_phone']."</a></td>
  72. </tr>\n";
  73.  
  74. };
  75.  
  76. echo "</table>\n";
  77. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  78.  
  79. }//closing if of clienttable
  80. else//not clients
  81. {
  82.  
  83. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@testing if it is DEPARTMENTS@@@@@@@@@@@@@@@@
  84. if(($door =="departments")||($door =="Dpartments"))
  85.  
  86. {
  87. echo"you requested table Departments ";
  88.  
  89. echo"we will try connect to the db<br/>\n";
  90.  
  91. $barak=mysql_connect("127.0.0.1","root","agouni2008");
  92.  
  93.  
  94.  
  95. if (!$barak)
  96.  
  97. {
  98. die("Fatal Error<br>".mysql_errno()."<br/>".mysql_error() );
  99. };
  100.  
  101.  
  102. echo "you are connect successfully to MYSQL <br/><br/>";
  103.  
  104. mysql_query("use dodgy");
  105.  
  106.  
  107.  
  108. if(mysql_errno() != 0)
  109.  
  110. {
  111. die("can't change databse");
  112. };
  113.  
  114.  
  115.  
  116. echo "Dtabase changed successfully! <br/>\n" ;
  117.  
  118.  
  119. $table = mysql_query("SELECT * FROM departments");
  120.  
  121.  
  122.  
  123.  
  124.  
  125. echo "<table border='10'>\n";
  126. echo" <tr>
  127. <tr bgcolor='red'>
  128. <th>code</th>
  129. <th>name</th>
  130. <th>adress</th>
  131. <tr>";
  132.  
  133.  
  134.  
  135.  
  136. while($info=mysql_fetch_array($table,MYSQL_ASSOC))
  137. {
  138.  
  139. echo "<tr>
  140. <tr bgcolor='yellow'>
  141. <td bgcolor='blue'><b>".$info['Dep_cod']."<b/></td>".
  142. "<td>".$info['Dep_name']."</td>".
  143. "<td>".$info['Dep_adress']."</td>
  144. </tr>\n";
  145.  
  146. };
  147.  
  148. echo "</table>\n";
  149.  
  150.  
  151. }//closing if of departments
  152. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@testing if it is employes@@@@@@@@@@@@@@@@@@@@@
  153. if(($door =="employees")||($door =="Employees"))
  154.  
  155. {
  156. echo"you requested table Employees ";
  157.  
  158. echo"we will try connect to the db<br/>\n";
  159.  
  160. $barak=mysql_connect("127.0.0.1","root","agouni2008");
  161.  
  162.  
  163.  
  164. if (!$barak)
  165.  
  166. {
  167. die("Fatal Error<br>".mysql_errno()."<br/>".mysql_error() );
  168. };
  169.  
  170.  
  171. echo "you are connect successfully to MYSQL <br/><br/>";
  172.  
  173. mysql_query("use dodgy");
  174.  
  175.  
  176.  
  177. if(mysql_errno() != 0)
  178.  
  179. {
  180. die("can't change databse");
  181. };
  182.  
  183.  
  184.  
  185. echo "Dtabase changed successfully! <br/>\n" ;
  186.  
  187.  
  188. $table = mysql_query("SELECT * FROM employees");
  189.  
  190.  
  191.  
  192.  
  193.  
  194. echo "<table border='10'>\n";
  195. echo" <tr>
  196. <tr bgcolor='red'>
  197. <th>Id</th>
  198. <th>name</th>
  199. <th>DOB</th>
  200. <th>Address</th>
  201. <th>Department code</th>
  202. <tr>";
  203.  
  204.  
  205.  
  206.  
  207. while($info=mysql_fetch_array($table,MYSQL_ASSOC))
  208. {
  209.  
  210. echo "<tr>
  211. <tr bgcolor='yellow'>
  212. <td bgcolor='blue'><b>".$info['Emp_id']."<b/></td>".
  213. "<td>".$info['Emp_name']."</td>".
  214. "<td>".$info['Emp_dob']."</td>".
  215. "<td>".$info['Emp_adress']."</td>".
  216. "<td>".$info['Dep_cod']."</td>
  217. </tr>\n";
  218.  
  219. };
  220.  
  221. echo "</table>\n";
  222.  
  223.  
  224. }//closing if of empolyees
  225. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@testing if it is jobs@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  226. if(($door =="jobs")||($door =="Jobs"))
  227.  
  228. {
  229. echo"you requested table Jobs ";
  230.  
  231. echo"we will try connect to the db<br/>\n";
  232.  
  233. $barak=mysql_connect("127.0.0.1","root","agouni2008");
  234.  
  235.  
  236.  
  237. if (!$barak)
  238.  
  239. {
  240. die("Fatal Error<br>".mysql_errno()."<br/>".mysql_error() );
  241. };
  242.  
  243.  
  244. echo "you are connect successfully to MYSQL <br/><br/>";
  245.  
  246. mysql_query("use dodgy");
  247.  
  248.  
  249.  
  250. if(mysql_errno() != 0)
  251.  
  252. {
  253. die("can't change databse");
  254. };
  255.  
  256.  
  257.  
  258. echo "Dtabase changed successfully! <br/>\n" ;
  259.  
  260.  
  261. $table = mysql_query("SELECT * FROM jobs");
  262.  
  263.  
  264. echo "<table border='10'>\n";
  265. echo" <tr>
  266. <tr bgcolor='red'>
  267. <th>Employees Id</th>
  268. <th>Projects number</th>
  269. <th>Working Dtae</th>
  270. <tr>";
  271.  
  272.  
  273.  
  274.  
  275. while($info=mysql_fetch_array($table,MYSQL_ASSOC))
  276. {
  277.  
  278. echo "<tr>
  279. <tr bgcolor='yellow'>
  280. <td bgcolor='blue'><b>".$info['Emp_id']."<b/></td>".
  281. "<td>".$info['Proj_num']."</td>".
  282. "<td>".$info['Date_work']."</td>
  283. </tr>\n";
  284.  
  285. };
  286.  
  287. echo "</table>\n";
  288.  
  289.  
  290. }//closing if of jobs
  291. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ testing if it is table manages@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  292. if(($door =="manages")||($door =="Manages"))
  293.  
  294. {
  295. echo"you requested table Manages ";
  296.  
  297. echo"we will try connect to the db<br/>\n";
  298.  
  299. $barak=mysql_connect("127.0.0.1","root","agouni2008");
  300.  
  301.  
  302.  
  303. if (!$barak)
  304.  
  305. {
  306. die("Fatal Error<br>".mysql_errno()."<br/>".mysql_error() );
  307. };
  308.  
  309.  
  310. echo "you are connect successfully to MYSQL <br/><br/>";
  311.  
  312. mysql_query("use dodgy");
  313.  
  314.  
  315.  
  316. if(mysql_errno() != 0)
  317.  
  318. {
  319. die("can't change databse");
  320. };
  321.  
  322.  
  323.  
  324. echo "Dtabase changed successfully! <br/>\n" ;
  325.  
  326.  
  327. $table = mysql_query("SELECT * FROM manages");
  328.  
  329.  
  330. echo "<table border='10'>\n";
  331. echo" <tr>
  332. <tr bgcolor='red'>
  333. <th>Departments code</th>
  334. <th>Projects number</th>
  335. <tr>";
  336.  
  337.  
  338.  
  339.  
  340. while($info=mysql_fetch_array($table,MYSQL_ASSOC))
  341. {
  342.  
  343. echo "<tr>
  344. <tr bgcolor='yellow'>
  345. <td bgcolor='blue'><b>".$info['Dep_cod']."<b/></td>".
  346. "<td>".$info['Proj_num']."</td>
  347. </tr>\n";
  348.  
  349. };
  350.  
  351. echo "</table>\n";
  352.  
  353.  
  354. }//closing if of manages
  355. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@testing if it is table projects@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  356. if(($door =="projects")||($door =="Projectss"))
  357.  
  358. {
  359. echo"you requested table Projectss ";
  360.  
  361. echo"we will try connect to the db<br/>\n";
  362.  
  363. $barak=mysql_connect("127.0.0.1","root","agouni2008");
  364.  
  365.  
  366.  
  367. if (!$barak)
  368.  
  369. {
  370. die("Fatal Error<br>".mysql_errno()."<br/>".mysql_error() );
  371. };
  372.  
  373.  
  374. echo "you are connect successfully to MYSQL <br/><br/>";
  375.  
  376. mysql_query("use dodgy");
  377.  
  378.  
  379.  
  380. if(mysql_errno() != 0)
  381.  
  382. {
  383. die("can't change databse");
  384. };
  385.  
  386.  
  387.  
  388. echo "Dtabase changed successfully! <br/>\n" ;
  389.  
  390.  
  391. $table = mysql_query("SELECT * FROM projects");
  392.  
  393.  
  394.  
  395.  
  396.  
  397. echo "<table border='10'>\n";
  398. echo" <tr>
  399. <tr bgcolor='red'>
  400. <th>Projects number</th>
  401. <th>Type</th>
  402. <th>Address</th>
  403. <th>Client Id</th>
  404. <tr>";
  405.  
  406.  
  407.  
  408.  
  409. while($info=mysql_fetch_array($table,MYSQL_ASSOC))
  410. {
  411.  
  412. echo "<tr>
  413. <tr bgcolor='yellow'>
  414. <td bgcolor='blue'><b>".$info['Proj_num']."<b/></td>".
  415. "<td>".$info['Proj_type']."</td>".
  416. "<td>".$info['Proj_adress']."</td>".
  417. "<td>".$info['Clie_id']."</td>
  418. </tr>\n";
  419.  
  420. };
  421.  
  422. echo "</table>\n";
  423.  
  424.  
  425. }//closing if of projects
  426. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ENd of testinf and viewinf tables@@@@@@@@@@@@
  427. }//closing else not cloients
  428.  
  429. }//close testing tables of database
  430. else
  431. {
  432. echo "There is not any table called <b>".$door."</b> in the Dodgy database";
  433. }
  434. echo "<tr>
  435. <A HREF='http://localhost/databases.php'>Click Here To go back the submit Query</A>
  436. </tr>";
  437. }//close _POST
  438. else//of if _POST
  439. {
  440. echo
  441. "<html>
  442. <head><title>Viewing tables of database</title>
  443. </head>
  444. <body>
  445. <form action='' method='POST'>
  446. <input type='text' name='door'>
  447. <input type='submit' />
  448. </form>
  449. </body>
  450. </html>";
  451. };
  452.  
  453.  
  454. ?>
Last edited by peter_budo; May 5th, 2009 at 2:20 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
marias is offline Offline
3 posts
since Apr 2009
May 1st, 2009
0

Re: Input data into the table from HTML file

From where you want to insert data in this table? from an html page that any user has submitted or from the DB?
Reputation Points: 21
Solved Threads: 0
Junior Poster
marjan_m is offline Offline
149 posts
since Apr 2005
May 2nd, 2009
0

Re: Input data into the table from HTML file

from DATA base (DB).

for more details: i have MYSQL and PHP instaed in machine only there no connect to any network (localhost).
as you see the program i posted before. from the html i put query then the program output table (data set) on html page. what i am looking how to use query to input from html file.
example: if have to unpdata table Clients i want to creat HTML page and by feeling all field (name, dob, address) and after pressing submit query will input this information on the table client.
thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
marias is offline Offline
3 posts
since Apr 2009
May 3rd, 2009
0

Re: Input data into the table from HTML file

Click to Expand / Collapse  Quote originally posted by marias ...
from DATA base (DB).

for more details: i have MYSQL and PHP instaed in machine only there no connect to any network (localhost).
as you see the program i posted before. from the html i put query then the program output table (data set) on html page. what i am looking how to use query to input from html file.
example: if have to unpdata table Clients i want to creat HTML page and by feeling all field (name, dob, address) and after pressing submit query will input this information on the table client.
thank you
As per I can reach to your problem you want to create such an html page from where you enter values and that values will be inserted in the table "client". For this the html page will be:

html Syntax (Toggle Plain Text)
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6. <title>Add new Client</title>
  7. </head>
  8.  
  9. <body>
  10. <form method="post" action="insertClient.php">
  11.  
  12. <table align="center" width="80%">
  13.  
  14. <tr>
  15. <td><input type="text" name="name" /></td>
  16. </tr>
  17.  
  18.  
  19. <tr>
  20. <td><input type="text" name="add" /></td>
  21. </tr>
  22.  
  23. </table>
  24.  
  25. </form>
  26. </body>
  27. </html>

and code for createClient.php is as follows:

php Syntax (Toggle Plain Text)
  1.  
  2. <?
  3.  
  4. // write here db connectivity code
  5.  
  6. /* value posted by user at html page. It will be retrived by post
  7.  method and should be saved in php variables */
  8.  
  9. $name = $_POST["name"];
  10. $add = $_POST["add"];
  11.  
  12. /* applying insert query. here the "name" and "add" are the name of db fields from client table and "$name", "$add" contains values posted by user */
  13.  
  14. $Q = mysql_query("Insert into clients (name, add) values ('$name', '$add') ");
  15.  
  16. /* if you have setted the client id at auto increment then there is no need to insert the value for client id, as db will automatically insert new id when a new client will be added */
  17.  
  18. ?>

Hope that it will be helpful.
Reputation Points: 21
Solved Threads: 0
Junior Poster
marjan_m is offline Offline
149 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: sql server 2000 and mysql
Next Thread in MySQL Forum Timeline: Bonus System DB design





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC