Problems displaying form information with php - php

I'm using php for the first time with xamp and when I want to show the data of a form I show them clear this is not the problem, the problem lies when I want to transfer my project to a virtual machine with nginx stops working when I'm showing the information, I'm clear I'm using vagrant, the link of my project on github Github Code
using xamp, image:
when I give it send if I get the information in another tab:
and using vagrant with nginx and php is quite the opposite I don't see the information
after the submit:
<?php
require "User.php";
if ( filter_has_var( INPUT_POST, 'submit' ) ) {
$first_name = $_POST['first-name'];
$last_name = $_POST['last-name'];
$direction= $_POST['address'];
$apt = $_POST['apt'];
$country = $_POST['country'];
$card_type = $_POST['card_name'];
$card_number = $_POST['last-name'];
$cvc = $_POST['cvc'];
$month = $_POST['expire-month'];
$year = $_POST['year'];
$h = new User($first_name ,$last_name,$direction,$apt,$country
,$card_type,$card_number,$cvc,$month,$year);
echo "Hello, " . $h->getFname(). "! You are ";
jsLogs($h->getFname());
}
function jsLogs($data) {
$html = "";
$coll;
if (is_array($data) || is_object($data)) {
$coll = json_encode($data);
} else {
$coll = $data;
}
$html = "<script>console.log('PHP: ".$coll."');</script>";
echo($html);
# exit();
}
?>
body {
background: rgba(33, 33, 33, 1) !important;
}
header {
position: fixed;
top: 0;
z-index: 100;
width: 100%;
}
.container {
margin-top: 80px;
text-align: center;
align-items: center;
align-content: center;
background-color: transparent;
}
.container.dos {
background-color: white;
border-radius: 5px;
}
.card {
padding: 25px;
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./css/online_pago.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.9/semantic.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.9/semantic.min.js"></script>
<title>Document</title>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#" id="click_cuatro">Inscripcion Web y metodo de pago</a>
</li>
</ul>
</div>
</nav>
</header>
<div class="container text-center col-md-5">
<!--Target Materia-->
<div class="container dos">
<div class="card">
<form class="ui form" action="./php/index.php" method="POST">
<h2 class="ui dividing header">Informacion de Compra</h2>
<div class="field">
<label>Informacion de comprador</label>
<div class="two fields">
<div class="field">
<input id="nombre_uno" type="text" name="first-name" placeholder="Primer Nombre">
</div>
<div class="field">
<input id="nombre_dos" type="text" name="last-name" placeholder="Segundo Nombre">
</div>
</div>
</div>
<div class="field">
<label>Direccion Comprador</label>
<div class="fields">
<div class="twelve wide field">
<input id="direccion" type="text" name="address" placeholder="Direccion">
</div>
<div class="four wide field">
<input id="apartamento" type="text" name="apt" placeholder="Apt #">
</div>
</div>
</div>
<div class="two fields">
<div class="field">
<label>Pais</label>
<div class="default text">Selecciona Pais</div>
<select name="country" id="pais">
<option value="">Selecciona uno</option>
<option value="">Guatemala</option>
<option value="">Belice</option>
<option value="">Costa Rica</option>
<option value="">Salvador</option>
</select>
</div>
</div>
<h4 class="ui dividing header">Informacion de comprador</h4>
<div class="field">
<label>Tipo de targeta</label>
<select name="card_name" id="tarjeta">
<option value="">Selecciona una opcion</option>
<option value="">Visa</option>
<option value="">Master Card</option>
<option value="">Paypal</option>
</select>
</div>
<div class="fields">
<div class="seven wide field">
<label>Numero de tarjeta</label>
<input id="numero" type="number" name="card_number" maxlength="16" placeholder="Tarjeta #">
</div>
<div class="three wide field">
<label>CVC</label>
<input id="cvc" type="text" name="cvc" maxlength="3" placeholder="CVC">
</div>
<div class="six wide field">
<label>Expiracion</label>
<div class="two fields">
<div class="field">
<select id="mes" class="ui fluid search dropdown" name="expire-month">
<option value="">Mes</option>
<option value="1">Enero</option>
<option value="2">Febrero</option>
<option value="3">Marzo</option>
<option value="4">Abril</option>
<option value="5">Mayo</option>
<option value="6">Junio</option>
<option value="7">Julio</option>
<option value="8">Agosto</option>
<option value="9">Septiembre</option>
<option value="10">Octubre</option>
<option value="11">Noviembre</option>
<option value="12">Diciembre</option>
</select>
</div>
<div class="field">
<input id="year" name="year" type="number" min="1900" max="2099" step="1" value="2016" placeholder="Año">
</div>
</div>
</div>
</div>
<h4 class="ui dividing header">Empaquetado</h4>
<div class="ui segment">
<div class="field">
<div class="ui toggle checkbox">
<input type="checkbox" name="gift" tabindex="0" class="show">
<label>Desea incluir empaquetado?</label>
</div>
</div>
</div>
<button type="submit" name="submit" class="btn btn-primary btn-block">Enviar</button>
</form>
</div>
</div>
</div>
</body>
</html>
Sorry to be so descriptive is that I had no other way to explain my problem to you, ied very much your help

Related

Bootstrap Modal Form doesn't insert data in MYSQL

I have a problem with the bootstrap modal, it doesn't insert data in MySQL even though i have a similar modal in the same page that updates the data.. The data is represented in tables with delete and update buttons for each row... Which both work well in the same page.. I am not using Ajax and i was hoping this would work without using any other technologies.. it's kinda odd as the update query uses the same technique and still works regardless
<?php
require_once "../db.php";
session_start();
if(!isset($_SESSION['admin'])){
header('location:login.php');
}
function redirect($url)
{
if (!headers_sent())
{
header('Location: '.$url);
exit;
}
else
{
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>'; exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../css/all.css">
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script src="../js/jquery-3.5.1.min.js"></script>
<script srC="../js/bootstrap.min.js"></script>
<style>
.nav-link{
font-size:18px;
font-weight:bold;
}
</style>
</head>
<body>
<?php
if(isset($_POST['confirmadd'])){
$code = $_POST['voyage'];
$newrow0 = $_POST['depart'];
$newrow1 = $_POST['villedep'];
$newrow2 = $_POST['arrivee'];
$newrow3 = $_POST['villearr'];
$newrow4 = $_POST['price'];
$addTrip = mysqli_query($sql,"INSERT INTO voyage VALUES('$code','$newrow0','$newrow1',$newrow2','$newrow3','$newrow4');");
if($addTrip){
redirect('dashboard.php');
}else{
echo "error";
}
}
?>
<div class="container-fluid bg-info sticky-top">
<div class="row d-flex align-items-center">
<div class="col-6 offset-1">
<h2 class="display-4 text-white">AnouBus</h2>
</div>
<div class="col-4">
<div class="navbar navbar-expand-lg navbar-light navbar-fixed-top">
<ul class="navbar navbar-nav">
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
</ul>
</div>
</div>
</div>
</div>
<h1 class="text-center">Your Trips</h1>
<button class="btn btn-primary mx-2" style="float:right;" data-toggle="modal" data-target="#addmodal">Add Trip</button>
<div class="modal fade" id="addmodal">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header"><h2 class="text-center">Update Trip</h2></div>
<div class="modal-body">
<form method="post">
<div class="form-row">
<div class="form-group col-12">
<input type="text" name="voyage" class="form-control" placeholder="Trip Code">
</div>
<div class="form-group col-12">
<input type="text" name="depart" class="form-control" placeholder="Departure Time" ?>
</div>
<div class="form-group col-12">
<input type="text" name="villedep" class="form-control" placeholder="Departure City">
</div>
<div class="form-group col-12">
<input type="text" name="arrivee" class="form-control" placeholder="Arrival Time">
</div>
<div class="form-group col-12">
<input type="text" name="villearr" class="form-control" placeholder="Arrival City">
</div>
<div class="form-group col-12">
<input type="text" name="price" class="form-control" placeholder="Price">
</div>
<div class="form-group col-12">
<input type="submit" class="form-control btn btn-success" name="confirmadd" value="confirm">
</div>
</div>
</form>
</div>
</div>
</div>
</div>

How to insert dynamically created textboxes with the same name into database?

This is my html code. It dynamically creates these textboxes but they all have the same name.
<?php
include 'db.php';
$office = $_GET['office'];
$application_name = $_GET['application_name'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Add Requirements for New Application</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/sidebar.css" rel="stylesheet">
<script type="text/javascript" src="//code.jquery.com/jquery-latest.js"></script>
<script src="js/jquery.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
<!-- Bootstrap css library -->
</head>
<style>
.header--banner {
background-image: url(cb.jpg);
background-size:100% 100%;
background-repeat: no-repeat;
}
.header--banner {
height: 45.5rem;
}
.jumbotron{
padding: 0.5em 0.6em;
}
.header--banner {
background-image: url(magic.jpg);
background-size:100% 100%;
background-repeat: no-repeat;
}
.header--banner {
height: 45.5rem;
}
.jumbotron{
padding: 0.5em 0.6em;
position: relative;
text-align: center;
color: black;
}
.green{
text-decoration: none;
font-family: Modern;
font-size: 18px;
border-radius: 5px;
padding: 5px 8px;
background-color: #27ae60;
color: #ffffff;
}
a.green:hover{
text-decoration: none;
background-color: #145a32;
color: #ffffff;
transition: 0.7s;
}
.bs-example2{
border: 3px solid black;
background: #f5f5f5;
text-align: center;
padding:20px;
margin:5px;
height:200px;
}
</style>
<body>
<header class="header--banner">
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand">
<a href="kiosk-HOMEPAGE.php">
HOME
</a>
</li>
<li>
Offices
</li>
<li>
Employees
</li>
<li>
Change Username & Password
</li>
<li>
Reports
</li>
<li>
Log Out
</li>
</ul>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="jumbotron">
<div class="container-fluid">
<img src="urdBanner.jpg" id="urdBanner" alt="Banner" style="width:100%; height:250px;">
<center><h2 style="position:relative;">Requirements</h2></center>
<p></p>
<img src="menu.jpg" class="rounded-circle" style="width:30px; height:30px;">
<br>
<br>
Previous
<br>
<br>
<form method="get" action="kiosk-NEW_CHARTER_REQUIREMENTS_insert.php">
<input type="hidden" name="office" value="<?php echo $office ?>">
<input type="hidden" name="application_name" value="<?php echo $application_name ?>">
<br>
<div class="row form-group">
<div class="col-md-2"><label for="textBox" class="col-form-label"><b>Step By Step Procedure</b></label>
</div>
<div class="col-md-2"><label for="textBox" class="col-form-label"><b>Personnel in charge</b></label>
</div>
<div class="col-md-2"><label for="textBox" class="col-form-label"><b>Time needed to complete procedure</b></label>
</div>
<div class="col-md-2"><label for="textBox" class="col-form-label"><b>Amount of fees if any</b></label>
</div>
<div class="col-md-2"><label for="textBox" class="col-form-label"><b>Required Documents</b></label>
</div>
<div class="col-md-2"><label for="textBox" class="col-form-label"><b>Procedure for the filing of complaints</b></label>
</div>
</div>
</div>
<div class="form-group fieldGroup">
<div class="input-group">
<div class="col-md-2">
<textarea name="steps[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Steps"></textarea>
</div>
<div class="col-md-2">
<textarea name="personnel[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Personnel"></textarea>
</div>
<div class="col-md-2">
<textarea name="time[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Time"></textarea>
</div>
<div class="col-md-2">
<textarea name="fees[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Fees"></textarea>
</div>
<div class="col-md-2">
<textarea name="documents[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Documents"></textarea>
</div>
<div class="col-md-2">
<textarea name="complaints[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Complaints"></textarea>
</div>
<div class="input-group-addon">
<span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span> Add
</div>
</div>
</div>
<!-- copy of input fields group -->
<div class="form-group fieldGroupCopy" style="display: none;">
<div class="input-group">
<div class="col-md-2">
<textarea name="steps[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Steps"></textarea>
</div>
<div class="col-md-2">
<textarea name="personnel[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Personnel"></textarea>
</div>
<div class="col-md-2">
<textarea name="time[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Time"></textarea>
</div>
<div class="col-md-2">
<textarea name="fees[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Fees"></textarea>
</div>
<div class="col-md-2">
<textarea name="documents[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Documents"></textarea>
</div>
<div class="col-md-2">
<textarea name="complaints[]" class="form-control" onkeyup="AutoGrowTextArea(this)" placeholder="Complaints"></textarea>
</div>
<div class="input-group-addon">
<span class="glyphicon glyphicon glyphicon-remove" aria-hidden="true"></span> Remove
</div>
</div>
</div>
<input type="submit" name="submit" class="btn btn-primary" value="SUBMIT"/>
</form>
</div>
</div>
</div>
</div>
</header>
<script type="text/javascript">
$(document).ready(function(){
//group add limit
var maxGroup = 10;
//add more fields group
$(".addMore").click(function(){
if($('body').find('.fieldGroup').length < maxGroup){
var fieldHTML = '<div class="form-group fieldGroup">'+$(".fieldGroupCopy").html()+'</div>';
$('body').find('.fieldGroup:last').after(fieldHTML);
}else{
alert('Maximum '+maxGroup+' groups are allowed.');
}
});
//remove fields group
$("body").on("click",".remove",function(){
$(this).parents(".fieldGroup").remove();
});
});
</script>
<script type="text/javascript">
// Auto-Grow-TextArea script.
// Script copyright (C) 2011 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
function AutoGrowTextArea(textField)
{
if (textField.clientHeight < textField.scrollHeight)
{
textField.style.height = textField.scrollHeight + "px";
if (textField.clientHeight < textField.scrollHeight)
{
textField.style.height =
(textField.scrollHeight * 2 - textField.clientHeight) + "px";
}
}
}
</script>
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Menu Toggle Script -->
<script>
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
</script>
</body>
</html>
this is my insert.php
<?php
if(isset($_GET['submit'])){
$con = mysqli_connect('localhost','root','','information_kiosk');
$office = $_GET['office'];
$application_name = $_GET['application_name'];
$steps = $_GET['steps'];
$personnel = $_GET['personnel'];
$time = $_GET['time'];
$fees = $_GET['fees'];
$documents = $_GET['documents'];
$complaints = $_GET['complaints'];
$totalSize = sizeof($steps);
for($i=0;$i <=$totalSize;$i++) {
$InsertSteps = (!empty($steps[$i])) ? $steps[$i] : '';
$InsertPersonnel = (!empty($personnel[$i])) ? $personnel[$i] : '';
$InsertTime = (!empty($time[$i])) ? $time[$i] : '';
$InsertFees = (!empty($fees[$i])) ? $fees[$i] : '';
$InsertDocuments = (!empty($documents[$i])) ? $documents[$i] : '';
$InsertComplaints = (!empty($complaints[$i])) ? $complaints[$i] : '';;
echo $InsertSteps;
echo "<br>";
echo $InsertPersonnel;
echo $InsertSteps;
echo "<br>";
}
}
?>
*update. with my insert code now it only shows the first row of data but not the 2nd or 3rd
only the first row gets inserted into database but the following dynamically created rows dont. My question is how could i change my syntax so that each row would insert into the database for example.
stepsColumn PersonnelColumn timeColumn feesColumn documentsColumn
array[0] array[0] array [0] array[0] array[0]
array[1] array[1] array [1] array[1] array[1]

how to fetch and display the data one by one by clicking next button

I have a quiz management system and need to fetch the data from the database and displaying the data one by one on clicking next button.
I have used ajax to insert data into database after clicking next button by using file read and write function.
I am hoping for a better and efficient solution for my problem.
<?php
$host="localhost";
$user="root";
$pass="";
$con=mysqli_connect($host,$user,$pass);//connect to database;
mysqli_select_db($con,'*****');
// Create connection
//$conn = new mysqli($host, $user, $pass);
?>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
nav {
background-color: #2196F3 !important;
}
.second {
background-color: #61BAE4 !important;
height:45px;
}
.logo {
display: inline-block;
height: 100%;
}
.logo>img {
vertical-align: middle
padding-bottom: 10px;
}
#media only screen and (max-device-width: 480px) {
#media only screen and (max-device-width: 480px) {
.card-panel{
width:280px !important;
}
nav{
width:300px !important;
}
</style>
</head>
<body style="background-color: #969696;">
<div class="row">
<nav>
<div class="nav-wrapper">
<img width="60" height="60" src="https://www.timefortest.com/images/logo1.png" alt=""><span>IBPS Portal</span>
<i class="material-icons">menu</i>
<ul class="right hide-on-med-and-down">
<li>Dashboard</li>
<li>Candidates</li>
<li>Add Question</li>
<li><a id="logout" href="logout">Logout</a></li>
<li><a id="logout" href="logout"><i class="material-icons">lock_outline</i></a></li>
</ul>
<!--<ul class="side-nav" id="mobile-demo">
<li>Dashboard</li>
<li>Candidates</li>
<li>Add Question</li>
<li><a id="logout" href="logout">Logout</a></li>
<li><i class="material-icons">lock_outline</i></li>
</ul>-->
</div>
</nav>
</div>
<!--<nav class="second">
<div class="nav-wrapper">
<div class="col s12">
Dashboard
Add Questions
Multiple Choice
</div>
</div>
</nav>-->
<?php $var=0;?><?php
//<div id="response">
?><form method="POST" action="submitanswer.php" id="answerdata">
<?php
$myfile = fopen("hitcount.txt", "r") or die("Unable to open file!");
$fh=fread($myfile,filesize("hitcount.txt"));
fclose($myfile);
$sql="SELECT description,question,choiceA,choiceB,choiceC,choiceD,choiceE,msqid FROM master_question where msqid=$fh";
if($r=mysqli_query($con,$sql))
{
while($result= $r->fetch_row())
{
?>
<div class="col s12 m12"style="background-color:Orange;">
<div class="row">
<div class="col s6 m6">
<h4 style="color:white;">DESCRIPTION</h4>
<div class="card horizontal" style="height:500px;background-color:white;">
<div class="card-stacked">
<div class="card-content">
<h5> <?php echo $result[0]?> </h4>
</div>
</div>
</div>
</div>
<div class="col s6 m6">
<h4 style="color:white;">QUESTION</h4>
<div class="card horizontal"style="height:500px;background-color:white;">
<div class="card-stacked">
<div class="card-content">
<h5><?php echo $result[1]?></h4>
</br />
<div class="card-stacked"style="padding-top:40px;">
<div class="card-content">
<input type="hidden" name="msqid" value="<?php echo $result[7]?>"/>
<p>
<input type="radio" name="group" id="test1" name="test1" value="<?php echo $result[1]?>" />
<label for="test1"><Strong> <?php echo $result[2]?></strong></label>
</p>
<br />
<p>
<input type="radio" name="group" id="test2" name="test2" value="<?php echo $result[2]?>" />
<label for="test2"><Strong><?php echo $result[3]?></strong></label>
</p>
<br />
<p>
<input type="radio" name="group" id="test3" name="test3" value="<?php echo $result[3]?>" />
<label for="test3"><Strong><?php echo $result[4]?></strong></label>
</p>
<br />
<p>
<input type="radio" name="group" id="test4" name="test4" value="<?php echo $result[4]?>" />
<label for="test4"><Strong><?php echo $result[5]?></strong></label>
</p>
<br />
<p>
<input type="radio" name="group" id="test5" name="test5" value="<?php echo $result[5]?>" />
<label for="test5"><Strong><?php echo $result[6]?></strong></label>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } } ?>
<div class="col s12 m12">
<div class="row">
<div class="col s6 m6">
<center>
<input type='button'value='back' class="btn" onclick="document.location.href='decrement.php';"/>
</center>
</div>
<div class="col s6 m6 offset-s3">
<center>
<button type="submit" id="submcq" value="Submit" name="Snext" class="btn btn-success">Next</button></center>
</center>
</div>
</div>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(".button-collapse").sideNav();<!--nav jquery starts-->
$(document).ready(function() {
Materialize.updateTextFields();
$(".button-collapse").sideNav();
$('select').material_select();
});
</script>
<script>
function copy() {
document.getElementById("label").innerHTML = document.getElementById("mySelect").value
}<!--to label the selected value-->
$(document).ready(function() {
$('select').material_select();
}); </script>
<script><!--ajax function to insert answer in answer table-->
$(document).ready(function(){
$("answerdata").on('submit',(function (e){
e.preventDefault();
$.ajax({
type:'POST',
url:'submitanswer.php',
data:$('#answerdata').serialize(),
contentType:true,
cache:true,
processData:true,
success:function(){
alert("worked");
}
});
}));
return false;
});
</script>
</body>
</html>
Insert page:
<?php
$host="localhost";
$user="root";
$pass="";
$con=mysqli_connect($host,$user,$pass);//connect to database;
mysqli_select_db($con,'******');
?>
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$msqid=$_POST['msqid'];
$answer=$_POST['group'];
$sql="INSERT INTO review(question_attend,Question_id,answerA,answerB,answerC,answerD,answerE)VALUES('','$msqid','$answer','','','','')";
$query= mysqli_query($con,$sql);
if($query)
{
echo "success";
$fp = fopen('hitcount.txt', 'c+');
flock($fp, LOCK_EX);
$count = (int)fread($fp, filesize('hitcount.txt'));
ftruncate($fp, 0);
fseek($fp, 0);
fwrite($fp, $count + 1);
flock($fp, LOCK_UN);
fclose($fp);
header("Location: newfetch.php");
}
else
{
echo mysqli_error;
}
}
?>

Onclick/Ajax on the Generate OTP without reloading?

I am having an issue that how to send the number to next page where it handles the mobile number and send a message to the user mobile number. By Using onClick method or by using ajax method can we send the message without reloading the page like below in the code.
index.php
<form method="POST" action="test.php">
<input type="text" class="form-control" name="mobile" placeholder="Mobile" maxlength="10">
<input type="text" class="form-control" name="otp" placeholder="OTP" maxlength="11" style="width: 40%; float: left;">
<input type="submit" id="btnonOtp" value="Generate OTP" class="form-control" style="background-color:#005995;width: 56.5%; float: left; margin: 0 0 0 12px; border-radius: 0;">
</form>
$('#btnonOtp').click(function()
{
$.ajax({
url: test.php,
type:'POST',
data:
{
text: mobile,
value: mobile
},
success: function(msg)
{
alert('OTP Sent');
}
});
});
Test.php
<?php
include 'send.php';
$_SESSION['smsotp'] = sms_OTP();
$num=$_POST['mobile'];
$number = $num;
//$text = 'Hi There, how are you?';
$sms_api_result = sms_Send($number, 'Please do not share the one time password with anyone. Your One Time password is: '.$_SESSION['smsotp'],$debug);
?>
If I run the test.php with mobile number passing directly then the message is delivered, but I need to pass the mobile number dynamically to $num variable.
Can any one help me where I am going wrong??
The 'data' object in your ajax isn't passing the right value.
First, add an id to the mobile tag,
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile" maxlength="10">
Second, change the input type of the buttom from type="submit" to type="button". This is required because 'submit' by default does a full page submit, even if you have an click handler defined for it. [the click function also gets executed but after than the page submit happens as well.]
And then update your click function like the one below.
$('#btnonOtp').click(function()
{
$.ajax({
url: test.php,
type:'POST',
data:
{
// The key is 'mobile'. This will be the same key in $_POST[] that holds the mobile number value.
mobile: $('#mobile').val()
},
success: function(msg)
{
alert('OTP Sent');
}
});
});
This should solve your core problem.
Debugging hint: To check if the data is being passed correctly, in test.php you can do a var_dump($_POST). This will print all the key-value pairs that were received. This should help you to analyse what is usually missing.
P.S: Also, as a good practice you might want to add a validation on the Value of the mobile number field to ensure the data entered by the user indeed looks like a mobile number.
Try below code that can help you:
NOTE: Please check if mobile number is getting in $number variable or not.
<?php
include 'send.php';
$_SESSION['smsotp'] = sms_OTP();
$number = (int) $_POST['mobile'];
//$text = 'Hi There, how are you?';
$sms_api_result = sms_Send($number, 'Please do not share the one time password with anyone. Your One Time password is: '.$_SESSION['smsotp'],$debug);
?>
M.AutoInit(),$(document).ready(function(){var e=$(window).height(),t=$(".row.main-background").height();$(document).height();t<e&&$(".row.main-background").css("height","100%"),$("body").css("height",e)});var Email=localStorage.getItem("Email"),Name=localStorage.getItem("Name"),Id=localStorage.getItem("Id"),Cognito_ID=localStorage.getItem("Cognito_ID");Email&&Name&&Id&&""!=Cognito_ID&&(window.location.href="matches.html");var selectedValue,referral,referralValue=[];function myFunction(){var e=localStorage.getItem("Cognito_ID");if(null!=(t=localStorage.getItem(e+".CrickingDuelsUserInfo")))var t=localStorage.getItem(e+".CrickingDuelsUserInfo");else $("#overlayLoader").hide(),$("#verification").modal("open",{onOpenStart:function(){$("main").addClass("filter-blur"),$("footer").addClass("filter-blur")},onCloseStart:function(){$("main").removeClass("filter-blur"),$("footer").removeClass("filter-blur")}}),document.getElementById("accountVerficationStepOne").style.display="block",document.getElementById("accountReferralCode").style.display="none";var n=JSON.parse(t);if(null==n&&(client=new AWS.CognitoSyncManager,client.openOrCreateDataset("CrickingDuelsUserInfo",function(e,t){SyncData(t)})),null!=t){null==n.ReferralTaken&&($("#overlayLoader").hide(),$("#verification").modal("open",{onOpenStart:function(){$("main").addClass("filter-blur"),$("footer").addClass("filter-blur")},onCloseStart:function(){$("main").removeClass("filter-blur"),$("footer").removeClass("filter-blur")}}),document.getElementById("accountVerficationStepOne").style.display="block",document.getElementById("accountReferralCode").style.display="none");var o=n.ReferralTaken.Key,a=n.ReferralTaken.Value;if(null!=n.SelectedState){var c=n.SelectedState.Key;n.SelectedState.Value;"SelectedState"==c&&localStorage.setItem("user_state","restricted")}"ReferralTaken"==o&&"true"==a&&($("#overlayLoader").show(),window.location.href="matches.html",cognitosync("Web","LastLoginOS"))}}function isPhoneKey(e,t){var n=e.which?e.which:event.keyCode;return!(n>31&&(n<48||n>57))&&!($(t).val().length>9)}function isOTPKey(e,t){var n=e.which?e.which:event.keyCode;return!(n>31&&(n<48||n>57))&&!($(t).val().length>0)}function delayedredirect(){window.location.href="matches.html"}function cognitosync(e,t){var n=localStorage.getItem("Cognito_ID",cognito),o=localStorage.getItem("Email",o),a=localStorage.getItem("Id",a),c=localStorage.getItem("Name",c);client=new AWS.CognitoSyncManager,client.openOrCreateDataset("CrickingDuelsUserInfo",function(c,l){SyncData(l),"stateselect"==t?(l.get("SelectedState",function(e,t){}),l.put("SelectedState",e,function(e,t){}),l.get("DeviceId",function(e,t){}),l.put("DeviceId",n,function(e,t){}),l.get("Email",function(e,t){}),l.put("Email",o,function(e,t){}),l.get("PrimaryEmail",function(e,t){}),l.put("PrimaryEmail",o,function(e,t){}),l.get("UserId",function(e,t){}),l.put("UserId",a,function(e,t){}),l.get("IsFavorites",function(e,t){}),l.put("IsFavorites","true",function(e,t){}),l.get("IsLikeFB",function(e,t){}),l.put("IsLikeFB","false",function(e,t){}),l.get("IsLikeTWITTER",function(e,t){}),l.put("IsLikeTWITTER","false",function(e,t){}),l.get("IsMusicOn",function(e,t){}),l.put("IsMusicOn","false",function(e,t){}),l.get("IsPushOn",function(e,t){}),l.put("IsPushOn","false",function(e,t){}),l.get("IsShowRatecard",function(e,t){}),l.put("IsShowRatecard","false",function(e,t){}),l.get("IsShowSocialMedia",function(e,t){}),l.put("IsShowSocialMedia","false",function(e,t){}),l.get("TriviaQuestions",function(e,t){}),l.put("TriviaQuestions","0",function(e,t){}),l.get("Country",function(e,t){}),l.put("Country","India",function(e,t){}),SyncData(l)):"LastLoginOS"==t?(l.get("LastLoginOS",function(e,t){}),l.put("LastLoginOS","Web",function(e,t){}),SyncData(l)):"PhoneNo"==t?(l.get("PhoneNo",function(e,t){}),l.put("PhoneNo",e,function(e,t){}),SyncData(l)):"GotPhoneNo"==t?(l.get("GotPhoneNo",function(e,t){}),l.put("GotPhoneNo","true",function(e,t){}),SyncData(l)):"referaltaken"==t&&(l.get("ReferralTaken",function(e,t){}),l.put("ReferralTaken",e,function(e,t){}),SyncData(l),setTimeout(delayedredirect,2e3))})}window.fbAsyncInit=function(){FB.init({appId:"1437031366566616",xfbml:!0,version:"v2.10"})},function(e,t,n){var o,a=e.getElementsByTagName(t)[0];e.getElementById(n)||((o=e.createElement(t)).id=n,o.
src="https://connect.facebook.net/en_US/sdk.js",a.parentNode.insertBefore(o,a))}(document,"script","facebook-jssdk"),document.getElementById("phonenumber_button").addEventListener("click",function(){var e=$("input[name='phone']").val();localStorage.setItem("phone_number",e);var t=Math.floor(1e3+9e3*Math.random());localStorage.setItem("otp",t);var n=localStorage.getItem("Cognito_ID");$.
ajax({url:'https://ws.cricking.com/ws5/otpsms.php?value={"userid":"'+n+'", "otp":"'+t+'", "tonumber":"'+e+'", "platform":1}',type:"GET",success:function(e){0==(e=JSON.parse(e)).StatusCode&&(document.getElementById("accountVerficationStepOne").style.display="none",document.getElementById("accountVerficationStepTwo").style.display="none",document.getElementById("accountVerficationStepThree").style.display="block")}}),cognitosync(e,"PhoneNo")}),document.getElementById("resend_code").addEventListener("click",function(){var e=localStorage.getItem("phone_number"),t=localStorage.getItem("otp"),n=localStorage.getItem("Cognito_ID");$.
ajax({url:'https://ws.cricking.com/ws5/otpsms.php?value={"userid":"'+n+'", "otp":"'+t+'", "tonumber":"'+e+'", "platform":1}',type:"GET",success:function(e){0==(e=JSON.parse(e)).StatusCode&&(document.getElementById("accountVerficationStepTwo").style.display="none",document.getElementById("accountVerficationStepThree").style.display="block")}})}),document.getElementById("otp_submit").addEventListener("click",function(){var e=$("input[name='otp1']").val()+$("input[name='otp2']").val()+$("input[name='otp3']").val()+$("input[name='otp4']").val(),t=localStorage.getItem("otp"),n=localStorage.getItem("phone_number"),o=localStorage.getItem("Cognito_ID");t==e&&($.ajax({url:'https://ws.cricking.com/ws5/userregistration.php?value={"tonumber":"'+n+'","userid":"'+o+'"}',type:"GET",success:function(e){}}),cognitosync("true","GotPhoneNo"),document.getElementById("accountVerficationStepTwo").style.display="none",document.getElementById("accountVerficationStepThree").style.display="none",document.getElementById("accountVerficationStepOne").style.display="none",document.getElementById("accountReferralCode").style.display="block")}),document.getElementById("loginBtn").addEventListener("click",function(){$("#overlayLoader").show(),FB.login(function(e){if(FB.api("/me",{fields:"email,name"},function(e){localStorage.setItem("Email",e.email),localStorage.setItem("Name",e.name),localStorage.setItem("Id",e.id);localStorage.getItem("Email"),localStorage.getItem("Name"),localStorage.getItem("Id"),localStorage.getItem("Cognito_ID")}),e.authResponse){setTimeout(myFunction,5e3);var t=e.authResponse.accessToken;if(localStorage.setItem("accesstoken",t),null!=t){var n={IdentityPoolId:"us-east-1:8017b399-3a23-45d6-8407-7271cef062ef",Logins:{"graph.facebook.com":t}};AWS.config.region="us-east-1",AWS.config.credentials=new AWS.CognitoIdentityCredentials(n),AWS.config.credentials.get(function(e,t){AWS.config.credentials.get(function(){AWS.config.credentials.identityId;client=new AWS.CognitoSyncManager,client.openOrCreateDataset("CrickingDuelsUserInfo",function(e,t){SyncData(t),t.getAllRecords(function(e,t){var n=t.length;0==t.length&&client.openOrCreateDataset("CrickingDuelsUserInfo",function(e,t){SyncData(t),t.getAllRecords(function(e,t){})});var o=localStorage.getItem("_internal._metadata"),a=JSON.stringify(o);JSON.parse(a);if(t.length>1){for(var c=0;c<n;c++)if("ReferralTaken"==t[c].key){referralValue={userval:t[c].value};break}localStorage.setItem("userVal",referralValue.userval)}})}),cognito=AWS.config.credentials.identityId,localStorage.setItem("Cognito_ID",cognito)})})}}})}),$("#select_state").click(function(){var e=document.getElementById("user_state");e=$("#user_state option:selected").val();if(""==(selectedValue=e))return M.toast({html:"Select a state"}),!1;"Assam"==selectedValue?(cognitosync("true","referaltaken"),cognitosync(selectedValue,"stateselect"),document.getElementById("accountReferralCode").style.display="none",document.getElementById("accountVerficationStepOne").style.display="none"):(cognitosync(selectedValue,"stateselect"),document.getElementById("accountVerficationStepTwo").style.display="block",document.getElementById("accountReferralCode").style.display="none",document.getElementById("accountVerficationStepOne").style.display="none")}),$("#final_refer").click(function(){var e=document.getElementById("refer_code").value,t=localStorage.getItem("Cognito_ID"),n=localStorage.getItem("Email"),o=localStorage.getItem("Name");$.getJSON('https://ws.cricking.com/ws4/?action=playerreferal&value={"UserId":"'+t+'","EmailId":"'+n+'","Code":"'+e+'","UserName":"'+o+'"}').success(function(e){if("0"==e.StatusCode)M.toast({html:"Congrats! Your referral code is valid. Take control! Join Hybrid Fantasy and enjoy Cricking Duels."}),cognitosync("true","referaltaken"),cognitosync("Web","LastLoginOS"),$("#overlayLoader").show();else{if("1"==e.StatusCode)return M.toast({html:"Oops! You entered an invalid referral code. Please check and re-enter the valid referral code."}),!1;if("2"==e.StatusCode)return M.toast({html:"Oops! You entered an invalid referral code. Please check and re-enter the valid referral code."}),!1}})}),$("#skip_refer_code").click(function(){cognitosync("true","referaltaken"),
cognitosync("Web","LastLoginOS"),$("#overlayLoader").show()});
<!DOCTYPE html>
<html>
<head>
<title>CrickingDuels</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.4.14.min.js"></script>
<script src="js\cognito\dist\amazon-cognito.min.js"></script>
<link href="css\materialize.min.css" rel="stylesheet">
<link href="css\fontawesome\css\font-awesome.min.css" rel="stylesheet">
<link href="css\common.css" rel="stylesheet">
<link href="css\login.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed|Rubik" rel="stylesheet">
<script src="https://use.typekit.net/wmk2lex.js"></script>
<script>try{Typekit.load({ async: true });}catch(e){}</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-54357006-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-54357006-1');
</script>
</head>
<body class="white">
<main>
<div class="row main-background">
<div class="">
<div class="col s12 m12 l12 relative" style="padding: 50px 10%;">
<div class="">
<div class="row no-margin">
<div class="col s12 m12 l12">
<h3 class="blue-text text-darken-4 margin-5-0 bold">Let's</h3>
<h3 class="blue-text text-darken-4 margin-5-0 bold">Play</h3>
<h3 class="blue-text text-darken-4 margin-5-0 bold">Fantasy!</h3>
</div>
</div>
<div class="row margin-10-0" style="margin-bottom: 30% !important;">
<div class="col s12 m12 l12">
<p class="font-16 blue-text text-darken-4 margin-5-0 bold">Play fantasy</p>
<p class="font-16 blue-text text-darken-4 margin-5-0 bold">& win cash daily!</p>
</div>
</div>
<div class="row no-margin" style="position: absolute;bottom: 0;left: 0;width: 100%;padding: 0 20px;">
<div class="col s12 m12 l12">
<div class="row add-amount no-margin">
<div class="col s12 m6 l6 no-padding push-l3 push-m3 center-align">
<button id="loginBtn" class="btn btn-flat blue darken-3 white-text width-100" style="text-transform: none;"><i class="fa fa-facebook white-text font-14"></i> Sign in with Facebook</button>
</div>
</div>
</div>
</div>
</div>
<div style="margin-bottom: 0;"></div>
</div>
</div>
</div>
</main>
<div class="modal" id="verification">
<div class="modal-content blue">
<div class="row no-margin" id="accountVerficationStepOne">
<div class="col s12 m12 l12 no-padding center-align">
<div class="img-block">
<img src="images\state_selection.png" class="img responsive-img img-center" width="150">
</div>
<!-- <p class="uppercase blue-text text-darken-4 bold">State Selection</p> -->
<p class="uppercase blue-text text-darken-4">Residents of the states of Assam and Odisha, and where otherwise prohibited by law are not eligible to enter pay leagues, you can play free Leagues</p>
<div class="form-group" style="padding-top: 30px;">
<select class="" name="state" id="user_state">
<option value="">--Select a state--</option>
<option value="Andaman and Nicobar">Andaman and Nicobar</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Delhi">Delhi</option>
<option value="Dadra and Nagar Haveli">Dadra and Nagar Haveli</option>
<option value="Daman and Diu">Daman and Diu</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Lakshadweep">Lakshadweep</option>
<option value="Madhya Pradesh">Madhya Pradesh</option>
<option value="Maharashtra">Maharashtra</option>
<option value="Manipur">Manipur</option>
<option value="Meghalaya">Meghalaya</option>
<option value="Mizoram">Mizoram</option>
<option value="Nagaland">Nagaland</option>
<option value="Odisha">Odisha</option>
<option value="Punjab">Punjab</option>
<option value="Puducherry">Puducherry</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Sikkim">Sikkim</option>
<option value="Tamil Nadu">Tamil Nadu</option>
<option value="Telangana">Telangana</option>
<option value="Tripura">Tripura</option>
<option value="Uttarakhand">Uttarakhand</option>
<option value="Uttar pradesh">Uttar Pradesh</option>
<option value="West bengal">West bengal</option>
</select>
<button class="btn btn-flat gradient-background white-text margin-10-0" id="select_state">Next</button>
</div>
</div>
</div>
<div class="row no-margin" id="accountVerficationStepTwo" style="display: none;">
<div class="col s12 m12 l12 no-padding center-align">
<div class="img-block">
<img src="images\mobile_number.png" class="img responsive-img img-center" width="150">
</div>
<p class="uppercase blue-text text-darken-4 bold">Mobile Verification</p>
<p class="uppercase blue-text text-darken-4">Please enter your mobile number</p>
<div class="form-group" style="padding-top: 30px;">
<input type="text" name="phone" id="phone" class="browser-default" onkeypress="return isPhoneKey(event, this)" placeholder="+91">
<button class="btn btn-flat gradient-background white-text margin-10-0" id="phonenumber_button">Next</button>
</div>
</div>
</div>
<div class="row no-margin" id="accountVerficationStepThree" style="display: none;">
<div class="col s12 m12 l12 no-padding">
<div class="img-block">
<img src="images\sms_otp.png" class="img responsive-img img-center" width="150">
</div>
<p class="uppercase blue-text text-darken-4 bold center-align">Mobile Verification</p>
<p class="uppercase blue-text text-darken-4 center-align">Please enter the OTP you have received on your registered mobile number</p>
<div class="form-group center-align" style="padding-top: 30px;margin: 0 auto;">
<input type="text" name="otp1" id="otp1" class="browser-default inline center-align" style="width: 16%; padding: 0 5px;" onkeypress="return isOTPKey(event,this)">
<input type="text" name="otp2" id="otp2" class="browser-default inline center-align" style="width: 16%; padding: 0 5px;" onkeypress="return isOTPKey(event,this)">
<input type="text" name="otp3" id="otp3" class="browser-default inline center-align" style="width: 16%; padding: 0 5px;" onkeypress="return isOTPKey(event,this)">
<input type="text" name="otp4" id="otp4" class="browser-default inline center-align" style="width: 16%; padding: 0 5px;" onkeypress="return isOTPKey(event,this)">
</div>
<div class="form-group center-align resend_code">
Resend code
</div>
<div class="form-group center-align">
<button class="btn btn-flat gradient-background white-text margin-10-0" id="otp_submit">Next</button>
</div>
</div>
</div>
<div class="row no-margin" id="accountReferralCode" style="display: none;">
<div class="col s12 m12 l12 no-padding">
<div class="img-block">
<img src="images\sms_otp.png" class="img responsive-img img-center" width="150">
</div>
<p class="uppercase blue-text text-darken-4 bold center-align">Referral code</p>
<p class="uppercase blue-text text-darken-4 center-align">We want to give you a head start. If you have a referral code, enter it below and we will load ₹ 89 in your wallet to join the leagues.</p>
<div class="form-group center-align" style="padding-top: 30px;margin: 0 auto;">
<input type="text" name="refer_code" id="refer_code">
</div>
<div class="form-group center-align resend_code">
Skip
</div>
<div class="form-group center-align">
<button class="btn btn-flat gradient-background white-text margin-10-0" id="final_refer">Submit</button>
</div>
</div>
</div>
</div>
</div>
<div id="overlayLoader" style="display: none;">
<div class="loader">
<div class="progress thin-4">
<div class="indeterminate"></div>
</div>
</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="js\materialize.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js" integrity="sha256-rsPUGdUPBXgalvIj4YKJrrUlmLXbOb6Cp7cdxn1qeUc=" crossorigin="anonymous"></script> -->
<!-- <script src="js/dust-full.min.js"></script>
<script src="js/dust-helpers.min.js"></script> -->
<script src="js\cognitosync.js"></script>
<script src="js\login.js"></script>
<!-- <script type="text/javascript" src="js/javascript.js"></script> -->
</html>

php & mysql form data not been inserted in database

I am trying to insert my form data into mysql, but when I enter the details and submit it, I am not able to get the data in database. May I know where am I wrong?
<?php
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
echo "jgj"
$servername = "localhost";
$username = "username";
$password = "";
$dbname = "sudhar";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "connected"
}
if(isset($_POST['submit']))
{
$Firstname=mysqli_real_escape_string($conn,$_POST['Firstname']);
$Lastname=mysqli_real_escape_string($conn,$_POST['Lastname']);
$Username=mysqli_real_escape_string($conn,$_POST['Username']);
$email=mysqli_real_escape_string($conn,$_POST['email']);
$Password=mysqli_real_escape_string($conn,$_POST['Password']);
$sql="insert into useraccount(Firstname,Lastname,Username,email,Password)values('$Firstname','$Lastname','$Username','$Password','$email')";
$result=mysqli_query($conn,$sql)
echo "data inserted"
or die(mysql_error());
}
?>
html,body
{
margin:0px;
height:100%;
}
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 60%;
margin: auto;
}
.content
{
width:100%;
height:400px;
}
.signup
{
height:500px;
}
.footer
{
position:relative;
background-color:black;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>ASK</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="boot.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-md-6">
<h1>school name</h1>
</div>
<div class="col-md-6">
<img src="../project/photo/l.png" height="150px"/>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#mynavbar">schoolName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li><a href="about.html" target=_self>About Us</a></li>
<li><a href="infra.html" target=_self>Infrastructure</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="">Administration<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>staff login</li>
<li>staff details</li>
<li>class handling</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="signup">
<form method="post" class="form-horizontal" action="user.php">
<div class="form-group">
<div class="col-xs-3">
<label for="Firstname">Firstname:</label>
<input type="text" name="Firstname" class="form-control" id="fnmae" placeholder="Enter Firstname">
</div></div>
<div class="form-group">
<div class="col-xs-3">
<label for="Lastname">Lastname:</label>
<input type="text" name="Lastname" class="form-control" id="lnmae" placeholder="Enter Lastname">
</div></div>
<div class="form-group">
<div class="col-xs-3">
<label for="Username">Username:</label>
<input type="text" name="Username" class="form-control" id="unmae" placeholder="Enter Username">
</div></div>
<div class="form-group">
<div class="col-xs-3">
<label for="email">Email:</label>
<input type="email" name="email" class="form-control" id="email" placeholder="Enter email">
</div></div>
<div class="form-group">
<div class="col-xs-3">
<label for="pwd">Password:</label>
<input type="Password" name="Password" class="form-control" id="pwd" placeholder="Enter password">
</div></div>
<button type="submit" class="btn btn-default">Submit</button><br>
</form>
</div>
</div>
<div class="footer nav">
<p> Copyrights# © WWW.schools.com</p>
</div>
</body>
</html>
$query=mysqli_query($con,"insert into useraccount('Firstname','Lastname','Username','email','Password')values($Firstname,$Lastname,$Username,$email,$Password)");
and change button name
If regardless to other errors, and if you just guess how to have your query run:
There are some reserved naming convention, and maybe your code could works in some situation, put column names between quotation marks.
INSERT into useraccount
('Firstname','Lastname','Username','email','Password')
VALUES
($Firstname,$Lastname,$Username,$Password,$email);
I suggest you escape characters in variables you put into query.
This is a valuable article for you:
http://php.net/manual/en/function.mysql-real-escape-string.php
But: Do not use this solution for production, as using login credential while learning the code is the worst possible way.
change
<button type="submit" class="btn btn-default">Submit</button><br>
to
<button type="submit" name="submit class="btn btn-default">Submit</button><br>
because $_POST['submit'] is not set since you forgot to set the name

Categories