{"id":306,"date":"2010-07-28T01:58:55","date_gmt":"2010-07-28T05:58:55","guid":{"rendered":"http:\/\/www.searchenginegenie.com\/programming-blog\/?p=306"},"modified":"2012-12-11T02:36:58","modified_gmt":"2012-12-11T06:36:58","slug":"phphtml-to-connect-two-tables","status":"publish","type":"post","link":"https:\/\/www.searchenginegenie.com\/programming-blog\/phphtml-to-connect-two-tables\/","title":{"rendered":"Transfer data from one page to another using php"},"content":{"rendered":"<p><strong>Steps:<\/strong><\/p>\n<p><strong>1:Create new php file and copy file1 code and save it as file1.php.<\/strong><\/p>\n<p><strong>2.Create another new php file and copy file2 code and save it as file2.php.<\/strong><\/p>\n<p><strong>3.Run file1.php, then it will display the file1 data.<\/strong><\/p>\n<p><strong>4.Enter your name, age and location and press the submit button.<\/strong><\/p>\n<p><strong>5.It will transfer to file2.php and displays the output.<\/strong><\/p>\n<p><strong> file1:<\/strong><\/p>\n<p>[php]<\/p>\n<p>&lt;!DOCTYPE html PUBLIC &quot;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&quot; &quot;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&quot;&gt;<br \/>\n &lt;html xmlns=&quot;http:\/\/www.w3.org\/1999\/xhtml&quot;&gt;<br \/>\n &lt;head&gt;<br \/>\n &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=iso-8859-1&quot; \/&gt;<br \/>\n &lt;title&gt;table1&lt;\/title&gt;<br \/>\n &lt;script language=&quot;javascript&quot; type=&quot;text\/javascript&quot;&gt;<br \/>\n function check()<br \/>\n {<br \/>\n if(document.getElementById(&#8216;name1&#8217;).value==&#8221;)<br \/>\n {<br \/>\n alert(&quot;Please enter your name&quot;);<br \/>\n document.getElementById(&#8216;name1&#8217;).focus();<br \/>\n }<br \/>\n else if(document.getElementById(&#8216;age1&#8217;).value==&#8221;)<br \/>\n {<br \/>\n alert(&quot;please enter your age&quot;);<br \/>\n document.getElementById(&#8216;age1&#8217;).focus();<br \/>\n }<br \/>\n else if(document.getElementById(&#8216;location1&#8217;).value==&#8221;)<br \/>\n {<br \/>\n alert(&quot;please enter the location&quot;);<br \/>\n document.getElementById(&#8216;location1&#8217;).focus();<br \/>\n }<br \/>\n else<br \/>\n {<br \/>\n document.form.submit();<br \/>\n }<br \/>\n }<br \/>\n &lt;\/script&gt;<br \/>\n &lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<br \/>\n &lt;form method=&quot;post&quot; action=&quot;file2.php&quot; name=&quot;form&quot; &gt;<br \/>\n &lt;table width=&quot;100%&quot; border=&quot;0&quot;&gt;<br \/>\n &lt;tr&gt;<br \/>\n &lt;td&gt;&lt;label&gt;Enter your name: &lt;\/label&gt;<br \/>\n &lt;\/td&gt;<br \/>\n &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot;\u00a0 id=&quot;name1&quot;; \/&gt;<br \/>\n &lt;\/td&gt;<br \/>\n &lt;\/tr&gt;<br \/>\n &lt;tr&gt;<br \/>\n &lt;td&gt;&lt;label&gt;Enter your age:&lt;\/label&gt;<br \/>\n &lt;\/td&gt;<br \/>\n &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;age&quot; id=&quot;age1&quot;; \/&gt;<br \/>\n &lt;\/td&gt;<br \/>\n &lt;\/tr&gt;<br \/>\n &lt;tr&gt;<br \/>\n &lt;td&gt;&lt;label&gt;Enter the location:&lt;\/label&gt;<br \/>\n &lt;\/td&gt;<br \/>\n &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;location&quot; id=&quot;location1&quot;; \/&gt;<br \/>\n &lt;\/td&gt;<br \/>\n &lt;\/tr&gt;<br \/>\n &lt;tr&gt;<br \/>\n &lt;td colspan=&quot;2&quot;&gt; &lt;div align=&quot;center&quot;&gt;<br \/>\n &lt;input type=&quot;button&quot; value=&quot;Submit&quot; onclick=&quot;check();&quot; name=&quot;Submit&quot; \/&gt;<\/p>\n<p>&lt;\/div&gt;&lt;\/td&gt;<br \/>\n &lt;\/tr&gt;<br \/>\n &lt;\/table&gt;<br \/>\n &lt;\/form&gt;<br \/>\n &lt;\/body&gt;<br \/>\n &lt;\/html&gt;<\/p>\n<p>[\/php]<\/p>\n<p><strong>\/\/save this as file1.php<\/strong><\/p>\n<p><strong><script type=\"text\/javascript\">\/\/ <![CDATA[\nfunction check()\n{\n    if(document.getElementById('name1').value=='')\n\t{\n        alert(\"Please enter your name\");\n\t\tdocument.getElementById('name1').focus();\n    }\n\telse if(document.getElementById('age1').value=='')\n\t{\n\t\talert(\"please enter your age\");\n\t\tdocument.getElementById('age1').focus();\n\t}\n\telse if(document.getElementById('location1').value=='')\n\t{\n\t\talert(\"please enter the location\");\n\t\tdocument.getElementById('location1').focus();\n\t}\n\telse\n\t{\n     document.form.submit();\n    }\n}\n\/\/ ]]><\/script><\/strong><\/p>\n<p><strong>It will display the output as:<\/strong><\/p>\n<form action=\"table2.php\" method=\"post\">\n<table width=\"100%\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"text\"><label>Enter your name: <\/label><\/td>\n<td><input id=\"name1\" type=\"text\" name=\"name\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"text\"><label>Enter your age:<\/label><\/td>\n<td><input id=\"age1\" type=\"text\" name=\"age\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"text\"><label>Enter the location:<\/label><\/td>\n<td><input id=\"location1\" type=\"text\" name=\"location\" \/><\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\">\n<div><input onclick=\"check();\" type=\"button\" name=\"Submit\" value=\"Submit\" \/><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/form>\n<p><strong>file2:<\/strong><\/p>\n<p>[php]<\/p>\n<p>&lt;!DOCTYPE html PUBLIC &quot;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&quot; &quot;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&quot;&gt;<br \/>\n &lt;html xmlns=&quot;http:\/\/www.w3.org\/1999\/xhtml&quot;&gt;<br \/>\n &lt;head&gt;<br \/>\n &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=iso-8859-1&quot; \/&gt;<br \/>\n &lt;title&gt;table2&lt;\/title&gt;<br \/>\n &lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<br \/>\n &lt;?php<br \/>\n $var1=$_POST[&#8216;name&#8217;];<br \/>\n $var2=$_POST[&#8216;age&#8217;];<br \/>\n $var3=$_POST[&#8216;location&#8217;];<br \/>\n echo &quot;your name is: $var1&quot;.&quot;&lt;br\/&gt;&quot;;<br \/>\n echo &quot;your age is: $var2&quot;.&quot;&lt;br\/&gt;&quot;;<br \/>\n echo &quot;loaction is: $var3&quot;;<br \/>\n ?&gt;<br \/>\n &lt;\/body&gt;<br \/>\n &lt;\/html&gt;<\/p>\n<p>[\/php]<\/p>\n<p><strong>\/\/save this as file2.php<\/strong><\/p>\n<p><strong>after entering your name, age and location and pressing the submit button, it displays the output.<\/strong><\/p>\n<p><strong>For example:<\/strong><\/p>\n<p><strong>your name is: John<br \/>\nyour age is: 25<br \/>\nloaction is: CA<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Steps: 1:Create new php file and copy file1 code and save it as file1.php. 2.Create another new php file and copy file2 code and save it as file2.php. 3.Run file1.php, then it will display the file1 data. 4.Enter your name, age and location and press the submit button. 5.It will transfer to file2.php and displays [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[145,112,15],"class_list":["post-306","post","type-post","status-publish","format-standard","hentry","category-php","tag-html","tag-javascript","tag-php-code"],"_links":{"self":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/comments?post=306"}],"version-history":[{"count":13,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":315,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/306\/revisions\/315"}],"wp:attachment":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/media?parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/categories?post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/tags?post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}