PHP Radio Buttons forms example - php

So lets say i have the following example how can i get values from radio buttons and acctualy work with those values? You can see that i tried something but i can't find it how to make it work ..
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-ex-collapse"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="navbar-brand">My learning skills: A self-assessment questionnaire</a></div>
<div class="collapse navbar-collapse" id="navbar-ex-collapse">
<ul class="nav navbar-nav navbar-right"></ul>
</div>
</div>
</div>
<div class="section">
<div class="container">
<div class="row">
<div class="col-md-12">
<form role="form" method="post">
<div class="form-group"><label class="control-label" for="exampleInputEmail1">Nume:</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter name" type="text"></div>
<div class="form-group"><label class="control-label" for="exampleInputEmail1">Email address:</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter email" type="email"></div>
<div class="container">
<div class= "row">
<h4>Your gender: *</h4>
</div>
<div class="row">
<div class="radio">
<label><input type="radio" name="gender" value="female">F</label>
</div>
<div class="radio">
<label><input type="radio" name="gender" value="male">M</label>
</div>
<div class="radio">
<label><input type="radio" name="gender" value="other">Other</label>
</div>
</div>
</br>
<div class="row">
<div class="form-group"><label class="control-label" for="exampleInputEmail1">Your age: *</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter age" type="text"></div>
</div>
<div class= "row">
<h2>That was it! Please, keep your scores saved and check that after refilling in this questionnaire, in 6-8 months from now on. Happy learning!</h2>
</div>
<div class= "row">
<button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg">Send</button>
</div>
</div>
</form>
<?php $gender = $_POST['contact']; echo $gender; ?>
</div>
</div>
</div>
</div>
</body>
</html>
As example:
echo $gender;
and the results should be $female

<?php $gender = $_POST['contact']; echo $gender; ?>
Change this to
<?php $gender = $_POST['gender']; echo $gender; ?>.
Name of your radio control is gender not contact.

Related

Bootstrap 4 carousel next and prev slides don't work

