I'm starting to try to learn PHP while using Expression Web 3. I set up PHP runtime and configured the ini. What happens is my script doesn't do as it should.
My page looks like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<title>Sports</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="master.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
</head>
<body>
<div id="masthead">
</div>
<div id="top_nav">
<ul>
<li>Sports </li>
<li>Clubs</li>
<li>Cloud</li>
</ul>
</div>
<div id="container">
<div id="left_col">
</div>
<div id="page_content">
</div>
</div>
<div id="footer">
<form method="post">
</form>
</div>
<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>
Then my PHP file looks like:
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>action</title>
</head>
<body>
Hi <?php echo htmlspecialchars($_POST['name']); ?>.
You are <?php echo (int)$_POST['age']; ?> years old.
</body>
</html>
What should happen is for example if I type John as name and 50 as age, it should output Hi John, you are 50 years old.
But instead it says (with Firefox) :
Hi you are years old
in Internet Explorer 8, it just outputs the whole php script.
I'm not sure where I went wrong.
Thanks
Either you are not running these files from a PHP enabled webserver or the webserver is not configured to serve the used file extension as PHP. How to install and configure a webserver is best asked on ServerFault.com. Have a look at XAMP or Zend Server CE.
In addition, you have a terribly low acceptance rate. Why not go back to some previous questions and you asked and accept some of the answers you have been given?
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>
Since yesterday slideshare API for upload slideshow using PHP didn't work.
We receive only 500 response (check below).
We accessed endpoint: https://www.slideshare.net/api/2/upload_slideshow
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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"/>
<link href="/stylesheets/error.css" type="text/css" rel="stylesheet" media="screen" />
<script type="text/javascript">
function disableSearch(event) {
var t = document.getElementById('searchstring');
if(t.value === 'Type text here …' || t.value.length === 0) {
event.preventDefault();
}
}
</script>
<title>500 error. The page could not be loaded.</title>
</head>
<body>
<div class="smiley"><img src="/images/errorsmiley.png" width="128px" height="128px" alt="error" /></div>
<div class="errorBox">
<p class="errorCode">500</p>
<h1>Sorry! The page could not be loaded.</h1>
<h2>
This is probably a temporary error. Just refresh the page and retry. If problem continues, please check back in 5-10 minutes.
<br/><br/>You could also check out our homepage or search below.</h2>
<div class="searchSection">
<form style="display: inline;" action="/search/slideshow" method="get">
<input type="text" id="searchstring" name="q" value="Type text here …" class="errorSearchBox" onclick="this.value = '';">
<button type="submit" onclick="disableSearch(event)">
Search<span> </span></button>
</form>
</div>
</div>
</body>
</html>
I am writing a PHP script where I take input from user like server IP and one more input.
After this is available, I make ssh call to the server and execute some command. I want to show the output on the web page but i gets error as 500 (server error).
Here is my main script where i get input from user:
<!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>Centos Health Checker</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="login-form">
<form method="post" action="redirectPage.php">
<table align="center" width="30%" border="0">
<tr>
<td><input type="text" name="IP" placeholder="System IP" required /></td>
</tr>
<tr>
<td><input type="text" name="Component" placeholder="Component" required /></td>
</tr>
<tr>
<td><button type="submit" name="submit">Check System</button></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
Here is my landing page:
<?php
function Connect()
{
include('/home/as5714/php_data/Net/SSH2.php');
$IP1 = $_POST['IP'];
$Component1 = $_POST['Component'];
$ssh = new Net_SSH2($IP1);
if (!$ssh->login('centos', 'centos')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
}
if(isset($_POST['submit']))
{
Connect();
}
?>
<!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>Welcome - <?php echo $IP1; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<div id="left">
<label>cleartuts</label>
</div>
<div id="right">
<div id="content">
Cennecting to ' <?php echo $IP1; ?> and Data is : <?php echo $data2; ?> Go Back
</div>
</div>
</div>
</body>
</html>
I am getting server error(500) while using above php code.
Please note that I am working on vim editor on a linux server for the script and do not have any logs available. Also, If I just run the program to do ssh connection and execution of command in server directly (php 123.php), I get proper data on console.
Please help.
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.
how to input a number range, from 2 text fields, this is my code is seems to be not working, the range function i want it to be inserted to mysql database but this code is just to test if i can get the 2 textfields to connect to the range function. anyone can help me solve this problem?
<?php
$from = '.from';
$to = '.to';
$number = range('$from','$to');
print_r ($number);
?>
<!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>New Waybill</title>
<link rel="shortcut icon" href="../img/icon.ico">
<link rel="stylesheet" type="text/css" href="../css/forms.css" />
</head>
<body>
<form id="form3" name="form1" method="post" action="">
<p>From:
<input type="text" name="from" id="form_number" class="from" value="0"/>
- To:
<input type="text" name="to" id="form_number" class="to" value="50" />
</p>
<p>Waybill Booklet:
<select name="waybill_booklet" id="form_list">
</select>
</p>
<p>
<input type="submit" name="button" id="form_button" value="OK!" />
</p>
</form>
</body>
</html>
Replace your php code with this:
<?php
if (!empty($_POST)) {
$from = $_POST['from'];
$to = $_POST['to'];
$number = range($from,$to);
print_r($number);
}
?>
To access a form post in PHP you use the $_POST superglobal. More info found here: http://www.php.net/manual/en/reserved.variables.post.php.
I've put a check to see if it's empty or not at the start, so when the page first loads it won't attempt to run the PHP code. Presumably you'll then replace the print_r with whatever you need to insert the data into your database.