-1

Why isn't my php file getting executed in my 2 tier application?

HTML CODE

<form autocomplete='on' name='form1' method='get'action='new_Assignment1.php'>
<table>
<tr>
<td>Username:</td><td><input type='textbox' name='usrname' maxlength='10'></td></tr>
<tr><td>First name:</td><td><input type='textbox' name='fname'></td></tr>
<tr><td>Last name:</td><td><input type='textbox' name='lname'></td></tr>
<tr><td>Age:</td><td><input type='number' name='age'   min='18' max='65' style='float:left;'></td></tr>
<tr><td>Empno:</td><td><input type='number' name='eno' min='10' step='2'style='float:left;'></td></tr>
<tr><td>Submit a file:</td><td><input type='file' formenctype='multipart/formdata' name='upfile'></td></tr>
<tr><td><input type='checkbox' name='terms' value='Tnc' checked>Terms & Conditions</td></tr>
<tr><td>Google Search:</td><td><input type='search' name='google' style='float:left;'></td></tr>
<tr><td><input type='submit'/></td></tr>
<tr><td><input type='submit' value='Click me' disabled /></td></tr>
</table>
</form>

PHP CODE

<?php
$var_1=$_REQUEST['usrname'];
$var_2=$_REQUEST['fname'];
$var_3=$_REQUEST['lname'];
$var_4=$_REQUEST['age'];
$var_5=$_REQUEST['eno'];
$var_6=$_REQUEST['file'];
$var_7=$_REQUEST['google'];
echo $var_1;
echo $var_2;
echo $var_3;
echo $var_4;
echo $var_5;
echo $var_6;
echo "You have searched"echo $var_7"."
if($var_7='Tnc')
{
"Agreed to terms and conditions.";
}
else
{
"Not agreed to terms and conditions.";
}
?>

OUTPUT OF HTML FILE 'enter image description here'

OUTPUT OF PHP FILE ON SUBMISSION OF HTML FILE 'enter image description here'

I'am not understanding why my php file is not getting invoked?

Taylor
  • 21
  • 4
  • you tried to reference images, but there's no link for them. so... kind of hard to figure out what's wrong here. There's also no array for `terms`. – Funk Forty Niner Feb 18 '16 at 17:24
  • output of html file is the first pic – Taylor Feb 18 '16 at 17:25
  • then you have `upfile` for a name attribute but using `$_REQUEST['file']` and you must use a POST method in order to process files. Files do not get processed with GET. So I'd call that an undefined index duplicate. and this `formenctype='multipart/formdata'` belong in form, not in input. but missing a space for it too `form enctype='multipart/formdata'` but that belongs in `
    ` and a post method.
    – Funk Forty Niner Feb 18 '16 at 17:26
  • Could it be because you're missing a space between your form method and form action? – hasumedic Feb 18 '16 at 17:30
  • A suggestion is put your both file at same location (at same place or same folder may be). And put `enctype='multipart/formdata'`along with `
    – Alive to die - Anant Feb 18 '16 at 17:30
  • I posted an answer below but made a few edits since. `formenctype='multipart/formdata'` is wrong for 2 reasons. It belongs in `
    ` and contains a typo which should read as `enctype="multipart/form-data"`. So, you'll need to reload it in order to see those edits. There's more info in it, but may be beyond the scope of this question. check for errors and I've shown you how in there. @Taylor
    – Funk Forty Niner Feb 18 '16 at 17:43
  • and these 2 things `echo "You have searched"echo $var_7"." if($var_7='Tnc')` are failing you, as I edited in my answer. Again... check for errors and see my note about webserver/php and how they're accessed. there is nothing else I can do here, except to catch a flight to where you are and sit right beside you to do this. – Funk Forty Niner Feb 18 '16 at 18:12

3 Answers3

1

Is your php code contained in new_Assignment1.php, if not that is where your problem is. Also not capital A in Assignment1.php. Links are case sensitive esp on live servers.

Your error is "this webpage is not found" which means you are posting to a page that does not exist.

TheTechGuy
  • 16,560
  • 16
  • 115
  • 136
0

There's quite a few things wrong here.

You have name='upfile' for a name attribute for the input, but using $_REQUEST['file'] so that doesn't match.

However, you must use a POST method in order to process files.

Files do not get processed with a GET method.

Then this formenctype='multipart/formdata' belongs in form, not in input and just enctype='multipart/formdata'. But there's a typo, it should be enctype="multipart/form-data" with a hyphen.

I.e.:

<form enctype="multipart/form-data" autocomplete='on' name='form1' method='post' action='new_Assignment1.php'>

Then you need to change all $_REQUEST to $_POST.

But for the file, it needs to read as $_FILES

and using:

$var_6=$_FILES['upfile']['name'];

Reference:

Sidenote: There is no indication as to how you want to process that file.

If the intention is to save it to a folder, then you need to use move_uploaded_file() and make sure the folder you want to upload to, has the proper permissions for it.

The manual contains an example on how to deal with uploaded files:

Plus, you have no array set for <input type='checkbox' name='terms' value='Tnc' checked>, so unsure how you want to handle that.

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Then the rest of your code

Sidenote: Displaying errors should only be done in staging, and never production.

And as noted in comments (and an answer), that comment appears to have been deleted and transcribed as answer.

  • A web page not found could mean that you may not have addressed the correct file.

On a * NIX system, FILE.xxx or File.xxx isn't the same as file.xxx as they are case-sensitive, unlike on a Windows platform.

Or that you are accessing PHP through a web browser as c:///folder/file.xxx rather than http://localhost/folder/file.xxx.

If you do not have a web server/PHP installed, then you won't be able to process PHP directives, should that be the case here.

Edit:

Oh, and you have a missing closing semi-colon in:

echo "You have searched"echo $var_7"."

and that alone would have caused a parse syntax error.

Then if($var_7='Tnc') you are assigning instead of comparing if($var_7 =='Tnc')

One = is an assignment. Two == is a comparison and three === is "identical".

Consult the following on Stack about those:

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • the intention is to display the uploaded file in the php file – Taylor Feb 18 '16 at 17:45
  • @Taylor that's a totally different animal here. You need another piece of code to do that. How were you planning on displaying it? as noted in my answer, have covered everything I could with what you posted in your original question. Displaying images is beyond the scope of this question. – Funk Forty Niner Feb 18 '16 at 17:48
  • @Taylor If you want to display files after processing, see http://stackoverflow.com/q/21703154/ and http://stackoverflow.com/a/16285454/ and as I said; was beyond the scope of your question. – Funk Forty Niner Feb 18 '16 at 17:50
0

HTML CODE :

<form  name='form1' method='POST'action='viewuser.php' enctype="multipart/form-data">
<table>
<tr>
<td>Username:</td><td><input type='textbox' name='usrname' maxlength='10'></td></tr>
<tr><td>First name:</td><td><input type='textbox' name='fname'></td></tr>
<tr><td>Last name:</td><td><input type='textbox' name='lname'></td></tr>
<tr><td>Age:</td><td><input type='number' name='age'   min='18' max='65' style='float:left;'></td></tr>
<tr><td>Empno:</td><td><input type='number' name='eno' min='10' step='2'style='float:left;'></td></tr>
<tr><td>Submit a file:</td><td><input type="file" name="file"/></td></tr>
<tr><td><input type='checkbox' name='terms' value='Tnc' checked>Terms & Conditions</td></tr>
<tr><td>Google Search:</td><td><input type='search' name='google' style='float:left;'></td></tr>
<tr><td><input type='submit' value='submit'/></td></tr>
<tr><td><input type='submit' value='Click me' disabled /></td></tr>
</table>
</form>

PHP CODE

<?php
$var_1=$_REQUEST['usrname'];
$var_2=$_REQUEST['fname'];
$var_3=$_REQUEST['lname'];
$var_4=$_REQUEST['age'];
$var_5=$_REQUEST['eno'];
$var_6=$_FILES['file']['name'];
$var_7=$_REQUEST['google'];
if(isset($_REQUEST['usrname']) && isset($_REQUEST['fname']) && isset($_REQUEST['lname']) && isset($_REQUEST['age']) && isset($_REQUEST['eno']) && isset($_REQUEST['google']))
{
echo "User name :".$var_1;
echo "<br>Name :".$var_2.''.$var_3;
echo "<br>age :".$var_4;
echo "<br>Emp No :".$var_5;
echo "<br>File Name :".$var_6;
echo "<br> You have searched".$var_7;
if($var_7='Tnc')
{
"Agreed to terms and conditions.";
}
else
{
"Not agreed to terms and conditions.";
}
}
else
{
    echo "Please  Check you are missing some parameter";

}
?>

Output enter image description here

Vasim Shaikh
  • 4,485
  • 2
  • 23
  • 52