Page 1 of 1

php script will not execute

PostPosted: 31. July 2012 10:04
by super2424
Hi everyone! I'm completely new to this. I installed xampp a few days ago. I've been trying to figure out how to get my php script to run. I've searched around
and haven't gotten anywhere. So I joined a forum :D . It worked fine when I was starting off with a basic script like localhost\phpinfo.php in my browser.
It executes just find. I know I must put everything in my htdocs in order for a php script to run. Ok now the problem... I've created a form in html. Once submitted it
executes a php script. But instead of displaying the persons name, email, comments etc.... It just displays the variables instead of the actual data it holds. That's on google chrome. On internet explorer it just displays the source code. I would very much appreciate the help..

Re: php script will not execute

PostPosted: 31. July 2012 11:46
by Altrea
Hi super2424,

please use line breaks in your threads for better readability.

super2424 wrote:I've created a form in html. Once submitted it executes a php script. But instead of displaying the persons name, email, comments etc.... It just displays the variables instead of the actual data it holds. That's on google chrome. On internet explorer it just displays the source code. I would very much appreciate the help..


Very common you don't request the file with the form the right way. SImply opening it in the browser will not work. It has to be requested with a valid URL.

best wishes,
Altrea

Re: php script will not execute

PostPosted: 01. August 2012 06:19
by super2424
Thanks for the reply. But Shouldn't it work if I have both the files in my htdocs? That's where I'm supposed to put them, correct?

Re: php script will not execute

PostPosted: 01. August 2012 07:36
by Altrea
If you request them correct, yes. If not, then no.
The whole thing depends what is showing in your browsers address bar at the time you get the sourcecode instead processed php.

Re: php script will not execute

PostPosted: 02. August 2012 05:26
by super2424
I appreciate you helping me. I've been searching all over the internet. When I load my php script(localhost/handle_form.php) I get a parse error I can't find. Here's the parse error.

Parse error: syntax error, unexpected ',' in C:\xampp\htdocs\handle_form.php on line 24

I guess this is why it's not working. It's displaying an error I can't find or seems to not exsist.

Everything looks fine. The code is excactly how it is in a php book I'm reading. Here's my script

<?php
ini_set ('display_errors', 1);
// Let me learn from my mistakes!
error_reporting (E_ALL | E_STRICT);
// Show all possible problems!

// This page receives the data from
feedback.html.
// It will receive: title, name, email,

response, comments and submit in //This is line 24.
$_POST.

// Create shorthand versions of the
variables:
$title = $_POST['title'];
$name = $_POST['name'];
$response = $_POST['response'];
$comments = $_POST['comments'];

// Print the received data:
print "<p>Thank you, $title $name,
for your comments.</p>
<p>You stated that you found this
example to be $response and
added:<br />$comments</p>";
?>


I really wanna figure it out.

Thanks! :)

Re: php script will not execute

PostPosted: 02. August 2012 14:06
by JonB
By any chance is this line 24

print "<p>Thank you, $title $name,
for your comments.</p>

8)

Re: php script will not execute

PostPosted: 02. August 2012 16:21
by Altrea
super2424 wrote:Parse error: syntax error, unexpected ',' in C:\xampp\htdocs\handle_form.php on line 24

I guess this is why it's not working.

That is not your initial problem that the variables are displayed instead of it's content.
If that would be your initial issue, you would get this error message after sending the form too.
But i guess that you request the form the wrong way.

super2424 wrote:Here's my script

<?php
ini_set ('display_errors', 1);
// Let me learn from my mistakes!
error_reporting (E_ALL | E_STRICT);
// Show all possible problems!

// This page receives the data from
feedback.html.
// It will receive: title, name, email,

response, comments and submit in //This is line 24.
$_POST.

// Create shorthand versions of the
variables:
$title = $_POST['title'];
$name = $_POST['name'];
$response = $_POST['response'];
$comments = $_POST['comments'];

// Print the received data:
print "<p>Thank you, $title $name,
for your comments.</p>
<p>You stated that you found this
example to be $response and
added:<br />$comments</p>";
?>

Please wrap your code in code-BBTags, because:
  • Your singleline line brakes are not visible here as single lined.
  • I can't see why the line you marked should be line 24.

sorry, but i can't provide any help with that informations.

best wishes,
Altrea

Re: php script will not execute

PostPosted: 02. August 2012 23:21
by super2424
I guess I'll figure it out eventually but here is my entire code for it. Thanks!

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/
xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/
xhtml" xml:lang="en" lang="en">
 <head>
 <meta http-equiv="Content-Type"
content="text/html; charset=utf-8"/>
 <title>Your Feedback</title>
 </head>
 <body>

 <?php
 ini_set ('display_errors', 1);
// Let me learn from my mistakes!
 error_reporting (E_ALL | E_STRICT);
// Show all possible problems!

 // This page receives the data from
feedback.html.
 // It will receive: title, name, email,

response, comments, and submit in   // This is line 24
$_POST.

 // Create shorthand versions of the
variables:
 $title = $_POST['title'];
 $name = $_POST['name'];
 $response = $_POST['response'];
 $comments = $_POST['comments'];

 // Print the received data:
 print "<p>Thank you, $title $name,
for your comments.</p>
 <p>You stated that you found this
example to be $response and
added:<br />$comments</p>";
 ?>
 </body>
 </html>

Re: php script will not execute

PostPosted: 02. August 2012 23:39
by Altrea
If this is your real sourcecode (line breaks, etc) then you have a massive problem with your singleline linebreaks. Your code will not run.

Re: php script will not execute

PostPosted: 03. August 2012 08:17
by super2424
WOW.. I finally figured it out!!!!! :mrgreen:

Re: php script will not execute

PostPosted: 03. August 2012 08:43
by Altrea
so why don't you tell the community what the problem was so that other users can have a benefit from your thread?

Re: php script will not execute

PostPosted: 03. August 2012 09:16
by super2424
On my php script I deleted the extra things like the html doc type at the head of my script as well as the title etc.. Any html element that was outside the php tags

<?php---?> and just left the php itself. Not sure if it is a proper thing to do but it worked for me. Then Just put a basic html element and a body

element around the php tags and still worked. Here is my revision of my php script. Hope it helps others. Thanks!

Code: Select all
<html>

<body>

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



 error_reporting (E_ALL | E_STRICT);

//variables
 $title = $_POST['title'];
 $name = $_POST['name'];
 $response = $_POST['response'];
 $comments = $_POST['comments'];

 // Print the received data:
 print "<p>Thank you, $title $name,
for your comments.</p>
 <p>You stated that you found this
example to be $response and
added:<br />$comments</p>";

 ?>
 </body>

 </html>