PHP code if not working [closed] - php

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 6 years ago.
Improve this question
i have a problem
My code is
if(isset($_SESSION["steamid"]))
{
echo' <button type="button" name="use_button" class="btn btn-warning">Login trough steam</button>';
}else{
echo'<form method="POST" action='givadd.php'><button type="submit" name="use_button" class="btn btn-success">Participate</button></form>';
}
But somehow it dosent work and page is blank. Maybe someone can help me. thank you.

The Problem is that you used
echo '... action='....' ...';
Instead of
echo '... action="...." ...';

HTML attributes require double quotes " to have their arguments passed, I've corrected this in your form action='' to become action="".
You could try it like this, it would also help you to maintain HTML.
if(isset($_SESSION["steamid"])) { ?>
<a href="?login">
<button type="button" name="use_button" class="btn btn-warning">
Login trough steam
</button>
</a>
<?php } else { ?>
<form method="POST" action="givadd.php">
<button type="submit" name="use_button" class="btn btn-success">
Participate
</button>
</form>
<?php }
/// Continue your script here...

Related

Ajax return php value with html [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I'm new to programming and started land job only 1 month, have no idea how to solve these issues
1: I would like to ask how can I insert php value into location.href with quotes?
2: Why my button is unclickable even though I leave send?phone= to blank?
"<button type='button' style='height:50%;'
onclick='location.href=https://api.whatsapp.com/send?phone={$num}'>
<i class='fa fa-whatsapp'></i>ere</button>"
//If the button is in HTML
<button type='button' style='height:50%;' onclick='location.href=https://api.whatsapp.com/send?phone=<?php echo $num; ?>'><i class='fa fa-whatsapp'></i>ere</button>
//If you want the button in php
echo "<button type='button' style='height:50%;' onclick='location.href=\"https://api.whatsapp.com/send?phone={$num}\"'><i class='fa fa-whatsapp'></i>ere</button>";
Your button should be like this.
<button type="button"
onclick="location.href='https://api.whatsapp.com/send?phone={$num}'">
<i class="fa fa-whatsapp"></i>ere</button>

Sleep() doesn't delay on form action [closed]

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 click on the submit button, I want a delay of 3 seconds and then a redirect.
My form will redirect to an other PHP site.
My code:
<button
class="button actionContinue scTrack:unifiedlogin-login-submit"
type="submit"
id="btnLogin"
name="btnLogin"
value="Login"
pa-marked="1">
Einloggen
</button>
</div></div>
<input type="hidden" name="" value="">
</form>
<?php
if (isset($_POST['submit']))
{
sleep(3);
// AND NOW action;
}
?>
Example
<?php
if (isset($_POST['submit']))
{
sleep(3);
// AND NOW action;
redirect('Location:next page.php');
}
?>
Why is it not working?
So the basic debugging in the comments shows that the $_POST['submit'] value which you expected to be there is actually not present. This is why your sleep is not working as the condition in your IF is not true.
So the next step is debug why you don't have that POST data. Which is because you don't have that as a form element. You will have btnLogin because that is the name you provided in your button.
name="btnLogin"
You can either test for the name you currently have:
isset($_POST['btnLogin']))
Or change the name in your button to Submit:
<button
class="button actionContinue scTrack:unifiedlogin-login-submit"
type="submit"
id="btnLogin"
name="Submit"
value="Login"
pa-marked="1">
Einloggen
</button>
EDIT: Try this as per your request in comments:
<?php
if (isset($_POST['btnLogin']))
{
sleep(3);
redirect('Location:next page.php');
}
?>

How to stop php from opening a new tab in browser when submitting a from [closed]

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
I am new to php and I'm trying to have a form in which you have to input two numbers which are added to each other when submitted.
It works just fine, but whenever I click submit it opens a new tab in my browser (tested in chrome and firefox) to show to anwser, which I don't want.
I write the php code in the same file as my html.
Can anyone help me?
Thank you!
<!DOCTYPE html>
<form target="/index.php" method="GET">
<input type="number" name="num1">
<input type="number" name="num2">
<input type="submit">
</form>
<p>anwser:</p>
<?php
echo $_GET["num1"] + $_GET["num2"];
?>
php has nothing to do with new window or not...
its your target what does it... it opens a new window with internal name "/index.php"
what you are looking for is action="/index.php"
<form action="/index.php" method="GET">
<input type="number" name="num1">
<input type="number" name="num2">
<input type="submit">
</form>
<p>anwser:</p>
<?php
echo $_GET["num1"] + $_GET["num2"];
?>

Why is unwanted script appearing in webpage? [closed]

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
I have written a HTML and PHP code which should show a survey form and invite you to enter your email address and have a submit button for you to click. However, when I "run" the code, I get some gibberish which I wrote in my code, which I did not expect to appear on my survey form. The code that I have written is as follows:
session_start();
if (!empty($_POST['posted']) && !empty($_POST['email'])){
$folder = "surveys/" . strtolower($_POST['email']);
// send path information to the session
$_SESSION['folder'] = $folder;
if(!file_exists($folder)) {
// make the directory and then add the empty files
mkdir($folder, 0777, true);
}
header("Location: 08_6.php");
}
else { ?>
<html>
<head>
<title>Files and folders - Online Survey</title>
</head>
<body bgcolor="white" text="black">
<h2>Survey Form</h2>
<p>Please enter your email address to start recording your comments</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="posted" value="1">
<p>Email address: <input type="text" name="email" size="45" /><br />
<input type="submit" name="submit" value="Submit"></p>
</form>
</body>
</html>
<?php }
What's happening is that I'm getting:
session_start(); if (!empty($_POST['posted']) && !empty($_POST['email'])){...
and whole bunch of other stuff appearing at the top of the webpage, which is certainly not what I want. Could one of you experts please tell me what I'm doing wrong?
You have not included an opening <?php tag in your page.

html button appearing as input box on form [closed]

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
I Apologize for the simplicity of the question, still learning the ropes.
I have the following code:
<form action="backyard_funcs.php" method="post" id="register-form">
<input "type="submit" id="register-submit" name="register-submit" value="Create Account" />
</form>
My objective is to have a form that is submitted at the push of the button named register-submit. However it is not appearing as a button, instead it is appearing as an input box.
All help is appreciated. Thanks in advance.
This is wrong:
"type="submit"
it should be
type="submit"
otherwise you break parsing of that input and default type it then falls back to is text
Try using a code editor like
sublimetext : http://www.sublimetext.com/3
it'll help you color any coding errors later on so easily! :)
Here's the right code for your answer:
<form action="backyard_funcs.php" method="post" id="register-form">
<button type="submit id="register-submit" name="register-submit">Create Account</button>
</form>
Hope this helps!
<input "type="submit" id=....
should be
<input type="submit" id=....
without the quote before type
There is an ( " ) too much in your code
<form action="backyard_funcs.php" method="post" id="register-form">
<input type="submit" id="register-submit" name="register-submit" value="Create Account" />
</form>

Categories