[TC] Gaming Forums
php coding - Printable Version

+- [TC] Gaming Forums (https://forum.city-driving.co.uk)
+-- Forum: Community Area (/forumdisplay.php?fid=14)
+--- Forum: Technology Area (/forumdisplay.php?fid=82)
+---- Forum: Tech Support (/forumdisplay.php?fid=85)
+---- Thread: php coding (/showthread.php?tid=11324)



php coding - Raz! - 2014-03-19 20:49

I have a problem with my php code, if anyone can figure it out, it would be highly appreciated!

Parse error: syntax error, unexpected '<' in C:\wamp\www\register.php on line 9

Code:
<?php
require('config.php');

if(isset($_POST['submit'])){

}else{

$form =
<form action="register.php" method="POST">    <<<<<--------THIS LINE
First Name: <input type="text" name="name" /><br />
Last Name: <input type="text" name="name" /><br />
Username: <input type="text" name="username" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="password" name="password1" /><br />
Confirm Email: <input type="password" name="password2" /><br />
<input type="submit" value="Register" name="Submit" />
</form>
EOT;

echo $form;

}
?>



RE: php coding - Dan - 2014-03-19 21:58

If you read the error, it says that you've placed a chevron on line nine that shouldn't be there. Looking at your code, you haven't opened (nor closed for that matter) the variable you're defining. So it'd need to be changed to $form = 'your form here';

I've used single apostrophes because you've included a form, where if you use speech marks, you'll keep opening and closing the variable.


RE: php coding - Pete - 2014-03-20 00:29

Unless you want to escape all of your quote marks (which you would need to do) I would recommend the following:

For this example I would consider putting the following code in a separate file called "form.php":

form.php

Code:
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br />
Last Name: <input type="text" name="name" /><br />
Username: <input type="text" name="username" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="password" name="password1" /><br />
Confirm Email: <input type="password" name="password2" /><br />
<input type="submit" value="Register" name="Submit" />
</form>

and from your main file call an include or require for the form HTML:

Code:
<?php
require('config.php');

if(isset($_POST['submit'])){

}else{

include('form.php');

}
?>

It will make your code a lot cleaner. Getting away from echoes is a good thing.


RE: php coding - Raz! - 2014-03-20 15:43

(2014-03-20 00:29)Pete Wrote:  Unless you want to escape all of your quote marks (which you would need to do) I would recommend the following:

For this example I would consider putting the following code in a separate file called "form.php":

form.php

Code:
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br />
Last Name: <input type="text" name="name" /><br />
Username: <input type="text" name="username" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="password" name="password1" /><br />
Confirm Email: <input type="password" name="password2" /><br />
<input type="submit" value="Register" name="Submit" />
</form>

and from your main file call an include or require for the form HTML:

Code:
<?php
require('config.php');

if(isset($_POST['submit'])){

}else{

include('form.php');

}
?>

It will make your code a lot cleaner. Getting away from echoes is a good thing.

Thanks very much, this works extremely well. Thanks All!