Here is my code: The page opens, but when I submit it I get this message " This page isn’t working
If the problem continues, contact the site owner.
HTTP ERROR 405"
<div class="form">
<form action="contactform.php" method="post">
<div class="name-section">
<input type="text" name="name" autocomplete="off" required />
<label for="name" class="label-name"></label>
<span class="content-name">Name</span>
</div>
<div class="companyname-section">
<input type="text" name="CompanyName" autocomplete="off" required />
<label for="Company Name" class="label-name"></label>
<span class="content-name">Company Name</span>
</div>
<div class="phonenumber-section">
<input
type="tel"
name="PhoneNumber"
autocomplete="off"
pattern="[0-9]{3} [0-9]{3}-[0-9]{4}"
required
/>
<label for="Phone Number" class="label-name"></label>
<span class="content-name">Phone Number</span><br />
</div>
<div class="email-section">
<input type="email" name="email" autocomplete="off" required />
<label for="email" class="label-name"></label>
<span class="content-name">Email Address</span>
</div>
<div class="messageus">
<label for="Message" class="label-name"></label>
<span class="content-name">Message Us!</span>
<br />
<textarea
id="sagecontact"
name="MessageUs"
rows="4"
cols="50"
></textarea>
</div>
<input type="submit" value="submit" id="submitbutton">
</form>
</div>
Thanks for any and all help
***Edit: So my php problems are fixed but when I add my …json page and try to load my website I get this message back: Not Found
The requested resource /
was not found on this server.
But when I delete my .json page my website loads
my .json page only has this
{
“install”: “echo ‘We Are Ready!’”,
“start”: “php -S 0.0.0.0:3000 -t .”
}
Can you please tell us the name of the project
Why is there no index.html
Your project is likely not working because you are trying to POST information to a static HTML page. I recommend that read into PHP forms as PHP is a great language for managing user input such as forms.
https://www.w3schools.com/php/php_forms.asp
1 Like
I do like PHP better, but it’s not well supported on Glitch. Would recommend using Express Routing for you POST
2 Likes
Really either option works, Express docs can be found here:
https://expressjs.com/
1 Like
yes. That is the link to the form I am talking about
Is this error fixed? From looking at your source code, it looks like you have set up PHP as the POST.
To run php you need to add this to your glitch.json file @jrstokes73
{
"install": "echo 'We Are Ready!'",
"start": "php -S 0.0.0.0:3000 -t ."
}
1 Like
I did that, filled out my form, submitted it, and got back
" This page isn’t working
sage-sourcing-and-support.glitch.me is currently unable to handle this request.
HTTP ERROR 500"
HTTP 500 means you have a PHP error. Do you have any errors in the logs?
here’s what my php code looks like:
<?php ( isset( $_POST['submit'] ) )|
$name = $_POST['name'];|
$CompanyName = $_POST['CompanyName'];|
$PhoneNumber = $_POST['PhoneNumber'];|
$email = $_POST['email'];|
$MessageUs = $_POST['MessageUs'];|
?>
Could you put it in back ticks? That makes it a lot easier to read.
edited with | to seperate code
Are there any errors in the logs?
Sorry, not sure how to check those
Click on tools, the click logs.
1 Like
SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at /opt/watcher/source/app-picker.ts:106:39
at ChildProcess.exithandler (child_process.js:285:7)
at ChildProcess.emit (events.js:189:13)
at ChildProcess.EventEmitter.emit (domain.js:441:20)
at maybeClose (internal/child_process.js:970:16)
[Fri Jun 5 16:18:05 2020] PHP Parse error: syntax error, unexpected ‘$name’ (T_VARIABLE) in /app/contactform.php on line 2
12:18 PM
[Fri Jun 5 16:18:05 2020] 127.0.0.1:55932 [500]: /contactform.php - syntax error, unexpected ‘$name’ (T_VARIABLE) in /app/contactform.php on line 2
at Socket.stream.socket.on (internal/child_process.js:389:11)
at Socket.emit (events.js:189:13)
at Socket.EventEmitter.emit (domain.js:441:20)
at Pipe._handle.close (net.js:597:12)
Do you have $name
defined?
yes in my html form:
<input type="text" name="name" autocomplete="off" required />
<label for="name" class="label-name"></label>
<span class="content-name">Name</span>
Did you mean $_POST['name']
I had it written like that in my php page I believe
I guess you could do this:
$name = $_POST['name'];
jrstokes73:
$name = $_POST[‘name’];
He did write that though @RiversideRocks
Thats right… Try this trick, run your code through an online PHP debugger, like this:
That site came back with this error:
PHP Syntax Check: Parse error: syntax error, unexpected ‘$name’ (T_VARIABLE) in your code on line 2
I think I realised what’s wrong.
You just put ( isset( $_POST['submit'] ) )
It needs to be:
if( isset( $_POST['submit'] ) ){
//Define your variables here
}
Edit: The PHP Code checker website returns no errors with that fixed
2 Likes
Ah good catch! I don’t use isset as much as I should, I use the lazy
if($_POST['submit'] == null){
// Nothing
}else{
// Something
}
When using PHP, i use isset all the time, but it always has to be inside an if statement. I should have realised before! Hope this helps @jrstokes73 !
Eddie
1 Like
I wish isset was a thing in nodejs/express. Would help out a lot!
1 Like
Is that really lazy - it looks like it would take longer to type
1 Like
EddiesTech:
if( isset( $_POS
nah just using shortcuts available to you
1 Like
@jrstokes73 If I fixed your issue, please mark my post as a ‘solution’ by pressing the button that says ‘solution’ below it. That means if people have the same issue can find the solution or people who want to help can see it has already been solved
2 Likes