below is my code where i am writing a code in php and calling it in body. When i run it and view source, the code gets visible. I have seen some site where nothing gets shown on source but a form appears on webpage. How can i do it too?
<?php
{ $avatar_form = '<form id="avatar_form" enctype="multipart/form-data" method="post" action="myphoto.php">';
$avatar_form .= '<h4>Change your avatar</h4>';
$avatar_form .= '<input type="file" name="avatar" required>';
$avatar_form .= '<p><input type="submit" value="Upload"></p>';
$avatar_form .= '</form>';
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Avatar</title>
</head>
<body>
<div><?php echo $avatar_form; ?></div>
</body>
</html>
Thanks
Shail
Why not write it in html? There should not be any code showing like that:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Avatar</title>
</head>
<body>
<div>
<form id="avatar_form" enctype="multipart/form-data" method="post" action="myphoto.php">
<h4>Change your avatar</h4>
<input type="file" name="avatar" required>
<p><input type="submit" value="Upload"></p>
</form>
</div>
</body>
</html>
just using php to echo html is sometimes not faster or useful then writing it directly in .html files.
Check whether the file type is .php or .html?
if html, it will show the php code.
If so, save it as .php
Related
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
Hello everyone first of all I have done a lot of research in the forum and other pages during these whole weekend before finally giving up and posting it.
Here is the code:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>El primer script</title>
</head>
<body>
<div id="wrapper">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<p>numero: <input type="text" name="number" /></p>
<p><input type="submit" value="start" /></p>
</form>
</div>
<?php
if(!isset($_SESSION['CREATED'])) {
session_start();
$_SESSION['aux'] = 1;
} else {
$_SESSION['aux'] = 0;
}
if(isset($_SESSION['CREATED'])){
var_dump($_SESSION['aux']);
}
?>
</body>
</html>
What I want to accomplish is that when I press the button (doesn’t matter if input is empty or not) it shows the number 1 but if I press again doesn't matter how many times it shows 0.
It is not working, it always shows 1, I don't think i managed to make the session work at all.
I might have mistaken the functionality of something rather than making a syntax error. I am beginning with php so if anyone can help if would be appreciated.
Whenever you use the global $_SESSION you have to declare session_start() at the very top of the page.
Try Using:
<?php session_start(); ?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>El primer script</title>
</head>
<body>
<div id="wrapper">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<p>numero: <input type="text" name="number" /></p>
<p><input type="submit" value="start" /></p>
</form>
</div>
<?php
if(!isset($_SESSION['CREATED'])) {
$_SESSION['aux'] = 1;
} else {
$_SESSION['aux'] = 0;
}
if($_SESSION['CREATED'])){
var_dump($_SESSION['aux']);
}
?>
</body>
I am trying to add reCAPTCHA to my php/html site. But it does not display. I have downloaded the library and set up my site so I have the public and private keys. I have created a basic page to try and get this working but still no luck. This is my php code:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once('lib/recaptchalib.php');
?>
<title>Test odds and ends</title>
</head>
<body>
<form method="post" action="">
<?php
$publickey = "~hidden~";
echo recaptcha_get_html($publickey);
?>
</form>
</body>
</html>
The page displays completely blank. The html produced is:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test odds and ends</title>
</head>
<body>
<form method="post" action="">
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=~hidden~">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=~hidden~" height="300" width="500" frameborder="0">
</iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>
</form>
</body>
</html>
Does anyone know why this doesn't work? Many thanks in advance.
i have two pages.When i click link on first page, it fill text field on second page(get value from 'from' ).
my first page codes abc.php :
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><strong>From</strong> <strong> Subject</strong> <strong>Reply</strong></p>
<p>biri deneme girdi click</p>
</body>
</html>
and this is second page kum.php :
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="hum" id="hum" />
</label>
</form>
</body>
</html>
What should i do?
you can get the url where the user comes from with $_SERVER['HTTP_REFERER'];
<input type="text" name="hum" id="hum"<?php if ($_SERVER['HTTP_REFERER'] == "http://examplepage.com/start/"){?> value="hi" <?php } ?>
/>
(not tested, just to give you a idea how you could use it)
I made a pop-up window that has a submit form and upon submission it must close but i first want to process the information from the pop-up window in a different page without displaying that other page. How can I do it?
my popupwindow contains this code
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function closeSelf(){
self.close();
return true;
}
</script>
<title>Add Activity</title>
</head>
<body>
<form action="./addact.php" method="post" onsubmit ="return closeSelf()">
<table width="500" border="1"><br/>
<tr>
<td>Activity Name</td>
<td>Assigned Person</td>
<td>Deadline</td>
</tr>
<tr>
<td> <input name="activities" type="text" size="40%"/></td>
<td><input name="name" type="text" size="40%"/></td>
<td><input type="date" name="deadline" size="20%"/></td>
</tr>
</table>
<input type="submit" name = "saved" id="saved"/>
</form>
</body>
</html>
and my other page contains this
<?php session_start(); ?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
include('config.php');
$actname= $_POST['activities'];
$assigned = $_POST['name'];
$deadline = $_POST ['deadline'];
$sql = "INSERT INTO ".$_SESSION['pname']."_activities
(actname, assigned, deadline)
VALUES
('$actname', '$assigned', '$deadline')
";
$query = mysql_query($sql);
echo $_SESSION['pname'];
?>
<body>
</body>
</html>
You should close the window when the response is returned, not when you submit the page. And as #Marc B pointed out, you have major security problem!
If i give textbox type as number and submit a form it cut off 0 .
ex: 099921 means it will post as 99921
why it cut off preceding 0
Because 0 in front means nothing and is removed. Make it a string (text) and it will stay. Ints have no 0 in front.
i dont know why but i did the same code and it is displaying the value with o i.e 099921
check out my code
<?php
if(isset($_POST['submit']))
{
echo $numberValue = $_POST['numVal'];
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<input type="number" name="numVal" value="" />
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html