I'm trying to solve an weird issue for a school group project on my own, but I'm at wit's end. Essentially, I have a Bootstrap 4 Carousel with three images. Though one of the images is displayed, you can't advance to the next or previous slides. The initial webpage is launched using php as follows:
<?php
//require_once('connection.php');
if (isset($_GET['controller']) && isset($_GET['action'])) {
$controller = $_GET['controller'];
$action = $_GET['action'];
} else {
$controller = 'static';
$action = 'landing';
}
require_once('views/layout.php');
?>
The landing page launches layout.php (which has the Bootstrap, jQuery, popper and other JavaScript files and landing.php (which has the carousel code:
landing.php:
<div id="main_container" class="container-fluid">
<div id="body" class="container">
<p>Stuff about how great the application is.</p>
<div id="carousel" class="carousel slide" content="width=device-width data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel" data-slide-to="0" class="active"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="2"></li>
</ol>
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="./views/images/kids_kites.png" alt="Los Angeles">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>We had such a great time in LA!</p>
</div>
</div>
<div class="carousel-item">
<img src="./views/images/kids_playing.png" alt="Chicago">
<div class="carousel-caption">
<h3>Chicago</h3>
<p>We had such great pizza in CHI!</p>
</div>
</div>
<div class="carousel-item">
<img src="./views/images/kids_swing.png" alt="New York">
<div class="carousel-caption">
<h3>New York</h3>
<p>It is too crowded!</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#carousel" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#carousel" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</div>
Search Events
</div>
layout.php
<!doctype HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<script defer src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script defer src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<title>Kamps For Kids</title>
<link rel="stylesheet" href="views/styles/styles.css">
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script defer src="views/scripts/main.js"></script>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
</head>
<body>
<?php
require_once "templates/header.php";
require_once "templates/footer.php";
require_once "routes.php";
?>
<div id="id01" class="modal">
<!--action_page.php is the php file which will perform user validation when the 'submit' button is clicked -->
<form class="modal-content animate" action="/action_page.php">
<div class="img-container">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
<div><img src="./views/images/KamparoosLogo.png" alt="Logo" class="logo"></div>
<img src="./views/images/img_avatar2.png" alt="Avatar" class="avatar">
<div>
<!-- Add icon library from font-awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Add font awesome icons -->
</div>
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="user-name" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#FAFC2F">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancel-btn">
Cancel
</button>
<span class="psw">Forgot password?</span>
</div>
</form>
</div>
<div id="id02" class="modal">
<!--action_page.php is the php file which will perform user validation when the 'submit' button is clicked -->
<form class="modal-content animate" name="registrationForm" onsubmit="return validateForm()" method="post"
action="/action_page.php">
<div class="img-container">
<h3>Registration Form</h3>
<span onclick="document.getElementById('id02').style.display='none'" class="close" title="Close Modal">×</span>
<div><img src="./views/images/KamparoosLogo.png" alt="Logo" class="logo"></div>
<img src="./views/images/img_avatar2.png" alt="Avatar" class="avatar">
<div>
<!-- Add icon library from font-awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</div>
</div>
<div class="container">
<div class="form-row">
<div class="form-group col-md-6">
<label for="firstName">First Name</label>
<input type="text" class="form-control" id="firstName" placeholder="Enter first name" name="firstName"
required>
</div>
<div class="form-group col-md-6">
<label for="lastName">Last Name</label>
<input type="text" class="form-control" id="lastName" placeholder="Enter last name" name="lastName"
required>
</div>
<div class="form-group col-md-6">
<label for="emailAddress">Email Address</label>
<input type="email" class="form-control" id="emailAddress" placeholder="Enter email address"
name="emailAddress" required>
</div>
<div class="form-group col-md-6">
<label for="phoneNumber">Phone Number</label>
<input type="tel" class="form-control" id="phoneNumber" placeholder="Enter 10 digit phone number"
name="phoneNumber" required
pattern="[0-9]{3}[0-9]{3}[0-9]{4}"
size="10">
</div>
<div class="form-group col-md-12">
<label for="numOfKids">Number of Kids </label>
<select name="numOfKids" id="numOfKids">
<option value="">Select...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Enter password" name="password"
required>
</div>
<div class="form-group col-md-4">
<label for="confirmPassword">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword" placeholder="Re-enter password"
name="confirmPassword" required>
</div>
<div class="form-group col-md-12">
<label for="userRole">Register as </label>
<select name="userRole" id="userRole" required>
<option value="">Select...</option>
<option value="user">Individual User</option>
<option value="admin">Admin</option>
<option value="organization">Organization</option>
</select>
</div>
</div>
</div>
<button type="submit" class="btn btn-danger btn-success"
">Register</button>
</form>
</div>
<script>
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, the modal with close
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
// Get the modal
var modalTwo = document.getElementById('id02');
// When the user clicks anywhere outside of the modal, the modal with close
window.onclick = function (event) {
if (event.target == modalTwo) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
If you're interested, the project is being saved in a GitHub repository at : https://github.com/ad410project/ad410project I'm sure it's possible some crazy php issue, but any help or suggestions would be appreciated.

Blank entries with SQL and PHP [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I tried the other solutions on this and other sites, but can´t make it work.
When I press refresh empty data is sent to phpmyadmin, and a blank entry is made.
When I press submit it doesn´t send anything, not even blank.
My database connection is working.
conn
<?php
$host = 'localhost'; // min host.
$user = 'root'; // mit brugernavn.
$password = 'mysql'; // mit password. Er tomt for Windows-brugere, men root for Mac-brugere.
$database = 'boliger'; // navnet på min database.
$conn = new mysqli($host, $user, $password, $database);
mysqli_set_charset($conn, 'utf8');
if ($conn->connect_error)
die($conn->connect_error);
?>
index
<?php
include_once 'conn.php';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<link rel="apple-touch-icon" sizes="76x76" href="assets/img/apple-icon.png" />
<link rel="icon" type="image/png" href="assets/img/favicon.png" />
<title>Bolig</title>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
<meta name="viewport" content="width=device-width" />
<!-- CSS Files -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/css/paper-bootstrap-wizard.css" rel="stylesheet" />
<!-- CSS Just for demo purpose, don't include it in your project -->
<link href="assets/css/demo.css" rel="stylesheet" />
<!-- Fonts and Icons -->
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Muli:400,300' rel='stylesheet' type='text/css'>
<link href="assets/css/themify-icons.css" rel="stylesheet">
</head>
<body>
<div class="image-container set-full-height" style="background-image:">
<!-- Creative Tim Branding -->
<!-- Big container -->
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<!-- Wizard container -->
<div class="wizard-container">
<div class="card wizard-card" data-color="green" id="wizard">
<form method="POST" action="process.php">
<!-- You can switch " data-color="green" " with one of the next bright colors: "blue", "azure", "orange", "red" -->
<div class="wizard-header">
<h3 class="wizard-title">Søg bolig</h3>
<p class="category">Denne information vil hjælpe os med, at denne et billed af dine bolig ønsker.</p>
</div>
<div class="wizard-navigation">
<div class="progress-with-circle">
<div class="progress-bar" role="progressbar" aria-valuenow="1" aria-valuemin="1" aria-valuemax="4" style="width: 15%;"></div>
</div>
<ul>
<li>
<a href="#location" data-toggle="tab">
<div class="icon-circle">
<i class="ti-map"></i>
</div>
Placering
</a>
</li>
<!--
<li>
<a href="#type" data-toggle="tab">
<div class="icon-circle">
<i class="ti-direction-alt"></i>
</div>
Type
</a>
</li>
-->
<li>
<a href="#facilities" data-toggle="tab">
<div class="icon-circle">
<i class="ti-panel"></i>
</div>
Kontakt Oplysninger
</a>
</li>
</ul>
</div>
<div class="tab-content">
<div class="tab-pane" id="location">
<div class="row">
<div class="col-sm-12">
<h5 class="info-text"> Lade os starte med, at få de grundlæggende oplysninger.</h5>
</div>
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Kommune 1</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
</div>
<div class="form-group">
<label>Kommune 2</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
</div>
<div class="form-group">
<label>Kommune 3</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
</div>
<div class="form-group">
<label>Kommune 4</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
</div>
<div class="form-group">
<label>Kommune 5</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
</div>
</div>
<div class="col-sm-5 col-sm-offset">
<div class="form-group">
<label>Antal Voksne</label>
<select class="form-control">
<option disabled="" selected="">- Voksne -</option>
<option>1 Person</option>
<option>2 Personer </option>
<option>3 Personer</option>
<option>4 Personer</option>
<option>5 Personer</option>
<option>6+ Personer</option>
</select>
</div>
</div>
<div class="col-sm-5 col-sm-offset">
<div class="form-group">
<label>Antal Børn</label>
<select class="form-control">
<option disabled="" selected="">- Børn -</option>
<option>1 Barn</option>
<option>2 Børn </option>
<option>3 Børn</option>
<option>4 Børn</option>
<option>5 Børn</option>
<option>6+ Børn</option>
</select>
</div>
</div>
<div class="col-sm-5 col-sm-offset">
<div class="form-group">
<label>Antal Rum</label>
<select class="form-control">
<option disabled="" selected="">- Værelser -</option>
<option>1 Værelse</option>
<option>2 Værelser </option>
<option>3 Værelser</option>
<option>4 Værelser</option>
<option>5 Værelser</option>
<option>6+ Værelser</option>
</select>
</div>
</div>
<div class="col-sm-5 col-sm-offset">
<div class="form-group">
<label>Maksimum husleje inkl. forbrug</label>
<div class="input-group">
<input type="text" class="form-control" placeholder="Husleje">
<span class="input-group-addon">DKK</span>
</div>
</div>
</div>
<div class="col-sm-5 col-sm-offset">
<div class="form-group">
<label>Kæledyr</label>
<div class="checkbox">
<label><input type="checkbox" value="">Hvis du har kæledyr og ønsker, at det er tilladt i den nye bolig, så sæt venligst et flueben.</label>
</div>
</div>
</div>
</div>
</div>
<!--
<div class="tab-pane" id="type">
<h5 class="info-text">Hvilken form for bolig har du?</h5>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="col-sm-4 col-sm-offset-2">
<div class="choice" data-toggle="wizard-checkbox">
<input type="checkbox" name="jobb" value="Design">
<div class="card card-checkboxes card-hover-effect">
<i class="ti-home"></i>
<p>Lejlighed</p>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="choice" data-toggle="wizard-checkbox">
<input type="checkbox" name="jobb" value="Design">
<div class="card card-checkboxes card-hover-effect">
<i class="ti-package"></i>
<p>Der komme flere på, i takt med, at vi udvider.</p>
</div>
</div>
</div>
</div>
</div>
</div>
-->
<div class="tab-pane" id="facilities">
<div class="row">
<div class="col-sm-12">
<h5 class="info-text">Dine kontaktoplysninger</h5>
</div>
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Navn</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast navn">
</div>
</div>
<div class="col-sm-5 col-sm-offset">
<div class="form-group">
<label>Email</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast email">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Mobil nummer</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast mobil nummer">
</div>
</div>
</div>
</div>
<div class="wizard-footer">
<div class="pull-right">
<input type='button' class='btn btn-next btn-fill btn-success btn-wd' name='next' value='Næste' />
<input type='submit' class='btn btn-finish btn-fill btn-success btn-wd' name="submit" value="Submit" />
</div>
<div class="pull-left">
<input type='button' class='btn btn-previous btn-default btn-wd' name='previous' value='Tilbage' />
</div>
<div class="clearfix"></div>
</div>
</form>
</div>
</div> <!-- wizard container -->
</div>
</div> <!-- row -->
</div> <!-- big container -->
<div class="footer">
<div class="container text-center">
</div>
</div>
</div>
<?php
if( isset( $_POST['submit'] ) )
{
$hvemErDu = $_POST['hvemErDu'];
} else {
echo error;
}
//connecting to sql database
$conn or die( $conn->error );
//inserting details into table
$insert = $conn->query( "INSERT INTO lejere ( `hvemErDu` ) VALUE ( '$hvemErDu' )" );
//closing mysqli connection
$mysqli->close;
//if ($_POST) {
// if (isset($_POST["Submit"])) {
// // $hvemErDu = $_POST["hvemErDu"];
// // Se side 250
// mysqli_query($conn, "INSERT INTO lejere (hvemErDu)
//VALUES ('$_POST[hvemErDu]')";
//
?>
</body>
<!-- Core JS Files -->
<script src="assets/js/jquery-2.2.4.min.js" type="text/javascript"></script>
<script src="assets/js/bootstrap.min.js" type="text/javascript"></script>
<script src="assets/js/jquery.bootstrap.wizard.js" type="text/javascript"></script>
<!-- Plugin for the Wizard -->
<script src="assets/js/paper-bootstrap-wizard.js" type="text/javascript"></script>
<!-- More information about jquery.validate here: http://jqueryvalidation.org/ -->
<script src="assets/js/jquery.validate.min.js" type="text/javascript"></script>
</html>
process
<?php
//process.php
if ($_SERVER["REQUEST_METHOD"] == "POST") {//Check it is coming from a form
$u_name = $_POST["hvemErDu"]; //set PHP variables like this so we can use them anywhere in code below
//$u_email = $_POST["user_email"];
//$u_text = $_POST["user_text"];
//print output text
print "Hello " . $u_name . "!, we have received your message and email "; //.$u_email;
print "We will contact you very soon!";
}
?>
How does your form look like? Do you have a "submit" input at all?
From what I see in your code, SQL statement runs every time you send the form, without any condition, you better place the query inside the condition brackets, like:
<?php
if (isset( $_POST['submit'] ))
{
$hvemErDu = $_POST['hvemErDu'];
//connecting to sql database
$conn or die( $conn->error );
//inserting details into table
$insert = $conn->query("INSERT INTO lejere ( `hvemErDu` ) VALUE ( '$hvemErDu' )");
//closing mysqli connection
$mysqli->close;
} else
{
echo 'error';
}
?>
Pay attention that you also echo error - I'm not sure if you meant to echo the string 'error' or the variable $error.
But again, this time it looks like you won't have any record - not even a blank one, can you show the whole form code?
Update:
As for your code, pay attention that when you post your form, you submit it to process.php, is that file exists at all? as your code wouldn't work unless you submit the form to the same page, as the following code:
// Send the form to the same page - index.php
<form method="POST">
Update:
You've another problem, you've many inputs which share the same name: hvemErDu.
You've to give each input a unique name, otherwise the latest input's value is gonna be submitted to server.
This is from your index.php code:
<label>Kommune 1</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
<label>Navn</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast navn">
<label>Email</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast email">
<label>Mobil nummer</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast mobil nummer">

PHP Display single value from session array

I currently have a PHP form for our partners to register quotes. After the user log in they are brought to the beginning of the quote form. I would like the user's first name to display in the first form field automatically.
The user's session information includes an array of values; one of which is the firstName value. This is the value that I would like to display in the first field when the user logs in.
When I try to load the page I am getting an error instead of the user's first name.
This is the error I am getting:
Notice: Undefined index: user in C:\wamp64\www\quote_generator\quote_tool.php on line 77
Here is the updated page code:
<?php
require("config.php");
if(empty($_SESSION['user']))
{
header("Location: index.php");
die("Redirecting to index.php");
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Quoting Tool </title>
<meta name="description" content="Teo partner quote generator tool">
<meta name="Kenneth Carskadon" content="www.kencarskadon.com">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="assets/css/bootstrap.min.css" media="screen">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.1.3/css/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="assets/css/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="assets/css/form-elements.css">
<link rel="stylesheet" href="assets/css/datepicker.css">
<link rel="stylesheet" href="assets/css/style.css">
<style>
body {
background: url("assets/images/backgrounds/background.jpg") no-repeat fixed center;
background-size: cover;
}
</style>
</head>
<body>
<!-- Top menu -->
<nav class="navbar navbar-inverse navbar-no-bg" role="navigation">
<div class="container">
<div>
<a class="navbar-brand" href="#">
<img src="assets/images/logo/Teo%20Logo%20White.png" class="img-responsive" id="teo-logo">
</a>
</div>
</div>
</nav>
<!-- Top content -->
<div class="top-content">
<div class="inner-bg">
<div class="container form-container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 text">
<h1><strong>Teo</strong> Partner Quote Generation Form</h1>
</div>
</div>
<div class="row">
<div class="col-sm-8 col-sm-offset-2 form-box">
<form role="form" action="" method="post" class="registration-form">
<!-- Fieldset 1: Partner Information -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h2>Partner Information</h2>
<h3>Tell us who you are</h3>
</div>
<div class="form-top-right">
<img src="assets/images/icons/partner_info.png" class="form-icon">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<input type="text" name="form-partner-name" placeholder="Partner name" class="form-partner-name form-control" id="form-partner-name"
value="<?php echo $_POST['user']['firstName']?>">
</div>
<div class="form-group">
<select name="partner-level" type="text" title="Select partner level" class="form-control" id="form-partner-level" >
<option>Select partner level</option>
<option data-price="34">Platinum</option>
<option data-price="32">Gold</option>
<option data-price="29">Silver</option>
</select>
</div>
<div class="form-group">
<input type="text" readonly="readonly" name="discount-perc" placeholder="Discount(%)" class="form-control" id="form-discount-perc">
</div><br />
<div class="form-group">
<input type="text" name="form-margin-perc" placeholder="Margin(%)" class="form-control" id="form-margin-perc">
</div>
<br /><br />
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<!-- Fieldset 2: Quote Information -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h2>Quote Information</h2>
<h3>Tell us about your customer</h3>
</div>
<div class="form-top-right">
<img src="assets/images/icons/partner_info.png" class="form-icon">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<input type="text" name="form-customer-name" placeholder="Customer name" class="form-customer-name form-control" id="form-customer-name">
</div>
<div class="form-group">
<input type="text" name="form-quote-number" placeholder="Quote Number" class="form-quote-number form-control" id="form-quote-number">
</div>
<div class="form-group">
<input type="text" name="form-incentive-exp" placeholder="Incentive Expiration Date" class="teo-datepicker">
</div>
<div class="form-group">
<input type="text" name="form-proposal-exp" placeholder="Proposal Expiration Date" class="teo-datepicker">
</div>
<br /><br />
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<!-- Fieldset 3: Select Servers -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h2>Select Servers</h2>
<h3>Tell us about the servers you need</h3>
</div>
<div class="form-top-right">
<img src="assets/images/icons/select_servers.png" class="form-icon">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<label for="server-select">What kind of server do you need?</label>
<select class="form-control" id="server-type-select">
<option>Please select and option below</option>
<option>Pro Server</option>
<option>Mini Server</option>
</select>
</div>
<div class="form-group">
<label for="server-select">How many servers do you need?</label>
<input type="text" name="form-server-quantity" placeholder="Number of servers" class="form-control" id="form-server-quantity">
</div>
<br /><br />
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
<button type="button" class="btn btn-skip">skip</button>
</div>
</fieldset>
<!-- Fieldset 4: Configure Servers -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h2>Select Servers</h2>
<h3>Tell us about the servers you need</h3>
</div>
<div class="form-top-right">
<img src="assets/images/icons/select_servers.png" class="form-icon">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<label for="server-select">What kind of server do you need?</label>
<select class="form-control" id="server-type-select">
<option>Please select and option below</option>
<option>Pro Server</option>
<option>Mini Server</option>
</select>
</div>
<div class="form-group">
<label for="server-select">How many servers do you need?</label>
<input type="text" name="form-server-quantity" placeholder="Number of servers" class="form-control" id="form-server-quantity">
</div>
<br /><br />
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
<button type="button" class="btn btn-skip">Skip</button>
</div>
</fieldset>
<div class="btn-logout">
Logout
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Javascript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.backstretch.min.js"></script>
<script type='text/javascript' src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>
<script src="assets/js/bootstrap-datepicker.js"></script>
<script src="assets/js/scripts.js"></script>
<!--[if lt IE 10]>
<script src="assets/js/placeholder.js"></script>
<![endif]-->
</body>
</html>
Update: I have a session page that shows me the information on the current session, and these are the results for the form I am talking about:
View Image
The screenshot clarified it.
You should be able to use
$session['user']['firstName']
As noted in the comments above though, you will want to migrate away from using eval, which has security implications.

trying to make a login system but nothing returns to database

i've been trying to make a login system on my website with a signup button but nothing returns to the database aka its empty, here's the code
<?php
include 'dbh.php', 'connect.php';
$usernames=$_POST['usernames'];
$passwords=$_POST['passwords'];
$repassword=$_POST['repassword'];
$email=$_POST['email'];
$taken="false";
$database="database1";
//Main if Statement
if($usernames&&$passwords&&$email&&$repassword){
//connect to database
$con = mysqli_connect('localhost', $username, $password) or die("Unable to log into database");
#mysql_select_db($database1, $con) or die("Unable to connect");
mysql_query("INSERT INTO `users` VALUES('', '$usernames', '$passwords', '$email', '$repassword')") or die ("Strange error");
echo "Account created";
mysql_close($con);
// header("location: index.php");
} else {
echo"You need to have Username, Password and Email!";
}
?>
i have tried to signup for testing but nothing returns to the database?
here's the html script
<!DOCTYPE html>
<html lang="en">
<head>
<link href="animate.css" rel="stylesheet">
<title>Twist - Shortie Lovers!</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js" </script>
</head>
<body>
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
Twist
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>New</li>
<li class="dropdown">
Hot <b class="caret"></b>
<ul class="dropdown-menu">
<li>Test</li>
</ul>
</li>
<li>Upload</li>
<li>Sign up</li>
<li>Login</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="jumbotron text-center">
<h1>You can do it!</h1>
<p>How? simple... Make your own movie, get rated by other users and movie makers and WIN!</p>
<a class="btn btn-info">Read More...</a>
</div>
</div>
<div class="container text-center">
<h3>Browse popular Posts or Login</h3>
</div>
<div class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container">
<p class="navbar-text pull-left">Copyright © 2016 Twist</p>
Contribute
</div>
</div>
<!--For signup-->
<div class="modal fade" id="signup" role="dialog" action="create.php" method="POST">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" >
<div class="modal-header">
<h4>Signup</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="signup-username" class="col-lg-2 control-label">Username:</label>
<div class="col-lg-10">
<input type="text" name="usernames" class="form-control" id="signup-username" placeholder="Username" required>
</div>
</div>
<div class="form-group">
<label for="signup-password" class="col-lg-2 control-label">Password:</label>
<div class="col-lg-10">
<input type="password" name="passwords" class="form-control" id="signup-password" placeholder="Password" required>
</div>
</div>
<div class="form-group">
<label for="signup-repassword" class="col-lg-2 control-label">Again:</label>
<div class="col-lg-10">
<input type="password" name="repassword" class="form-control" id="signup-repassword" placeholder="Retype Password" required>
<!--<script>
$('form').on('submit1',function(){
if($('#signup-password').val()!=$('#signup-repassword').val()){
alert('Password does not match!');
return false;
}
return true;
});
</script>-->
</div>
</div>
<div class="form-group">
<label for="signup-email" class="col-lg-2 control-label">Email:</label>
<div class="col-lg-10">
<input type="text" name="email" class="form-control" id="signup-email" placeholder="Email" required>
</div>
</div>
</div>
<!--<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>-->
<div class="modal-footer">
<a class="btn btn-primary" data-dismiss="modal">Close</a>
<button class="btn btn-primary" type="submit1">Sign Up</button>
</div>
</form>
</div>
</div>
</div>
<!--Login -->
<div class="modal fade" id="login" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" action="">
<div class="modal-header">
<h4>Login</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="login-username" class="col-lg-2 control-label">Username:</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="login-username" placeholder="Username" required>
</div>
</div>
<div class="form-group">
<label for="login-password" class="col-lg-2 control-label">Password:</label>
<div class="col-lg-10">
<input type="password" class="form-control" id="login-password" placeholder="Password" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-primary" data-dismiss="modal">Close</a>
<button class="btn btn-primary" type="submit">Log In</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Your query is probably not working because you override your username and password, so you probably can't login:
$username=$_POST['username'];
$password=$_POST['password'];
$repassword=$_POST['repassword'];
$email=$_POST['email'];
$taken="false";
$database="database1";
$password=""; //This one is already set!!!
$username="root"; //This one is already set!!!
EDIT:
Try adding something like this, to make sure your query is right:
$result = mysql_query('YOUR QUERY');
if (!$result) {
die('Invalid query: ' . mysql_error());
}

Need help in Redirecting to another page

<html>
<head>
<title>
Installation
</title>
<script src="public/js/jquery-1.9.0.min.js"></script>
<script src="public/js/bootstrap3/js/bootstrap.js"></script>
<link media="all" type="text/css" rel="stylesheet" href="public/js/bootstrap3/css/bootstrap.min.css">
<link media="all" type="text/css" rel="stylesheet" href="public/js/bootstrap3/css/font-awesome.min.css">
<link media="all" type="text/css" rel="stylesheet" href="public/js/bootstrap3/css/main.css">
</head>
<body>
<div
class="navbar navbar-default navbar-fixed-top">
<div
class="container">
<div
class="navbar-header">
<button
type="button"
class="navbar-toggle"
data-toggle="collapse"
data-target=".navbar-collapse">
<span
class="icon-bar"></span>
<span
class="icon-bar"></span>
<span
class="icon-bar"></span>
</button>
<a
class="navbar-brand"
href="<?php // echo base_url()?>">Kingpabel
ATN</a>
</div>
<div
class="navbar-collapse collapse">
</div>
<!--/.nav-collapse -->
</div>
</div>
<div
class="rc">
<div
class="container main">
<div
class="col-md-3">
</div>
<div
class="col-md-6">
<form
method="post"
accept-charset="utf-8"
role="form"
class="form- signin form-horizontal">
<h2
class="form-signin-heading">Installation</h2>
<div
style="margin-top: 20px;">
<label
for="host_name"
class="col-sm-3 control-label"
style="color: black">
Host
Name
</label>
<div
class="input text database_host col-md-9">
<input
type="text"
name="host_name"
class="form-control"
placeholder="Database Host Name"
autofocus=""
required="required"
id="host_name">
</div>
</div>
<div>
<label
for="database_name"
class="col-sm-3 control-label"
style="color: black">
Database
Name
</label>
<div
class="input text database_name col-md-9">
<input
type="text"
name="database_name"
class="form-control"
placeholder="Database Name"
autofocus=""
required="required"
id="database_name">
</div>
</div>
<div>
<label
for="user_name"
class="col-sm-3 control-label"
style="color: black">
User
Name
</label>
<div
class="input text user_name col-md-9">
<input
type="text"
name="user_name"
class="form-control"
placeholder="Database User Name"
autofocus=""
required="required"
id="user_name">
</div>
</div>
<div>
<label
for="password"
class="col-sm-3 control-label"
style="color: black">
Password
</label>
<div
class="input text password col-md-9">
<input
type="password"
name="password"
class="form-control"
placeholder="Database Password"
autofocus=""
id="password">
</div>
</div>
<div>
<label
for="project_url"
class="col-sm-3 control-label"
style="color: black">
Project
Url
</label>
<div
class="input text project_url col-md-8 input-group input-group-sm">
<input
style=" margin-left: 13px;"
type="text"
name="project_url"
class="form-control"
placeholder="Project URL"
autofocus=""
id="project_url"
aria-describedby="basic-addon2">
<span
class="input-group-btn">
<button
class="btn btn-default"
type="button"
style="margin-top: -15px;">/public</button>
</span>
</div>
</div>
<button
type="submit"
class="btn btn-lg btn-login btn-block">Install</button>
</form>
</div>
</div>
</div>
<section
id="bottom"
style="margin-top: 50px">
</section>
<footer
id="footer">
<div
class="container">
<div
class="footer">
<div
class="row">
<div
class="col-md-12">
</div>
</div>
</div>
</div>
</footer>
</body>
</html>
<?php
if ($_POST) {
$envFile = file_get_contents('.env');
if (isset($_POST['host_name']) && $_POST['host_name'])
$envFile = str_replace('DB_HOST=localhost', "DB_HOST= {$_POST['host_name']}", $envFile);
if (isset($_POST['database_name']) && $_POST['database_name'])
$envFile = str_replace('DB_DATABASE=homestead', "DB_DATABASE={$_POST['database_name']}", $envFile);
if (isset($_POST['user_name']) && $_POST['user_name'])
$envFile = str_replace('DB_USERNAME=homestead', "DB_USERNAME={$_POST['user_name']}", $envFile);
if (isset($_POST['password']) && $_POST['password'])
$envFile = str_replace('DB_PASSWORD=secret', "DB_PASSWORD={$_POST['password']}", $envFile);
file_put_contents('.env', $envFile);
if (isset($_POST['project_url']) && $_POST['project_url']) {
file_get_contents('index.php');
file_put_contents('index.php', "<?php
header('Location: {$_POST['project_url']}/public');
");
}
}`
In above code, after submitting the form, the idex.php is rewriiten and changes. And i wanted to redirect to another page after submitting the form. But it is not being redirected.
Not sure what all your block of codes are for but perhaps try this..
On your
if (isset($_POST['project_url']) && $_POST['project_url']) {
file_get_contents('index.php');
file_put_contents('index.php', "<?php
header('Location: {$_POST['project_url']}/public');
");
}
change to
if (isset($_POST['project_url']) && $_POST['project_url']) {
$url = $_POST['project_url'] + '/public';
header('Location: $url');
}

Categories