how to add data to an sql server - php

Hi guys I started creating a website 2 months ago and just a week before I hit rock bottom in making it. My problem is that I can't get it to add data to my SQL database which I created using the SQL database and phpmyadmin provided with my 000webhost.com package.
Here is my PHP code with HTML at the bottom:
<?php
$con=mysqli_connect("mysql11.000webhost.com","xxxxxxxx","xxxxxxxxx","xxxxxxxx");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$mysqli_query("INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob#gmail.com', 'gigtit',bob_name)");
echo"adding is done";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Friend It sign up</title>
<link rel="stylesheet" type="text/css" href=" css/bootstrap.css">
<link rel="stylesheet" type="text/css" href=" css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href=" css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href=" css/index.css">
</head>
<body>
<ul class="nav nav-pills">
<li>Home</li>
<li>About</li>
<label class="web-name">Friend It</label>
</ul>
<div class="page-header">
<h1>Sign up</h1>
</div>
<div class="container">
<div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-col-sm-8 col-sm-offset-2">
<div class="panel panel-primary" >
<div class="panel-heading">
<div class="panel-title">Sign up</div>
</div>
<div style="padding-top:30px" class="panel-body" >
<from action="connect.php" method="post">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input id="login-username" name="user" type="text" class="form-control" name="username" value="" placeholder="email">
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<input id="login-username" type="text" name="fullname" class="form-control" name="username" value="" placeholder="Full Name">
</form>
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input id="login-password" name="pass" type="password" class="form-control" name="password" placeholder="Password">
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-repeat"></i></span>
<input id="login-password" type="password" class="form-control" name="passwordre" placeholder="Re-type Password">
</div>
<div style="margin-top:10px" class="form-group">
<div style="margin-left:140px" class="col-sm-12 controls">
<a id="btn-signup" href="connect.php" class="btn btn-primary" type="submit">Sign up</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
You can also check out the website by going to friendit.meximas.com

the function is mysqli_query() not $mysqli_query(), I don't know why the others did not catch this.
mysqli_query("INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob#gmail.com', 'gigtit', 'bob_name')");
Since its the procedural style you can pass the connection as the first parameter:
mysqli_query($con, "INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob#gmail.com', 'gigtit', 'bob_name')");

Try this query, I think only problem is value for name column should be wrapped by single quote, which is missing.
$mysqli_query("INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob#gmail.com', 'gigtit','bob_name')");
Hope this help :)

the problem is in your query, try this one:
$mysqli_query("INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob#gmail.com', 'gigtit','bob_name')");

for your second error (edit: Which you posted as a comment) its about wrong parenthesis
you can check PHP Error: Function name must be a string
or post that line which cause the error.

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.

I am able to display only first word of fullname i want to display full string

