How do I echo submitted values from settings.php to mainpage.php? - php

I'm basically trying to get the values submitted from settings so that when the user submits it, it is displayed onto mainpage.php. Here's the code from what I have in settings.php...
<html>
<head><title></title></head>
<body>
Logout
Main Page
<form action="" method="get">
<b>Bio</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="bio">
</form>
<form action="" method="get">
<b>Hobbies</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="hobbies">
</form>
<form action="" method="get">
<b>Past School</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="school">
</form>
<form action="" method="get">
<b>Work History</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="work">
</form>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Choose Profile Picture:</label>
<input type="file" name="file" id="file">
<input type="submit" name="pic" value="Submit">
</form>
</body>
</html>
And this is what I have for mainpage.php
<?php
?>
<html>
<head><title></title></head>
<body>
Logout
Settings
</body>
</html>
Any suggestions?

As Jenna R said, it is better to use POST, not GET.
Then each variable is referenced with $_POST["name"], so $_POST["result"] and so on.
I suggest you start reading up on PHP and submitting forms securely if you are doing this for anything other than learning. This is pretty basic, so it looks like you haven't opened up the manual or a book just yet.

Related

Call the upload file

In html I have an upload button for a photo:
<p>
<input type="file" name="datafile" size="40">
</p>
<br>
<p>
<input type="submit" name="submit" id="submit" value="submit" />
</p>
After that I want to take the results using the echo and insert the result in a table in the center of page.
I made this but it is not working properly. Any suggestion?
<table align="center">
<tr>
<?php echo $_POST['datafile']; ?>
</tr>
</table>
Your code should be
<?php
if(isset($_POST['submit'])){
print_r($_FILES); // you will get your data in $_FILES variable.
}
?>
<form action="file_upload.php" method="post" enctype="multipart/form-data">
<p>
<input type="file" name="datafile" size="40">
</p>
<br>
<p>
<input type="submit" name="submit" id="submit" value="submit" />
</p>
</form>
You should have enctype="multipart/form-data in your form tag
<form action="upload.php" method="post" enctype="multipart/form-data">
And get the uploaded file via $_FILES: http://www.w3schools.com/php/php_file_upload.asp
$_FILES['datafile']
Read more here http://www.w3schools.com/php/php_file_upload.asp

how to add another form in current form in codeigniter?

form.php
<html>
<head>
<title>Welcome to SmartSage</title>
<?php echo validation_errors(); ?>
<body>
<form id='myform' action="" method="POST">
<h5>Username:</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password:</h5>
<input type="password" name="passwd" value="" size="50" />
<h5>Security question:</h5><select name="securityq">
<option value="1">What is your house no?</option>
<option value="2">Who is your fav teacher?</option>
</select>
<input type="text" name="securitya" value="" size="50" />
<br>
<input type="submit" value="Login" id="submit" />&nbsp&nbsp
<input type="button" value="Sign Up!" id="signup" />
</form>
</body>
</html>
This is my current form coding... now my objective is to redirect from this form to signup form when user clicks "signup" button...i hv tried above code but its not working...pls help me
Views folder contains /views/signup.php /views/form.php
Thank you!!
You can do in two ways. You have to redirect to signup page. You can't redirect to view file directly. Here signup is controller name. If yu have your signup in another controller then you have to call as site_url("controller_name/signup"); in below code.
<input type="button" value="Sign Up!" id="signup" />
or remove a tag and call via JS.
<input type="button" value="Sign Up!" id="signup" onclick = "window.location='<?php echo site_url("signup.php"); ?>'" />

HTML input field jumps

I have 2 text fields, user and password. When I enter the password, it jumps to the first one. I have no idea why that is happening. I couldn't find why it is jumping. How do I change it so the password form doesn't jump? Here is the code:
<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
</form>
<?php
}else{
?>
<form name="login_form" method="post" action="login2.php">
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
<input type="submit" name="login" id="login" action="index.php" value="Login">
</label>
</p>
</form>
<form name="Register" method="post" action="reg.php">
<input type="submit" name="register" id="register" value="Register">
</form><br />
<form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
?>
You have both of the inputs wrapped in one label. The browser is getting confused and it thinks that that entire content is a label for the first input (that's how labels work, apparently). You should only use <label> to wrap text for input.
This:
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
Should be this:
<input name="user" type="text" id="user">
<label for="user">ID</label><br />
<input name="pass" type="password" id="pass">
<label for="pass">Password</label><br />

trying to post to php file - server error

I'm a newbie here to php and Apache.
I have an html form:
<html>
<body>
<?php
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit"/> </form>
</body>
</html>
I have contact.php located in what I believe is the right place, but when I submit the query, I get "The HTTP verb POST used to access path '/www/contact.php' is not allowed."
When I access contact.php as a url I get strange results (like a repeating File Download message box asking whether I want to Save or Open)
if you are using which is missing in your code.
for your below code will work.
<html>
<body>
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit"/> </form>
</body>
</html>
First Thing Give Name to Submit Button and second remove
<html>
<body>
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit" name="submit" /> </form>
</body>
</html>
and if you can still face an error then try to give full file path in action

php form not passing variable through?

Hey guys I am not able to pass the variable "profile" through... This is done with smarty templates btw
{if $commentpossible == true}
<form name="form1" method="get" action="comment.php?profile=5">
<p>
<label for="comment"></label>
<textarea name="comment" id="comment" cols="45" rows="5" ></textarea>
<br>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
{/if}
Basically this page is profile?profile=5 and I want to pass that profile through...I have "5 manaully inputed atm rather than a variable just too see if it would work...it still does not....when submit is hit it just goes to comment.php?comment=&Submit=Submit....(comment is blank intentionally there)...I need to be more comment.php?profile=5comment=blablabla etc etc
Any idea on what could be the problem?
Add profile as a hidden field when you're using the GET method:
{if $commentpossible}
<form name="form1" method="get" action="comment.php">
<input type="hidden" name="profile" value="5">
<p>
<label for="comment"></label>
<textarea name="comment" id="comment" cols="45" rows="5" ></textarea>
<br>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
{/if}

Categories