nothing happens after clicking submit button - php

I can not figure out what i missed here in my code. i if else statement is working because i can see my form and after submitting i suppose to see message after tag. How would i know if submit button is respond or not.
<?php
$output_form = true;
$fname = "";
$lname = "";
$address1 ="";
$address2 ="";
$city = "";
$state = "";
$zipcode = "";
if (isset($_POST['submit'])) {
print_r($_POST);
$fname = trim($_POST["firstName"]);
$lname = trim($_POST['lastName']);
$address1 = trim($_POST['address1']);
$address2 = trim($_POST['address2']);
$city = trim($_POST['city']);
$state = trim($_POST['state']);
$zipcode = trim($_POST['zipcode']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Assignment 3 </title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
if ($output_form) {
?>
<h1>Enter your information</h1>
<form name="userform" action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
<p>First Name: <input name="firstName" type="text" value="<?= $fname ?>"></p>
<p>Last Name: <input name="lastName" type="text" value="<?= $lname ?>"></p>
<p>Address 1: <input name="address1" type="text" value="<?= $address1 ?>"></p>
<p>Address 2: <input name="address2" value="<?= $address2 ?>" type="text" ></p>
<p>City: <input name="city" type="text" value="<?= $city ?>"></p>
<p>State: <input name="state" type="text" value="<?= $state ?>"></p>
<p>Zip Code: <input name="zipcode" type="number" value="<?= $zipcode ?>"></p>
<input class="button" name="submit" type="button" value="Button">
</form>
<?php
} else {
?>
<h2>Your information is:</h2>
<p class="result">
Name: <?= $fname.' '.$lname ?><br>
Street Address: <?= $address1 ?><br>
City, State: <?=$city.' '.$state ?>
</p>
<?php
}
?>
</body>
</html>

Make your input type submit
<input class="button" name="submit" type="button" value="Button">
Should be
<input class="button" name="submit" type="submit" value="Button">

Related

Update query for database in PHP not working

I am having trouble updating my database data. I put the data that I want to update but when I click on the "Update" button it does
nothing. I have called the file on another php file by using Update
It also shows this error
Notice: Undefined variable: fname in
C:\xampp\htdocs\project\change1.php on line 71
Can someone help me figure this issue, please?
<?php include("config.php"); ?>
<?php
if (isset($_GET['edit'])) {
$update = true;
$record = mysqli_query($con, "SELECT * FROM employee WHERE id='".$_GET['edit']."'");
$row = mysqli_fetch_array($record,MYSQLI_BOTH);
}
if (isset($_POST['update'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$password = $_POST['password'];
$addr = $_POST['addr'];
$phone = $_POST['phone'];
$id=$_GET['edit'];
$query = "UPDATE employee SET fname='".$fname."',lname='".$lname."',password='".$password."',addr='".$addr."',phone='".$phone."' WHERE id='".$id."'";
$result = mysqli_query($con,$query) or die ("problem inserting new record into database");
if($result){
header('location: show_db.php');
}
else {echo "Update not successful"; }
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Update Data</title>
</head>
<body>
Home
<br/><br/>
<input type="hidden" name="id" value="<?php echo $id; ?>">
Name:<input type="text" name="fname" value="<?php echo $fname ; ?>">
Surname:<input type="text" name="lname" value="<?php echo $lname; ?>">
Password:<input type="text" name="password" value="<?php echo $password; ?>">
Address:<input type="text" name="addr" value="<?php echo $addr; ?>">
Contact:<input type="text" name="phone" value="<?php echo $phone; ?>">
<input type="submit" name="update" value="Update">
</body>
</html>
Put the html inputs inside a form
<form name ="form1" method ="get" action="">
<input type="hidden" name="id" value="<?php echo $id; ?>">
Name:<input type="text" name="fname" value="<?php echo $fname ; ?>">
Surname:<input type="text" name="lname" value="<?php echo $lname; ?>">
Password:<input type="text" name="password" value="<?php echo $password; ?>">
Address:<input type="text" name="addr" value="<?php echo $addr; ?>">
Contact:<input type="text" name="phone" value="<?php echo $phone; ?>">
<input type="submit" name="update" value="Update">
</form>

How to connect page between signin,signup and profile in php

i'm still newbie in php, i want to connect this three page. I want to know how to tansfer data from signup to pfofile and also the sign in page. I tried to use tag but not working.
page=signup
<body>
<?php
// define variables and set to empty values
$email = $username = $name = $contact = $birthday = $gender = $address = $password = $payment ="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = test_input($_POST["email"]);
$username = test_input($_POST["username"]);
$name = test_input($_POST["name"]);
$contact = test_input($_POST["contact"]);
$birthday = test_input($_POST["birthday"]);
$gender = test_input($_POST["gender"]);
$address = test_input($_POST["address"]);
$password = test_input($_POST["password"]);
$payment = test_input($_POST["payment"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div id="login">
<form id="registeration" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<fieldset>
<legend><h1>Registeration</h1></legend>
<p>Email:<br/>
<input type="email" name="email"></p>
<p>Username:<br/>
<input type="text" name="username" />
</p>
<p>Your Name:<br/>
<input type="text" name="name"/></p>
<p>Contact Number:<br/>
<input type="text" name="contact"/></p>
<p>Birthday:<br/>
<input type="date" name="birthday">
<p>Gender:<br/>
<input type="radio" name="gender" value="male"/>Male
<input type="radio" name="gender" value="female"/>Female
</p>
<p>Address: <br/>
<textarea name="address" cols="50"></textarea></p>
<p>Password:<br/>
<input name="password" type="password" size="50"/></p>
</p>
<h2>Choose payment method:<br/></h2>
<p><input type="radio" name="payment" value="cod"/>CASH ON DELIVERY</p>
<p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : CIMB Clicks<br/>
<p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : Maybank<br/>
<p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : BSN<br/>
<p><input type="radio" name="payment" value="atm"/>ATM</p>
<p><button type="submit" value="submit">Submit</button><span> <span><span><span><span>
<button type="reset" value="cancel">Cancel</button></p>
</fieldset>
</form>
</div>
echo $email;
echo "<br>";
echo $username;
echo "<br>";
echo $name;
echo "<br>";
echo $contact;
echo "<br>";
echo $birthday;
echo "<br>";
echo $gender;
echo "<br>";
echo $address;
echo "<br>";
echo $password;
echo "<br>";
echo $payment;
?>
</body>
page=signin
<body>
<div id="login">
<fieldset>
<legend><h1>Login</h1></legend>
<form id="signin" method="POST">
<p>Username:<br/>
<input type="text" name="username"/></p>
<p>Password:<br/>
<input type="password" name="password"/></p>
<p><button type="submit" value="submit">Submit</button><span>
<button type="reset" value="cancel">Cancel</button></p>
</form>
</fieldset>
<!-- end .content --></div>
<?php
error_reporting(0);
if (!empty ($_POST)){
if ($_POST ["username"] == NULL){
echo "Please insert your username!";}
else{
$strusername=$_POST["username"];
echo "<p>$strusername</p>";
}}
if (!empty ($_POST)){
if ($_POST ["password"] == NULL){
echo "Please insert the password!";}
else {
$strpassword=$_POST["password"];
echo "<p>$strpassword</p>";
}}
?>
</body>
page=profile
<body>
<div class="container">
<div class="content">
<table>
<td colspan="5"><b>PROFILE</b></td>
<tr>
<td><div align="left">Username:</div></td><td><?php echo $username ?></td></tr>
<td><div align="left">Name:</div></td><td><?php echo $name ?></td></tr>
<td><div align="left">Username:</div></td><td><?php echo $username ?></td></tr>
<td><div align="left">Birthday:</div></td><td><?php echo $birthday ?></td></tr>
<td><div align="left">Contact Number:</div></td><td><?php echo $contact ?></td></tr>
<td><div align="left">Gender:</div></td><td><?php echo $gender ?></td></tr>
<td><div align="left">Address:</div></td><td><?php echo $address ?></td></tr>
<td><div align="left">My payment Method:</div></td><td><?php echo $payment ?></td> </tr>
<tr>
<td><div align="left"><button type="submit" value="Edit Profile" >Edit Profile</button></div> </td>
</tr>
</table>
<!-- end .content --></div>
<!-- end .container --></div>
</body>
Well, Try to use the post and get.
The PHP superglobals $_GET and $_POST are used to collect form-data.The example below displays a simple HTML form with two input fields and a submit button:
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method.
To display the submitted data you could simply echo all the variables. The "welcome.php" looks like this:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
The output could be something like this:
Welcome John
Your email address is john.doe#example.com
The same result could also be achieved using the HTTP GET method:
<html>
<body>
<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
and "welcome_get.php" looks like this:
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</body>
</html>
I Suggest you to follow this tutorial here
I hope it will help you, best regards
Use $_SESSION
In every page start with <?php session_start(); ?>
then store $_SESSION['email'] = test_input($_POST["email"]);
Then in any page you can use echo $_SESSION['email'];
You should use SESSION for simple login functionality....
refer this tutorial about basic login and functionality

Copying a value from POST into a variable

In a page I have a form that submits with Post method. In another page I'm just trying to retreive and echo those values. If I just:
var_dump($_POST)
I see every value I entered in the form.
If I do something like:
echo $_POST['name'];
echo $_POST['surname'];
echo $_POST['telephone'];
I see the correct values.
But if, at the beginning of the page, use:
$name = $_POST['name'];
$surname = $_POST['surname'];
$telephone = $_POST['telephone'];
echo $name . ' ' . $surname . ' ' . $telephone;
I notice that for example name and telephone are always empty.
HTML form:
<form id="dom_com_sci" class="form" name="dom_com_sci" action="./ricevuta-fiscale-2convention.php" method="post" enctype="application/x-www-form-urlencoded" target="_self" style="height: 2200px; width: 619px;">
<p>
<label for="name">name:</label>
<input id="name" class="focus capitalize" name="name" type="text" size="26" value="" maxlength="70" placeholder="es. Mario" autocomplete="off" />
</p>
<p>
<label for="surname">surname:</label>
<input id="surname" class="focus capitalize" name="surname" type="text" size="26" value="" maxlength="70" placeholder="es. Rossi" autocomplete="off" />
</p>
<p>
<label for="telephone">telephone:</label>
<input id="telephone" class="focus capitalize" name="telephone" type="text" size="26" value="" maxlength="70" placeholder="es. Rossi" autocomplete="off" />
</p>
<input type="submit" name="Send" value="Send" tabindex="34" />
</form>
The php script on the result page:
<?php
require_once('./function/generic_function.php');
if(isset($_POST['submit']) && $_POST['submit'] == "Send") {
$surname= $_POST['surname'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
}
?>
generic_function.php:
<?php
function replace($stringa) {
$stringa_r = str_replace('\\','',$stringa);
return $stringa_r;
}
function accesso($percorso,$opzione = "N") {
($opzione == "Y") ? $blank = "target=_blank" : $blank = "";
if(isset($_SESSION['access_level']) && $_SESSION['access_level'] > 1 && isset($_SESSION['logged']) && $_SESSION['logged'] == 1 && isset($_SESSION['user_id'])) {
print('href="'.$percorso.'"'.$blank);
} else {
print('href="'.$dir.'access.php"');
}
}
?>
you are missing on quote (') in these line
$surname= $_POST['surname];
$name = $_POST['name];
$telephone = $_POST['telephone];
it should be this
$surname= $_POST['surname'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
<?php
//error_reporting($level=NULL);
?>
<form id="dom_com_sci" class="form" name="dom_com_sci" action="" method="post" enctype="application/x-www-form-urlencoded" target="_self" >
<p>
<label for="name">name:</label>
<input id="name" class="focus capitalize" name="name" type="text" size="26" value="" maxlength="70" placeholder="es. Mario" autocomplete="off" />
</p>
<p>
<label for="surname">surname:</label>
<input id="surname" class="focus capitalize" name="surname" type="text" size="26" value="" maxlength="70" placeholder="es. Rossi" autocomplete="off" />
</p>
<p>
<label for="telephone">telephone:</label>
<input id="telephone" class="focus capitalize" name="telephone" type="text" size="26" value="" maxlength="70" placeholder="es. Rossi" autocomplete="off" />
</p>
<input type="submit" name="submit" value="submit" tabindex="34" />
</form>
<?php
//require_once('./function/generic_function.php');
if(isset($_POST['submit']) && $_POST['submit'] == "submit") {
$surname= $_POST['surname'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
echo $name . ' ' . $surname . ' ' . $telephone;
}
?>
Comment:: To style your form. You can put it inside the div and than can give that div style.
Thanks let me know it work or not.

$_POST returning empty value

EDIT: The code seems to work if I place the PHP code in the same file at the HTML. I'll implement this method for now. Thank you for the help!
Whenever I try to echo the values in a PHP file from an input box the values appear to be empty.
Here is my HTML code
<form action="sendmail.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
This is my sendmail.php file
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo $name;
echo $email;
echo $message;
You can get the value in Your current page itself
<?php
if(isset($_POST['person']))
{
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo "Name".$name;
echo "Email".$email;
echo "Message".$message;
}
?>
<form action="" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
or if you want the data in another page
<form action="send.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
send.php file
<?php
if(isset($_POST['person']))
{
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo "Name".$name;
echo "Email".$email;
echo "Message".$message;
}
?>
I tried this code and it worked fine, so whatever is wrong it is not with the code you have pasted here.
to make sure the post is successful, try this:
if(isset($_POST['person']))
echo "passed fine.";
check:
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST'){
if(isset($_POST['person'])){
$name = $_POST['person'];
echo $name;
}
}
else{
echo"Your form submission is not correct";
}
try this code.
HTML
<form action="sendmail.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
PHP
<?php
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo $name;
echo $email;
echo $message;
?>
<form action="456.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
<?
print_r($_POST);
?>

can't insert data into database with php

I have writen some code in php for user registration but if i click on submit button It is not writing in database.Please help me. Here is my code...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register - Vatsal Technosoft Messenger</title>
<link href="Style/regstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<div id="outer">
<div id="companyname"></div>
<div class="container">
<div id="formcontainer">
<h3>Registration Form </h3>
<form name="register_form" action="" method="post">
<?php
if( isset($_POST['register']) AND
isset($_POST['username']) AND
isset($_POST['password']) AND
isset($_POST['firstname']) AND
isset($_POST['lastname']) AND
isset($_POST['contact1']) AND
isset($_POST['address']) AND
isset($_POST['jobtitle'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$con1 = $_POST['contact1'];
$con2 = $_POST['contact2'];
$email = $_POST['email'];
$address = $_POST['address'];
$jobtitle = $_POST['jobtitle'];
if( empty($username) or
empty($password) or
empty($fname) or
empty($lname) or
empty($con1) or
empty($email) or
empty($address) or
empty($jobtitle)) {
$message = "All Information Is neccessary";
} else {
$sql = mysql_query("INSERT INTO users VALUES (``,` $username `,` $password `,` $fname `,` $lname `,` $con1 `,` $address `,` $jobtitle `)");
if($sql) {
$message = "OK....!";
} else {
$message = "BAD";
}
}
echo "<div class='box'> $message </div>";
}
?>
<div id="formtext">
User Name : <input type="text" name="username" style="width:200px;" autocomplete="off"/>
Passwrod : <input type="password" name="password" autocomplete="off" style="width:200px;"/>
<br /><br />
First Name : <input type="text" name="firstname" style="width:200px;" autocomplete="off" />
Last Name : <input type="text" name="lastname" autocomplete = "off" style = " width:200px; "/>
<br /><br />
Contact(1) : <input type="text" name="contact1" autocomplete="off" style="width:200px;" />
Contact(2) : <input type="text" name="contact2" autocomplete="off" style="width:200px;"/>
<br /><br />
E-mail ID : <input type="text" name="email" autocomplete="off" style="width:300px;"/>
<br /><br />
Address :<br />
<textarea name="address" cols="25" rows="5" autocomplete="off" style="background: #333;color: #fff;border-radius:5px;border: 0px; margin-top:-20px;" placehoder="Address"></textarea>
<br /><br />
Job Title : <input type="text" name="jobtitle" autocomplete="off" style="width:215px;"/>
<br /><br /><br />
<input type="button" name="back" value="Back" style="width:100px; margin-left:95px;"/>
<input type="reset" name="reset" value="Reset" style="width:100px; margin-left:45px;"/>
<input type="submit" name="register" value="Register" style="width:100px; margin-left:45px;"/>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Your issue is probably this line:
$sql = mysql_query("INSERT INTO users VALUES (``,` $username `,` $password `,` $fname `,` $lname `,` $con1 `,` $address `,` $jobtitle `)");
It is recommended to always declare your column names in the INSERT statement like this:
$sql = mysql_query("INSERT INTO `users` (`col1` , `col1` , `col3`) VALUES ('val1' , 'val2' , 'val3')");

Categories