<?php
include "dbconfig.php";
session_start();
if (isset($_SESSION["session_admin"])=="" || $_SESSION["session_admin"]=="") {
header("location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="bootstrap.css">
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style type="text/css">
.form-control
{
width: 300px;
/*text-transform: uppercase;*/
}
.email
{
/*ext-transform: lowercase;*/
}
.btn
{
color: white;
}
.error{
color: red;
}
.right-addon input { padding-right: 0px; }
.right-addon .glyphicon { right: 0px;}
</style>
</head>
<script type="text/javascript">
</script>
<body>
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<center><strong><h2>Edit</h2></strong></center>
</div>
<div class="panel-body">
<?php
$get_id=$_GET["id"];
$result=mysqli_query($db,"select * from signup where sid=$get_id");
while ($row=mysqli_fetch_array($result)) {
?>
<form method="post" id="signup" role="form">
<div class="row">
<div class="form-group col-xs-7">
<div class="inner-addon left-addon">
<span class="glyphicon glyphicon-user"></span>
<input type="text" class="form-control" name="fullname" placeholder="Fullname" value=<?php echo $row["sfullname"]; ?>>
</div>
</div>
<div class="form-group col-xs-3">
<div class="inner-addon left-addon">
<span class="glyphicon glyphicon-envelope"></span>
<input type="text" class="form-control email" name="email" placeholder="Email address">
</div>
</div>
<div class="form-group col-xs-7">
<div class="inner-addon left-addon">
<span class="glyphicon glyphicon-earphone"></span>
<input type="text" class="form-control" name="mobile" placeholder="Mobile number">
</div>
</div>
<div class="form-group col-xs-3">
<div class="inner-addon left-addon">
<input type="date" class="form-control" name="dob">
</div>
</div>
<div class="form-group col-xs-7">
<div class="inner-addon left-addon">
<span class="glyphicon glyphicon-map-marker"></span>
<input type="text" class="form-control" name="address" placeholder="Address">
</div>
</div>
<div class="form-group col-xs-3">
<select class="form-control" name="state" style="width: 100px;" >
<option value="">State</option>
<option>Gujrat</option>
<option>Maharashtra</option>
<option>Goa</option>
<option>Rajasthan</option>
</select>
</div>
<div class="form-group col-xs-7">
<div class="inner-addon right-addon">
<input type="password" id="password" class="form-control" name="createpass" placeholder="Create password">
</div>
</div>
<div class="form-group col-xs-3">
<select class="form-control" name="city" style="width: 100px;" >
<option value="">City</option>
<option>Ahmedabad</option>
<option>Mumbai</option>
<option>Kolkata</option>
<option>Delhi</option>
<option>Banglore</option>
<option>Chennai </option>
</select>
</div>
<div class="form-group col-xs-7">
<div class="inner-addon right-addon">
<input type="password" class="form-control" name="confirmpass" placeholder="Confirm password">
</div>
</div>
<div class="form-group col-xs-3">
<strong>Gender</strong>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
</div>
</div>
<div class="form-group ">
<center>
<!-- <input type="submit" name="sbt" value="Register" class="form-control btn-success"> -->
<button type="submit" name="sbt" class="btn"><span style="color: white;">Update</span></button>
</center>
</div>
</form>
<?php }?>
</div>
</div>
<!-- Jquery Plugin CDN -->
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<!-- Jquery Validation Plugin CDn -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery-validation#1.17.0/dist/jquery.validate.js"></script>
<!-- Linking Page to index.js for form validation -->
<script type="text/javascript" src="index.js"></script>
</body>
</html>
I want to display wholw string from my database into textbox but I am only able to display first word of that string. How can I display the whole string?
I have attached 2 images for reference, please look at them. In my database there is "abc xyz" in sfullname column and when I am selecting it only "abc" is displaying in the textbox...please refer images Please look this Database table
I want to display wholw string from my database into textbox but I am only able to display first word of that string. How can I display the whole string?
I have attached 2 images for reference, please look at them. In my database there is "abc xyz" in sfullname column and when I am selecting it only "abc" is displaying in the textbox...please refer images Please look this Database table
In your first input look here:
value=<?php echo $row["sfullname"]; ?>
Your value attribute is unquoted. Any spaces will result in the output you describe. Besides, it should be html-escaped as well, as a stray quote in the data will result in the same behavior.
Fix by quoting correctly:
value="<?php echo htmlspecialchars($row["sfullname"], ENT_QUOTES); ?>"
While I am here. empty() fits better for your if statement, so you probably want something more like:
if (empty($_SESSION["session_admin"])) {
header("location:index.php");
exit;
}
Don't forget to exit after a header redirection, else the rest of your code is executed.
Plus mandatory nag about using prepared queries - else you are open to SQL injection.
You are missing double quotes in the value attributes, your code looks like:
<input type="text" class="form-control" name="fullname" placeholder="Fullname" value=<?php echo $row["sfullname"]; ?>>
Plese try below one instead of your code:
<input type="text" class="form-control" name="fullname" placeholder="Fullname" value="<?php echo $row["sfullname"]; ?>">

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.

The character encoding is not declared

I am using form to update my database through a php file but I am getting following error in Firefox :
The character encoding of the HTML document was not declared. The
document will render with garbled text in some browser configurations
if the document contains characters from outside the US-ASCII range.
The character encoding of the page must be declared in the document or
in the transfer protocol.
And following error in Chrome:
Calling Element.createShadowRoot() for an element which already hosts
a shadow root is deprecated. See
https://www.chromestatus.com/features/4668884095336448 for more
details
A complete blank page is shown once I click the submit button with above console message.
I am attaching my html and php file for the better idea.
register.html
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Info</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="bootstrap/css/scheduler.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container container-table" >
<div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2" >
<div class="panel panel-info" style="background-color:#ccc;">
<div class="panel-heading"style="background-color:#990000;">
<div class="panel-title" style="color:white; text-align:center">Register</div>
<!-- <div style="float:right; font-size: 80%; position: relative; top:-10px">Forgot password?</div>-->
</div>
<div style="padding-top:30px" class="panel-body" >
<div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
<form action="register.php" id="loginform" class="form-horizontal" role="form" method="post">
<div style="margin-bottom: 20px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-education"></i></span>
<input id="login-username" type="text" class="form-control" name="sbuid" value="" placeholder="SBU ID">
</div>
<div style="margin-bottom: 20px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input id="login-username" type="text" class="form-control" name="stuName" value="" placeholder="Name">
</div>
<div style="margin-bottom: 20px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input id="login-username" type="text" class="form-control" name="emailID" value="" placeholder="Email ID">
</div>
<div style="margin-bottom: 20px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
<input id="login-username" type="text" class="form-control" name="contactInfo" value="" placeholder="Contact No.">
</div>
<div style="margin-bottom: 15px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input id="login-password" type="password" class="form-control" name="pass" placeholder="Password">
</div>
<div style="margin-top:10px;text-align:center" class="form-group">
<!-- Button -->
<div class="col-sm-12 controls" >
<input type = "submit" value= "Register" class="btn btn-success"></input>
</div>
</div>
</form>
<div style="text-align:center">
<strong>Sign In </strong>
</div>
</div>
</div>
</div>
</div>
<div id = "footer" class="container-fluid text-center">
<p>INFO</p>
</div>
</body>
</html>
register.php
<?php
$sbuidreg = isset($_POST['sbuid']) ? htmlspecialchars($_POST['sbuid']):"NA";
$passreg = isset($_POST['pass']) ? htmlspecialchars($_POST['pass']):"NA";
$stuNamereg = isset($_POST['stuName']) ? htmlspecialchars($_POST['stuName']):"NA";
$emailIDreg = isset($_POST['emailID']) ? htmlspecialchars($_POST['emailID']):"NA";
$contactInforeg = isset($_POST['contactInfo']) ? htmlspecialchars($_POST['contactInfo']):"NA";
$myserver = "127.0.0.1:3306"
$database = "tcpscheduler";
$password = "rootpassword";
$username = "root";
// Connect to database
$con = mysqli_connect($myserver, $username, $password, $database);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
mysqli_query($con,"INSERT INTO `loginsection` VALUES('$sbuidreg', '$passreg','$stuNamereg', '$emailIDreg','$contactInforeg')") or die("Strange Error");
echo "Account Created";
mysqli_close($con);
header('Location: index.html');
?>

Form submitting but mysql query not properly functioning [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
The following code gives a signup form that i created but unfortunately though it works the mysql query fails and returns the error message unsuccessfull signup! how can i correct this?
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Theme Made By www.w3schools.com - No Copyright -->
<title>Arsiri Textile </title>
<meta charset="utf-8">
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Theme Made By www.w3schools.com - No Copyright -->
<title>Arsiri Textile </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/basic.css">
<style>
</style>
</head>
<body id="myPage" data-spy="scroll" data-target=".navbar" data-offset="60">
<div class="header" style="height:60px;background:#330d00;width:1350px">
<a class="navbar-brand" href="#myPage">ARSIRI TEXTILE |</a>
<ul class="nav navbar-nav navbar-left">
</ul>
<ul class="nav navbar-nav navbar-right">
<li>About Us</li>
<li>Contact Us</li>
<li>Login</li>
<li> Signup</li>
</ul>
</div>
<div class="image" style="height:530px; width:1350px" >
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css" />
</head>
<body>
<div class="panel panel-default">
<div class="panel-heading" style="background:#330d00;">
<h3 class="panel-title">Customer Registration</h3><br>
</div>
<div class="panel-body" >
<form class="form-horizontal" role="form" action="signupaction.php" method="post" >
<div class="form-group">
<label for="name" class="col-sm-2 control-label">First Name</label>
<div class="col-sm-10" style="width:300px">
<input type="text" class="form-control" id="name" name="firstname" required>
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Last Name</label>
<div class="col-sm-10" style="width:300px">
<input type="text" class="form-control" id="name" name="lastname" required>
</div>
</div>
<div class="form-group">
<label for="Address" class="col-sm-2 control-label">Address</label>
<div class="col-sm-10" style="width:300px">
<textarea class="form-control" class="form-control" name="address"></textarea>
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Contact No.</label>
<div class="col-sm-10" style="width:300px">
<input type="text" maxlength="10" class="form-control" id="name" name="contactno" required>
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">E-Mail</label>
<div class="col-sm-10" style="width:300px">
<input type="email" class="form-control" id="name" name="emailaddress" required>
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10" style="width:300px">
<input type="password" class="form-control" id="pass" name="password" required>
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Confirm password
</label>
<div class="col-sm-10" style="width:300px">
<input type="password" class="form-control" id="confirmpass" name="cpassword" required><br>
</div>
</div>
<div class="panel-footer" style="overflow:hidden;text-align:left;">
<div class="col-sm-offset-2 col-sm-10">
<input class="btn btn-success btn-sm" type=submit name=submit value=Submit >
<input class="btn btn-success btn-sm" type=reset name=reset value=Cancel>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</div>
<div class="footer " style="background:#330d00; height:60px ;width:1350px ">
<p align="center" > Asiri all rights reserved</p>
</div>
The relevant php script(ignupaction.php) for the above html form is as follows
<?php
//importing db.php in the includes folder
require("includes/db.php");
$fname=$_POST["firstname"];
$lname=$_POST["lastname"];
$address=$_POST["address"];
$contact=$_POST["contactno"];
$email=$_POST["emailaddress"];
$password=$_POST["password"];
$cpassword=$_POST["cpassword"];
$sql="INSERT INTO `signup` VALUES ('$fname','$lname','$address','$contact','$email','$password',$cpassword')";
$result=mysqli_query($db,$sql);
if(!$result){
echo "Unsuccessful signup";
}
else{
echo "Successful signup";
}
?>
when the form is submitted it returns unsuccessful signup! how can i correect this?
$sql="INSERT INTO signup VALUES ('$fname','$lname','$address','$contact','$email','$password',$cpassword')";
you are missing a ' on the last variable. you have '$password',$cpassword' <----- missing '. Also change the ticks around 'signup'.
Try this :
$sql="INSERT INTO 'signup' VALUES ('$fname','$lname','$address','$contact','$email','$password','$cpassword')";

Categories