Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
It throws me a syntax error, unexpected T_STRING, and I don't see anything wrong with it.
<div id="main">
<div id="wrap">
<?php
require("top.php");
$archpreg=fopen("p.txt", 'a+');
$archresp=fopen("r.txt", 'a+');
$preg=fread($archpreg,filesize("p.txt"));
$resp=fread($archresp,filesize("r.txt));
fclose($archpreg); fclose($archresp);
$listapreg= explode('###12', $preg); $listar= explode('###12', $resp);
for ($c=9; $c>=0; --$c){
$p=array_pop($listapreg);
$pp= explode ('###11',$p);
$nombre= $pp[1];
$apellido=$pp[2];
$foto= base64_decode ($pp[3]);
$id=$pp[0];
$pregunta= $pp[5];
$titulo= $pp[4];
for ($i=0; $i<count($listar); ++$i){
$r=$array_pop($listar);
$rr=explode ('###11',$r);
#if($rr[0]==$id){
# $nombre2=$rr[1];
# $apellido2=$rr[2];
# $respuesta=$rr[3];
#} ?>
<div>
<h4><?php echo $titulo?></h4>
<h5>Escrita por: <?php echo $nombre.' '.$apellido; >?> </h5>
<p>
<?php echo $pregunta ?>
<form method="get" action= "iresp.php">
<input type="submit" value="Responder!" id="responder"/>
<input type="hidden" name="id" value="aaa" />
</form>
</p>
<p>
<?php echo $respuesta ?>
</p>
</div>
<?php }
} ?>
</div>
</div>
</body>
</html>
The line $resp=fread($archresp,filesize("r.txt)); is missing a ", it should be $resp=fread($archresp,filesize("r.txt")); or better yet $resp=fread($archresp,filesize('r.txt')); since there is no variable substitution in the string.
$resp=fread($archresp,filesize("r.txt));
You have missed " sign ;)
You are missing some " in this line: $resp=fread($archresp,filesize("r.txt));
$resp=fread($archresp,filesize("r.txt));
There is a missing ". You should use an editor with syntax highlighting!
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to do a simple thing, create a login page that shows successful login and logoff messages, but it always shows the successful login message ("Logado com sucesso"). My hosting is Hostinger. Here is my code:
<?php
require_once('db.php');
session_start();
if(isset($_POST['action'])){
if($_POST['action'] = 'login'){
$_SESSION['login'] = $_POST['login'];
$msg = 'Logado com sucesso!';
} elseif($_POST['action'] = 'logoff') {
$msg = 'Deslogado com sucesso!';
unset($_SESSION['login']);
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<div id="container">
<form method="POST">
<? if(!$_SESSION['login']){ ?>
<h3>Preencha os seus dados abaixo</h3>
<input type="hidden" name="action" value="login">
<input type="text" required name="login" placeholder="Nome de usuário">
<input type="password" required name="senha" placeholder="Senha">
<input type="submit" value="Entrar">
<? } else { ?>
<h3>Você está logado como</h3>
<input type="hidden" name="action" value="logoff">
<input type="text" required name="login" disabled value="<?=$_SESSION['login']?>">
<input type="submit" value="Sair">
<? } ?>
<? if(isset($msg)){ ?>
<div id="msg"><? echo $msg?></div>
<?} ?>
</form>
</div>
</body>
</html>
Your if statements are performing assignment and not a comparison.
For example
if($_POST['action'] = 'login')
is assigning $_POST['action'] = 'login' and will always be TRUE.
You need == so that would become
if($_POST['action'] == 'login')
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
<?php
session_start();
?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="pageContainer">
<form action="second.php" class="formLayout" method="post">
<div class="formGroup">
<label>Name:</label>
<input type="text" name="first_name"><br>
<input type="hidden" name="postback" value="true"><br>
</div>
<div class="formGroup">
<label> Car model:</label>
<div class="formElements">
<input type="radio" name="model" value="Mustang">Ford Mustang<br>
<input type="radio" name="model" value="Subaru">Subaru WRX STI<br>
<input type="radio" name="model" value="Corvette">Corvette<br>
</div>
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
$_SESSION["first_name"] = $_POST["first_name"];
$_SESSION["model"] = $_POST["model"];
}
?>
</div>
</body>
</html>
I set up my code to set the value of the "first_name" and "model" names into my session variables.
When I try to access the values of the stored variables in the submission page of the form:
<?php
session_start();
?>
<html>
<body>
<?php
echo $_SESSION["first_name"];
echo $_SESSION["model"];
?>
</body>
</html>
I only receive the out of the model value, not the first_name value. I don't understand what I'm doing wrong here.
Let's assume your first file is called first.php. As shown in your <form>, the second one is second.php.
It seems that you are writing the data into the session in the first.php file, but this code will never run because you are submitting your form to second.php and not first.php!
So, move the code that writes the session variables into second.php instead. To test that it really worked, you can create a third.php to display them.
(I'm not sure why see the model set, but I guess it's still there from a previous test you did.)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
when i'm trying to run my code i come across a blank site and i don't know how to fix it
i guess my calculations aren't working
here's the codes:
<html>
<head>
<meta charset="utf-8">
<title>Kalkulator spalania paliwa</title>
</head>
<body align="center">
<h1>Kalkulator spalania paliwa.</h1><br>
<form action="get_info.php" method="get">
Podaj spalone paliwo: <input type="text" name="sp"> l<br>
Podaj przejechaną odległość: <input type="text" name="km"> km<br>
<input type="submit">
</form>
</body>
and
<html>
<body>
<?php
function spalanie(){
$sp = $_GET["sp"];
$km = $_GET["km"];
$wynik = $sp * 100 / $km;
echo $wynik;
}
?>
</body>
You have defined the function but haven't called it. Call it like this below the function like
spalanie();
beacause your input tag has no value...
<input type="text" name="km" value="km">
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
with this example I recap my problem:
The first time I execute this php page I want to echo "I have two buttons".When the user click buttons "next" or "next1" I want to echo "I already said I have two buttons" and not "I have to buttons" again.I proved also with hidden input text but it doesn't work. thk for help
<?php
if ($_SESSION['already_said'] == false ){
echo "I have two buttons". date('h:i:s')."<br>";
}
$_SESSION['already_said']=true;
if( isset($_GET["next"]) || isset($_GET["next1"])) {
echo "I already said I have two buttons". date('h:i:s')."<br>";
}
?>
<html>
<body>
<form name="form" method="GET" action="" >
<button type="submit" name="next">
<span class="label">Next</span>
</button>
<button type="submit" name="next1">
<span class="label">Next1</span>
</button>
</form>
</body>
</html>
Of course the important thing is to remember to put the session_start() at the top of any script that uses the session. In fact it is a good idea to put it in all your scripts even if a few dont use the session just to keep the session alive.
<?php
session_start();
$msg = "I have two buttons ". date('h:i:s')."<br>";
if (! isset($_SESSION['already_said']) ){
$_SESSION['already_said'] = true;
}
if( (isset($_GET["next"]) || isset($_GET["next1"]) ) && isset($_SESSION['already_said'])) {
$msg = "I already said " . $msg;
}
?>
<html>
<body>
<div> <?php echo $msg; ?></div>
<form name="form" method="GET" action="" >
<button type="submit" name="next">
<span class="label">Next</span>
</button>
<button type="submit" name="next1">
<span class="label">Next1</span>
</button>
</form>
</body>
</html>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have an HTML Form and I am trying to get the values from the form in my php file.
<div id="qForm">
<form action="postComment.php" method="post" name="comment">
Name: <input type="text" name="askerName"><br>
Title: <input type="text" name="qTitle"><br>
<textarea maxlength="255" name="theQ"></textarea>
<input type="submit">
</form>
</div>
My PHP file looks like this but It echos as Welcome
<?php
$name = $_POST["askerName"];
echo $name; //this works
$textArea = $_POST["theQ"];
echo $textArea; //this does not work
?>
<html>
<head>
</head>
<body>
welcome <?php $_POST["askerName"]; ?>
</body>
</html>
Use
<body>
welcome <?php echo $_POST["askerName"]; ?>
</body>
instead.
you have to use print/echo to display your php output these two basic ways to get output: echo and print
<body>
welcome <?php print $_POST["askerName"]; ?>
</body>
else
<body>
welcome <?php echo $_POST["askerName"]; ?>
</body>
echo is marginally faster compared to print as echo does not return any value