473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

I am trying to pass values from an html form to php...

4
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.   <p>
  4. WELCOME TO THE STUDENT PORTAL
  5.  </p>
  6. </head>
  7. <body>
  8.  
  9. <form action="details.php" method="post"  enctype="multipart/form-data">
  10.  
  11. <label>Student_id</label>
  12. <input type="integer" name="Student_id" id="Student_id">
  13.  
  14. <label>StudentName</label>
  15. <input type="text" name="StudentName" id="StudentName">
  16.  
  17.  <label>Surname</label>
  18. <input type="text" id="Surname"name="Surname">
  19.  
  20. <label>Parent</label>
  21. <input type="text" name="Parent" id="Parent">    
  22. <input type="submit"/>      
  23.  </form>
  24.  </body>
  25.    </HTML>



Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.   $Student_id = $_REQUEST['Student_id'];
  3.   $StudentName = $_REQUEST['StudentName'];
  4.   $Surname = $_REQUEST['Surname'];
  5.   $Parent = $_REQUEST['Parent'];
  6.  
  7.   echo("Student_id:" . $Student_id);
  8.   echo("Student Name:" . $StudentName);
  9.   echo("Surname:" . $Surname);
  10.   echo("Parent:" . $Parent);
  11.  
  12.  
  13.   ?>
  14.  



**ON THE PHP PAGE IT RETURNS THE PHP'coding INSTEAD ON THE VALUES ENTERED**
May 17 '14 #1
8 1743
you have to check if a value was in fact inserted in the input box itself man. If nothing was entered, there will be not data for you to output.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. if(isset($_POST["Student_id"])){
  4. $ID = $_POST["Student_id"];
  5.  
  6. //put your output code here
  7.  
  8. }
  9. ?>
  10.  
May 17 '14 #2
Baholo
4
thanks,what happens is that the ".html page" loads on the browser as intended and shows fields and a button, but the .php page just shows me the code ..

Expand|Select|Wrap|Line Numbers
  1.   <?php
  2. if(isset($_POST["Student_id"])){
  3. $ID = $_POST["Student_id"];
  4.  
  5.  echo("Student_id:" . $ID);
  6. }else
  7.    {
  8.    echo("No student " );
  9.  
  10. }
  11. ?>
  12.  
Is it still missing something? or maybe because both pages are stored in..."file:///C:/Users/Vex/Desktop/website/details.php"...
I am confused.
May 17 '14 #3
Hmmmmmm . . . . . now that is interesting.

you might be doing this incorrectly but correct me if i am wrong;
from what you said I assuming that you have two seperate pages or maybe you are not wording correctly but php code has to be embedded into the html code.

its not two seperate pages, remember, html is for the basic structure of the site, whilst PHP is to add dynamic functionality to it. so to clear that up, its one file.

I don't think anything is missing because i ran this on my system and it worked perfectly.

now I have experienced your problem before in internet explorer when I ran php files, but ever since I started using google chrome, i never had the issue. so maybe its your browser.

also what server are you using? is it old? or did you mess around with some options in the configuration that you shouldn't have? I personally use xampp and have not had any issues to date

another possible reason for this is that usually when a html file containing php code is saved accidently as an html file, php code in the browser will be exposed so double check that your files have the right extension.
May 17 '14 #4
Baholo
4
Yes you are right, here is my situation; I am using Notepad++ and have two separate pages, one named: studentregister.html and details.php. I am using Chrome as my Browser.

I am running widows 7 and don't remember altering my configurations.

when you say:
its not two seperate pages, remember, html is for the basic structure of the site, whilst PHP is to add dynamic functionality to it. so to clear that up, its one file.

..are you suggesting that i put all codes(everything) on 1 and only 1 page? like so..

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <?php
  3.  
  4. ?>
  5. </html>
  6.  
this does not make sense to me because what I understand is that the "form action=" function sends entered data on/from the ".html page" to the ".php page" specified on the "form action=" function.

so if i put everything on one page the; "studentregister.html"..and save it as so....then the "form action=" function will point to a page that does not exist and hence bring back the same page.

