Post: Using html code in php file
10-05-2015, 05:28 AM #1
Trefad
I defeated!
(adsbygoogle = window.adsbygoogle || []).push({}); So I've been trying to add a login and registration system to my website and I downloaded some scripts but then when I run the registration.php it shows the code only because the html is in the php but I don't think the php code works with the html if I make an html file and add the html code there. I'm not sure what to do.
(adsbygoogle = window.adsbygoogle || []).push({});
10-05-2015, 10:17 AM #2
Default Avatar
Oneup
Guest
Originally posted by Trefad View Post
So I've been trying to add a login and registration system to my website and I downloaded some scripts but then when I run the registration.php it shows the code only because the html is in the php but I don't think the php code works with the html if I make an html file and add the html code there. I'm not sure what to do.


Can you post the code you are using?
10-05-2015, 11:39 AM #3
Trefad
I defeated!
This is the register.php but theirs multiple files




<?php
session_start();
if(isset($_SESSION['user'])!="")
{
header("Location: home.php");
}
include_once 'dbconnect.php';

if(isset($_POST['btn-signup']))
{
$uname = mysql_real_escape_string($_POST['uname']);
$email = mysql_real_escape_string($_POST['email']);
$upass = md5(mysql_real_escape_string($_POST['pass']));

if(mysql_query("INSERT INTO users(username,email,password) VALUES('$uname','$email','$upass'Winky Winky"))
{
?>
<script>alert('successfully registered 'Winky Winky;</script>
<?php
}
else
{
?>
<script>alert('error while registering you...'Winky Winky;</script>
<?php
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login & Registration System</title>
<link rel="stylesheet" href="style.css" type="text/css" />

</head>
<body>
<center>
<div id="login-form">
<form method="post">
<table align="center" width="30%" border="0">
<tr>
<td><input type="text" name="uname" placeholder="User Name" required /></td>
</tr>
<tr>
<td><input type="email" name="email" placeholder="Your Email" required /></td>
</tr>
<tr>
<td><input type="password" name="pass" placeholder="Your Password" required /></td>
</tr>
<tr>
<td><button type="submit" name="btn-signup">Sign Me Up</button></td>
</tr>
<tr>
<td><a href="index.php">Sign In Here</a></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
10-05-2015, 02:16 PM #4
Trefad
I defeated!
Originally posted by 1UP View Post
Can you post the code you are using?


Posted it but didn't quote you.
10-05-2015, 08:12 PM #5
Specter
Pro Memer
Originally posted by Trefad View Post
Posted it but didn't quote you.


You can put HTML into php files, however you cannot put php into HTML files, so for most websites even if the pages don't use any php code, they'll use the .php file extension so that it's easier to add code in the future if need be. If your php file on your server is displaying the code rather than the webpage, then your configuration isn't setup properly as it's not being parsed properly.

A .PHP and a .HTML file are the exact same in terms of markup, you just throw the html code into the file and it'll work the same, what PHP allows is the use of <?php ?> tags which allow you to enclose php code inside those tags. So say you had a php code that had a variable that stored the name of a person and you wanted to output this name in a page, you'd put this in "index.php" (keep in mind this page is useless and serves no practical use):

    
<?php
$name = "John Doe";
?>
<p>Hi, this user's name is <b><?php echo $name; ?></b></p>


Note you can just use <? ?> iirc, you can omit the "php" from the tags. You can also just use {} instead of using the php tags, that's just the way I'd do it Smile
10-05-2015, 08:46 PM #6
Trefad
I defeated!
Originally posted by Specter View Post
You can put HTML into php files, however you cannot put php into HTML files, so for most websites even if the pages don't use any php code, they'll use the .php file extension so that it's easier to add code in the future if need be. If your php file on your server is displaying the code rather than the webpage, then your configuration isn't setup properly as it's not being parsed properly.

A .PHP and a .HTML file are the exact same in terms of markup, you just throw the html code into the file and it'll work the same, what PHP allows is the use of <?php ?> tags which allow you to enclose php code inside those tags. So say you had a php code that had a variable that stored the name of a person and you wanted to output this name in a page, you'd put this in "index.php" (keep in mind this page is useless and serves no practical use):

    
<?php
$name = "John Doe";
?>
<p>Hi, this user's name is <b><?php echo $name; ?></b></p>


Note you can just use <? ?> iirc, you can omit the "php" from the tags. You can also just use {} instead of using the php tags, that's just the way I'd do it Smile


Thanks! So the code shows, how would I parse it? And I used the html part in the php file and it showed the code too but the html part is also important to the design so how would I show it?
10-05-2015, 08:48 PM #7
Specter
Pro Memer
Originally posted by Trefad View Post
Thanks! So the code shows, how would I parse it? And I used the html part in the php file and it showed the code too but the html part is also important to the design so how would I show it?


Your nginx / apache2 configuration mustn't be setup properly, I might make a tutorial on setting up a basic web-server in a bit using nginx and such. The HTML should be working fine though.
10-05-2015, 09:26 PM #8
Trefad
I defeated!
ok thanks Smile
10-06-2015, 04:11 AM #9
Trefad
I defeated!
do you know if this also works? Its sql.
10-06-2015, 04:26 PM #10
Passion
League Champion
Originally posted by Trefad View Post
do you know if this also works? Its sql.


Yes it should work but you shouldn't use mysql_real_escape_string as it's not really secure. use PDO instead Happy

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo