Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Software/Applications: Notepad++ 6.5, Google Chrome Version 26.0.1410.64 m
I copied a code online just to test on how forms work so I can map it on my real page.
But even I tried the online example code it still doesnt work in my end. Can pls someone tell me what's the reason behind this?
copypaste.php
<html><body>
<form action="DesignPageProcess.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" value="submit" name="submit" /></p>
</form>
</body></html>
DesignPageProcess.php
<html><body>
<?php
if ($_POST['submit'] == "submit")
{
$name = $_POST['name'];
echo "asd".$name.;
// - - - snip - - -
}
?>
</body></html>
It returns a blank page.
Remove the extra .
<html><body>
<?php
if($_POST['submit'] == "submit")
{
$name = $_POST['name'];
echo "asd".$name; //Removed the extra . on this line
// - - - snip - - -
}
?>
</body></html>
Try:
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "asd".$name;
// - - - snip - - -
}
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 5 years ago.
Improve this question
I wrote a code such that if I fill all fields of form and I submit then I should get "Ok"
and if I left the form blank then I should get "Please fill all fields".
I am not getting any errors so I am confused how to proceed .
<?php
if(isset($_POST['submit_text']) && isset($_POST['find_word']) && isset($_POST['replaced_word'])){
$sub_text = $_POST['submit_text'];
$fin_text = $_POST['find_word'];
$rep_text = $_POST['replace_word'];
if(!empty($sub_text )&& !empty($fin_text) && !empty($rep_text)){
echo "Ok.";
}else{
echo "Please fill all fields.";
}
}
?>
<html>
<head>
</head>
<body>
<form id="myForm" name="myForm" action="index.php" method="post" >
<p>
Submit Text<br/>
<textarea rows="5" cols="40" type="text" id="submit_text" name="submit_text" ></textarea>
</p>
<p>
Find<br/>
<input id="find_word" name="find_word" type="text" />
</p>
<p>
Replace<br/>
<input id="replace_word" name="replace_word" type="text" />
</p>
<input id="submit" name="submit" type="submit" value="Submit" />
</form>
</body>
</html>
For any query please comment below.
you have missed few characters here
isset($_POST['replaced_word'])
you have to use same name you use in input field.like this
isset($_POST['replace_word'])
Your first "if" needs an "else", I think it would trigger that in your scenario.
I generally try separating these, and do not put them into one large IF..
for example, I would do an if isset and else on each one separately, converting to a different variable accordingly before doing the rest of the logic.
In the first if, you wrote "replaced_word", but the name of the input tag is "replace_word" without the "d". So $_POST['replaced_word'] is never set so that's why it's not working.
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
From the HTML page I am submitting some records to a PHP page, where the records will be saved to the DB and then show a
message saved successfully
message to the user on the same HTML page.
When i submit my form, the records are sent to the HTML page and it displays the success message on another page and not on the same HTML page (where the form code is written). How can i correct it?
HTML
<form action="save.php" class="tsc_form_contact_dark nolabel" method="POST">
<input type="text" name="name" class="form-input" placeholder="Name (required)" required />
<input type="email" name="email" class="form-input" placeholder="Email (required)" required />
<input class="form-btn" type="submit" value="Send Message" />
</form>
PHP
<?php
$name = $_POST["name"];
$email = $_POST["email"];
// Do other stuff
echo "Success";
?>
All you need to do is set a message variable. Something like this:
$msg=isset($_GET['msg']) ? $_GET['msg'] : "";
<div><?php echo $msg; ?></div>
<form action="save.php" class="tsc_form_contact_dark nolabel" method="POST">
//rest of the form
And in the php, you need to redirect to the form page something likt this:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
// Do other stuff
$msg = "Success";
$redirecturl = "form_page.php?msg=".$msg;
header("Location: $redirecturl");
?>
There could be other methods to send result message using session, but I would recommend not doing that.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Im just learning and....
It just wont connect is there something stupid that im doing wrong?
Add.php
<?php
mysql_connect("db517452461.db.1and1.com","dbo517452461","******") or die
(mysql_error());
echo "Oops ";
mysql_select_db("admin") or die (mysql_error());
echo "Ooops ";
$ref= ($_POST['ref']);
$firstname = ($_POST['firstname']);
mysql_query("insert admin set ref='".$ref."', firstname='".$firstname."'");
echo "<script>alert('Record successfuly saved.');window.location.href='paragview.php';
</script>";
?>
index.php
<html>
<body>
<div style="border:1px solid;">
<form action="add.php" method="post">
Ref: <input type="text" name="ref"><br>
Firstname <input type="text" name="firstname"><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</div>
</body>
</html>
Ive checked my host, username and password over and over again.
SShttp://i.cubeupload.com/FTYOhp.jpg
Your database name is something else rather than the one mentioned in the image.
Change this line:
mysql_select_db("admin") or die(mysql_error());
To:
mysql_select_db("db517452461") or die(mysql_error());
As a side note, I recommend you to use mysqli or PDO as mysql is now deprecated.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
$redirect=$_GET["r"];
if ( isset($_GET["r"]) ){
header("location: http://" .$redirect);
} else {
$redirect = "mickiewiki.nl/login/profile.php";
header("location: http://" .$redirect);
this code won't work? I want it to be like if I go to mickiewiki.nl/login/login.php?r=mickiewiki.nl/Doneer.php that when I login I go back to the page Doneer.php
When I login, I am always being sent to profile.php no matter if I add my r or not
<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$database = mysql_select_db('***', $con) or die(mysql_error());
//include out functions file giving us access to the protect() function made earlier
include "login/functions.php";
$selectedid = $_GET['id'];
if(empty($selectedid)) {
$selectedid = $_SESSION['uid'];
}
if(strcmp($_SESSION['uid'],"") == 0){
header("location: login/login.php?r=mickiewiki.nl/Doneer.php");
} else {
?>
In your form on your website, you are not setting r through GET. You have username, password & submit for your form - and nothing for GET. If you are submitting r with your form (which I cannot see that you are), then you should probably be checking for $_POST['r'] instead of $_GET['r'].
Basically, you need to add a hidden field for your r variable and submit that along with your form.
<form method="post" action="login.php">
<input type="hidden" name="r" value="<?php print $_GET['r']; ?>">
<p><label for="name">Username: </label>
<input type="text" name="username" /></p>
<p><label for="pwd">Password: </label>
<input type="password" name="password" /></p>
<p>
<input type="submit" id="submit" value="Login" name="submit" />
</form>
but, you must do a control for $_GET["r"] ... and why it doesn't work?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
In the following code, everything works except that when you click the submit button, nothing happens at all
Please tell me what's wrong, the connection and everything is fine (it is included in the Header.php file) and submit forms on other pages work, but this one seems to just do nothing, page doesn't even load
Thanks!
Here is the code
<?php
//connection is in header
include "../Header.php";
//checks if logged in
if (!$User)
{
header("Location: ../index.php"); exit();
}
//heres the form
echo"<form><center><br /><br /><br /><br /><font size='3'><br />You are changing your Post Color<br />
Your current color is $myU->PostColor<br /><br /></font><form>
Color:<br /><textarea name='color' rows='1' cols='15'></textarea><br /><br />
<input type='submit' name='Submit' value='submit'></form></center></form>";
$Color = mysql_real_escape_string(strip_tags($_POST['Color']));
$submit = mysql_real_escape_string(strip_tags($_POST['submit']));
if ($submit) {
mysqli_query("UPDATE `socialli_main`.`Users` SET `PostColor` = '$Color' WHERE `Users`.`ID` ='$myU->ID'");
header("Location: ../index.php"); exit();
}
include "../Footer.php";
A submit button will submit the form that it is inside. You don't have a <form> element at all. You need to add one.
More importantly than adding a <form> tag is actually setting attributes on it. Try the following.
<form action='' method='POST'>
And you also end your </form> tag many times...
Here is how I would fix up your code anyways:
<?php
//connection is in header
include "../Header.php";
//checks if logged in
if (!$User)
header("Location: ../index.php"); exit();
?>
<form action='' method='POST'>
<div style="text-align:center;">
<br /><br /><br /><br /><br />
<span style="font-size:1.6em;">
You are changing your Post Color
</span><br>
<span style="font-size:1.3em;">
Your current color is <?=$myU->PostColor?>
</span><br>
Color:<br />
<textarea name='color' rows='1' cols='15'></textarea>
<br /><br />
<input type='submit' name='Submit' value='submit'>
</div>
</form>
<?php
$Color = mysql_real_escape_string(strip_tags($_POST['Color']));
$submit = mysql_real_escape_string(strip_tags($_POST['submit']));
if ($submit){
mysqli_query("UPDATE `socialli_main`.`Users` SET `PostColor` = '$Color' WHERE `Users`.`ID` ='$myU->ID'");
header("Location: ../index.php"); exit();
}
include "../Footer.php";
?>