What do you mean they are one file? or do you mean they are just stored in one file maybe?

what i tried different was adding <html> tags on the ".php page" also so that it loads on the browser,like so:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. </body>
  4.    <?php
  5. if(isset($_POST["Student_id"])){
  6. $ID = $_POST["Student_id"];
  7.  echo("Student ID:" . $ID);
  8.  }else
  9.    {
  10.    echo("No student " );
  11.  }
  12. ?>
  13. </body>
  14. </html>
  15.  
I thought this was the missing piece, but now When I click submit I see a blank page..
May 18 '14 #5
ohk man I understand your problem, sorry for the late reply, i was quite busy.

I said it must be in one file because i assumed that you wanted your output on the same form page.

PHP is a server-side language, so processing for the dynamic page is done on the server side.

what you are trying to do is submit values from an html file to a php file. its not possible my friend. Html is static in its nature. Any process other than displaying stuff would require dynamic functionality. So the solution to your problem is a very simple one. change the file extension of the html file to "php". And it should work.

ignore what i said about embedding the code.
May 18 '14 #6
the code for checking if there was a value inserted will come in handy alittle later so keep it at hand. input validation is essential with forms man.
May 18 '14 #7
Rabbit
12,516 Expert Mod 8TB
If you are accessing the PHP page through a URL starting with file://, then you are not accessing it through the webserver. PHP has to be processed through a webserver to interpret the code.
May 18 '14 #8
Baholo
4
..But how do I do that Rabbit If I may ask?

On the right side of Nopepad++ it shows: "NppFTP - Connected to Bester Wireless" ...
After saving changes on each page I click on "upload file"..and according to my understanding this saves the pages on the server.

Now I have a file on my desktop which contained duplicate pages, the website file I think that is the reason why I get this :"file:///C:/Users/Vex/Desktop/website/details.php" because like you said it is not being accessed through the web server.

I deleted the file from my desktop, and now when I run the ".html page" on chrome from Note++ it loads but when I click submit it says it gives me a different path:..

"file:///C:/Users/Vex/AppData/Roaming/Notepad++/plugins/config/NppFTP/Cache/bestekef@www.besterwireless.com/bestekef/details.php" ...same with the ".html page"

How do I get it to run on the server because when I click submit it keeps taking me to anywhere else on my pc where the ".php page" is stored instead of on the server??
May 19 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Matthew Lasar | last post by:
I am trying to study php from a book. But the code doesn't seem to work for me. I set up a form, as follows: <html> <head> <title>form</title> </head> <body> <form action="results.php"...
1
by: Ross McLoughlin | last post by:
Hey all, Is it possible to pass a html form to a vb component, where it can be further processed? Thanks Ross
0
by: Martin | last post by:
I'm distributing stand-alone HTML forms for users to complete and e-mail/snail-mail back to me. (For security and budget reasons, receiving the form data to a web- server is not an option.) Then...
5
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 ...
2
by: Robert | last post by:
I have a form (frmWorksheet) that contains project information from a Projects table. The form contains a number of fields including ClientID and Project. On the form header is two combo boxes,...
3
by: drec | last post by:
I am creating a search box that the user types a value in, and then this gets passed to another page called search.php I would like to be able to pass these values through the URL, but I cant...
0
by: bp_jobemail | last post by:
I'm trying to use PHP to wrap the output of an HTML form before it goes into a precompiled C cgi script. Essentially, the company that I work for uses a purchased precompiled c program for their...
10
by: patsman77 | last post by:
I hope this is the right spot to post this.... I am working on a form to pull the information from the database. I am trying to use arrays, but I only get one record to come back and it is...
4
by: billa856 | last post by:
Hi, My project is in MS Access. I have one form in which I have one combobox.When I select an item from combobox and press submit button then report should be open and show all the details for the...
4
by: damicomj | last post by:
I am trying to pass an HTML Form variable to a .JS file. The .JS file then passes the variable to an ASP page, which works properly. The part that doesn't work properly is trying to pass it to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.