Show the input data PHP - php

I'm used to using CIN, of C++, to get a input into a var... Its really EASY!
So, I'm starting learn PHP.
And, I'm testing show on the screen what the user input in a form.
I know its a easy thing, but I am not achieving.
The form is in this file:
- html5.html
<div id="form">
<form action="test.php" method="post" >
<label for="code"> Code </label> <br />
<input type="password" id="coded" name="code" /> <br /> <br />
<hr />
<select name="modo-log[]" id="choose">
<option class="select_mod" value="professor">Professor</option>
<option class="select_mod" value="student" selected="selected">Student</option>
<option class="select_mod" value="user">User</option>
<option class="select_mod" value="adm">Adm</option>
</select>
<hr />
<button> Entrar </button>
</form>
And the PHP file:
- test.php
<?php
$code = $_POST['code'];
echo "$code";
$type_entered = $_POST['modo-log'];
echo "$type_enterd";
?>
But, I dont Know what I'm doing wrong...
The page just gets blank.
Help me?
Thanks.

Add type="submit" attribute in <button> tag. SO that it will submit your form request
Change
<button> Entrar </button>
to
<button type="submit">Entrar</button>

This following setup should tell you whats wrong :)
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
?>
<div id="form">
<form action="" method="post" >
<label for="code"> Code </label> <br />
<input type="password" id="coded" name="code" /> <br /> <br />
<hr />
<select name="modo-log[]" id="choose">
<option class="select_mod" value="professor">Professor</option>
<option class="select_mod" value="student" selected="selected">Student</option>
<option class="select_mod" value="user">User</option>
<option class="select_mod" value="adm">Adm</option>
</select>
<hr />
<button type="submit">Entrar</button>
</form>
<?php var_dump($_POST); ?>

I'm almost sure that my apache is wrong installed...
It'snt possible! I cannot do a simple test!
When I suspected the trouble was the apache, I tryed only this:
<!DOCTYPE html>
<html>
<body>
<?php
$varr_1 = 1;
$varr_2 = 2;
$varr_3 = $varr_1 + $varr_2;
echo $varr_3;
?>
</body>
</html>
And I didn't got any result. The page gets blank yet.
thanks to those who tried to help, I'll create a website on 000webhost to run php, whereas I've already tryed reinstalling the apache.
I'm sad....
Bye

Related

select tag name not working while using it in php

I have a form in html and I am saving it as search.php:
<form name="myform" action="" method="POST" onsubmit="search_clicked(); return false;">
Keyword<input type="text" name="Keyword" id="Keyword" value="XYZ" required/><!-- value is the default name that appears in the text box-->
<br>
Type
<select name="sel" id="sel" class="form-control" onchange="checkcolors(this.value)">
<option selected value="Users">Users</option>
<option value="Pages">Pages</option>
<option value="Events">Events</option>
<option value="Places">Places</option>
<option value="Groups">Groups</option>
</select>
</form>
<div id="loc_dist_displayarea" style="display:none;">
Location<input type="text" name="Location" value="90007" required/> Distance(meters)<input type="text" name="distance" value="10000" required/>
</div>
<br><br>
<input type="submit" name="Search"/>
<input type="submit" value="clear" id="clear" onclick="return clearclicked()"/>
</form>
and my php script is in the same file:
<div id="body_area" style="display:none">
<?php
echo "hi I am searching ";
if($_SERVER["REQUEST_METHOD"]=="POST")
{
//echo "yes value is selected";
//echo $_POST["Keyword"];
if (isset($_POST['sel'])) {
$selectedval= $_POST["sel"];
echo "$selectedval";
}
//echo $_POST["Location"];
}
echo "no value is selected";
?>
</div>
I am not able to display the $_POST['sel'] while $_POST['Keyword'] is echoed.Please help.
First of all, you arent using good programming practices, you use quotation marks (these " and these ') Indiscriminately. You should only alternate between them when you have them nested.
Next, on the action paramenter you should put the name of the file, even if it's the same.

Same page form submit very slow to display data

I have a Joomla site that I am building a form for. The form is working fine in a localhost test environment but when I put it on my live server, the form would not work properly. I stripped out code until I basically just had the form and I still have issues, the form is very slow to submit and display the data, it could take minutes for the updated data to display and I have to refresh the page to get it. On another server the form works properly. Data is displayed as fast as the submit button is clicked.
I've been fighting this for a couple of days and have gotten nowhere.
Here is the form:
<form action="<?php $_SERVER['REQUEST_URI'] ?>" method="post">
<select name="vendor_num">
<option value="" selected="selected" > Select a Vendor </option>
<option value="000000" >All Vendors</option>
<option value="008064" >Great Glacier Salmon</option>
<option value="008173" >Seed 2 Sausage</option>
<option value="008219" >Back Forth Artisan Cheese</option>
<option value="008215" >True North Salmon</option>
</select>
<br />
<label for="prov_ont">
<input type="radio" id="prov_ont" name="prov" value="Ontario" > Ontario
</label>
<br />
<label for="country_canada">
<input type="radio" id="country_canada" name="country" value="Canada" > Canada
</label>
<br />
<label for="kosher">
<input type="radio" id="kosher_flag" name="kosher" value="Y" > Kosher
</label>
<br />
<label for="halal">
<input type="radio" id="halal_flag" name="halal" value="Y" > Halal
</label>
<br />
<label for="oceanwise">
<input type="radio" id="oceanwise_flag" name="oceanwise" value="Y" > Oceanwise
</label>
<br />
<input type="submit" name="submit" value="submit" style="padding:5px; margin-top:20px;">
<input type="reset" value="reset" name="reset" style="padding:5px; margin-top:20px;">
</form>
<pre>
<?php
var_dump($_POST);
echo "<br />";
?>
</pre>
the problem URL is: http://findlayfoods.com/search-test
Here is another host with the same page working:
http://glenntooth.com/index.php/form-test
I have also tried with action="", exactly the same thing.
I am admittedly a beginner but have been working on this for a while. Help appreciated.
G

Form action not refreshing properly

I have a problem whit form submission. I have a html form and the action simpli doesnt want to work. maybe i am doing something wrong, but here take a look at it:
<form action="add.php" method="post" autocomplete="off">
<input type="text" name="title" placeholder="Title" style="width:300px;">
<select id="type" name="type">
<option value="0">Matrix</option>
<option value="1">LoL</option>
<option value="2">Dota 2</option>
</select><br />
<textarea rows="30" cols="90" placeholder="Content here" name="content"></textarea><br />
<input type="submit" value="DODAJ">
</form>
so when i click on the button i does refresh the page but nothing is displayed. I't worked in local but when i upload it online nothnig, just a blank page. And the stuff that has to go to the database doesnt go. no errors, no nothing.
help?
Here's the complete code for that add.php page:
<?php
include '../php/db/init.php';
include '../php/db/connection.php';
protect_page();
admin_protect();
if(isset($_SESSION['logged_in'])){
if(isset($_POST['title'], $_POST['content'], $_POST['type'])){
$title = $_POST['title'];
$content = nl2br($_POST['content']);
$content_short = substr($content,0, 150);
$type = $_POST['type'];
echo $type;
die();
if(empty($title) or empty($content) or empty($type)){
$error = 'Potrebno je popuniti sva polja!';
} else {
$query = $pdo->prepare('INSERT INTO articles (article_title, article_content, article_content_short, article_timestamp, article_type) VALUES (?,?,?,?,?)');
$query->bindValue(1,$title);
$query->bindValue(2,$content);
$query->bindValue(3,$content_short);
$query->bindValue(4,time());
$query->bindValue(5,$type);
$query->execute();
redirect('http://www.matrixgamingns.com/admin/index.php');
}
}
?>
<html>
<head>
<title>Matrix Gaming Admin Panel</title>
<link rel="stylesheet" type="text/css" href="../css/admin.css">
<link rel="stylesheet" type="text/css" href="../css/reset.css">
</head>
<body>
<div id="home">
<div id="wrapper">
<?php include 'adminmenusidebar.php'; ?>
<div id="field">
<h3 style="font-size:22px;">Dodaj vest</h3>
<?php if(isset($error)){ ?>
<small style="color:#aa0000"> <?php echo $error?> </small>
<br/>
<?php }?>
<br />
<form action="add.php" method="post" autocomplete="off">
<input type="text" name="title" placeholder="Title" style="width:300px;">
<select id="type" name="type">
<option value="0">Matrix</option>
<option value="1">LoL</option>
<option value="2">Dota 2</option>
</select><br />
<textarea rows="30" cols="90" placeholder="Content here" name="content"></textarea><br />
<input type="submit" value="DODAJ">
<?php
ini_set('display_errors','On');?>
</form>
</div>
</div>
</div>
</body>
</html>
<?php
} else {
redirect('http://www.matrixgamingns.com/admin/index.php');
}
?>
Get rid of the die() after echo $type;
By including a die() function, it stops all in its tracks, just like return does and nothing gets executed afterwards.
You could use the login form example posted here: HTML Dynamic Forms Generator
I downloaded the source code for the login form and it saved me lots of time.

php echo not working properly

Basically, I want made a simple form in html and i want to output the all of the user input once clicked submit using php. So far its just displaying the details I entered but it doesn't get user's data to echo them out. Here are my two files
output.php:
<?php
echo 'Name: '.$POST["name"].'<br /> Gender: '.$POST["gender"].'<br />Country: '.$POST["country"];
?>
testingformphp.html (form part):
<form id="form" name="form" method="post" action="./PHP/output.php"/>
Name<input name="name" type="text" id="name"/><br/>
Gender<label><input type="radio" name="gender" id="gender_0" value="male"/>Male</label><br/>
<label><input type="radio" name="gender" id="gender_1" value="female"/>Female</label><br/>
<select name="country" id="select">
<optgroup title="europe">
<option value="Russia">Russia</option>
<option value="Greece">Greece</option>
</optgroup>
</select>
<input type="submit" id="button" value="Submit"/>
<input type="reset" id="reset" value="Reset"/>
</form>
Can anyone help?
$POST does not exists, try $_POST.
<?php
echo 'Name: '.$_POST["name"].'<br /> Gender: '.$_POST["gender"].'<br />Country: '.$_POST["country"];
?>
http://www.tizag.com/phpT/postget.php To review the post and get method.

2 Questions: PHP code runs successfully on Apache webserver, but not on local EasyPHP?

1: When I run this code (some unnecessary code omitted) on a webserver, it runs fine. I have an EasyPHP setup, and when I run the exact same code on that, I get the error:
Parse error: syntax error, unexpected '<<' (T_SL) in C:\Program Files (x86)\EasyPHP-12.1\www\my portable files\part1.php on line 985
(Line 985 is commented as such below)
2: Whenever I run this code on the webserver, it says that I do not have access to $_SERVER[PHP_SELF], so I have to use "". While "" works, it doesn't validate correctly.
note: I cannot get the code blocks to format properly. The block(s) below should read as one continuous block.
function print_form() {
echo <<<END /*Line 985*/
<h1>Welcome to the player registration page. Please input the following:</h1>
<form action="$_SERVER[PHP_SELF]" method="post">
<div class="name">
Username: <input type="text" name="name" size="12" /> <br />
</div>
<div class="country">
Country: <select name="country">
<option value="">Select Country</option>
<option value="AF">Afghanistan</option>
...
<option value="ZW">Zimbabwe</option>
</select>
</div>
<div class="xfire">
Xfire: <input type="text" name="xfire" /> <br />
</div>
<div class="team">
Team: <input type="text" name="team" /> <br />
</div>
<div class="tag">
Tag: <input type="text" name="tag" /> <br />
</div>
<input type="hidden" name="stage" value="process">
Submit Info:
<input type="submit" value="Submit"/>
</form>
END;
try:
function print_form() {
?>
<h1>Welcome to the player registration page. Please input the following:</h1>
...
<? } ?>
I think this way is much easier...

Categories