I'm hoping one of you experts can point out the error in my code for my database connection in my PHP. My page wont work at all.
I'm trying to create new users into my database. I've checked all the names in my table and they match up perfectly.
Here is my function:
<?php include('connection.php'); ?>
<?php
function createUser()
{
if(isset($_POST['submit']))
{
global $connection;
$username = $_POST['username'];
$password = $_POST['password'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$emailAddress = $_POST['emailAddress'];
$phoneNumber = $_POST['phoneNumber'];
$privilege = $_POST['privilege'];
$query = "INSERT INTO users(username,password,firstName,lastName,emailAddress,phoneNumber,privilege)";
$query .= "VALUES ('$username', '$password','$firstName','$lastName','$emailAddress','$phoneNumber','$privilege')";
$result = mysqli_query($connection, $query);
if(!$result)
{
die('Query Failed' . mysqli_error());
}
else
{
echo '<div class="modal-footer">
<div class="alert alert-success alert-block fade in" id="successAlert">
<button class="close" type="button" data-dismiss="alert" aria-label="close"><span aria-hidden="true">×</span></button>
<h4>Success!</h4>
<p>New user registered successfully</p>
</div>
</div>';
die;
}
}
}
?>
Here is my HTML:
I call the header.php into my home page but the functions are also called on in there.
<?php include('connection.php'); ?>
<?php include('functions.php'); ?>
<?php createUser(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<button class="navbar-toggle" data-target=".navbar-responsive-collapse" data-toggle="collapse" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- end responsive-dropdown -->
RichmondMC
<div class="nav-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav">
<li>Movie Database</li>
<li>Gallery</li>
<li>Ratings</li>
</ul>
<!-- end navbar-nav -->
<ul class="nav navbar-nav pull-right">
<li class="dropdown">
<span class="glyphicon glyphicon-user"></span> My Account <strong class="caret"></strong>
<ul class="dropdown-menu">
<li><span class="glyphicon glyphicon-wrench"></span> Settings</li>
<li><span class="glyphicon glyphicon-list-alt"></span> Register New User</li>
<li class="divider"></li>
<li><span class="glyphicon glyphicon-play"></span> Sign In</li>
<li><span class="glyphicon glyphicon-off"></span> Sign Out</li>
</ul>
<!-- end dropdown-menu -->
</li>
<!-- end dropdown -->
</ul>
<!-- end myAccount-dropdown -->
</div>
<!-- end nav-collapse -->
</div>
<!-- end container -->
</div>
<!-- end navbar -->
<div class="modal fade" id="registerModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
×
<h4 class="modal-title"><span class="glyphicon glyphicon-th-list"></span> New User Registration </h4>
</div>
<!-- end modal-header -->
<div class="modal-body">
<h5>Enter the New Members details including username/password to complete registration</h5><br>
<form action="" class="form-horizontal" method="post">
<div class="form-group">
<label for="username" class="col-lg-4 control-label">Username:</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="username" name="username" placeholder="Username" required>
</div>
</div>
<div class="form-group">
<label for="password" class="col-lg-4 control-label">Password:</label>
<div class="col-lg-8">
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
</div>
</div>
<div class="form-group">
<label for="firstName" class="col-lg-4 control-label">First Name:</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="First Name" required>
</div>
</div>
<div class="form-group">
<label for="lastName" class="col-lg-4 control-label">Last Name:</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Last Name" required>
</div>
</div>
<div class="form-group">
<label for="emailAddress" class="col-lg-4 control-label">Email Address:</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="emailAddress" name="emailAddress" placeholder="Email Address" required>
</div>
</div>
<div class="form-group">
<label for="phoneNumber" class="col-lg-4 control-label">Phone Number:</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="phoneNumber" name="phoneNumber" placeholder="Phone Number" required>
</div>
</div>
<div class="form-group">
<label for="role" class="col-lg-4 control-label">Privileges</label>
<div class="col-lg-8">
<select name="Role" id="role" class="form-control">
<option value="member" name="privilege">Member</option>
<option value="admin" name="privilege">Admin</option>
</select>
</div>
</div>
<button class="btn btn-success pull-right" type="submit" name="submit" id="alertMe">Submit</button><br>
</form>
<!-- end form -->
</div>
<!-- end modal-body -->
</div>
<!-- end modal-content -->
</div>
<!-- end modal-dialog -->
</div>
<!-- end modal -->
</body>
</html>
Related
</div>
<div class="row block-9">
<div class="col-md-6 order-md-last d-flex">
<form action="#" class="bg-white p-5 contact-form">
<form class="=contact-form" action="contact.php" method="post"
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Email">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Subject">
</div>
<div class="form-group">
<textarea name="" id="" cols="30" rows="7" class="form-control" placeholder="Message"></textarea>
</div>
<div class="form-group">
<input type="submit" value="Send Message" class="btn btn-primary py-3 px-5">
</div>
</form>
</div>
<div class="col-md-6 d-flex">
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d14884.226370030301!2d79.103842!3d21.150146!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x5106808b025223d!2sRajshri%20Traders!5e0!3m2!1sen!2sid!4v1566792666441!5m2!1sen!2sid" width="600" height="450" frameborder="0" style="border:0;" allowfullscreen=""></iframe>
</div>
</div>
</div>
</section>
<footer class="ftco-footer ftco-section">
<div class="container">
<div class="row">
<div class="mouse">
<a href="#" class="mouse-icon">
<div class="mouse-wheel"><span class="ion-ios-arrow-up"></span></div>
</a>
</div>
</div>
<div class="row mb-5">
<div class="col-md">
<div class="ftco-footer-widget mb-4">
<h2 class="ftco-heading-2">Rajshri Traders</h2>
<p>We provide the best Cctvs.</p>
<ul class="ftco-footer-social list-unstyled float-md-left float-lft mt-5">
<li class="ftco-animate"><span class="icon-twitter"></span></li>
<li class="ftco-animate"><span class="icon-facebook"></span></li>
<li class="ftco-animate"><span class="icon-instagram"></span></li>
</ul>
</div>
</div>
<div class="col-md">
<div class="ftco-footer-widget mb-4 ml-md-5">
<h2 class="ftco-heading-2">Menu</h2>
<ul class="list-unstyled">
<li>Shop</li>
<li>About</li>
<li> </li>
<li> </li>
</ul>
</div>
</div>
<div class="col-md-4">
<div class="ftco-footer-widget mb-4">
<h2 class="ftco-heading-2"> </h2>
<div class="d-flex">
<ul class="list-unstyled mr-l-5 pr-l-3 mr-4">
<li> </li>
<li> </li>
<li> </li>
<li> </li>
</ul>
<ul class="list-unstyled">
<li> </li>
<li> </li>
</ul>
</div>
</div>
</div>
<div class="col-md">
<div class="ftco-footer-widget mb-4">
<h2 class="ftco-heading-2">Have a Questions?</h2>
<div class="block-23 mb-3">
<ul>
<li><span class="icon icon-map-marker"></span><span class="text">Plot No 1, Nike buildings, Fawara Chouk,Gandhibag, Nagpur, Maharashtra 440032, India</span></li>
<li><span class="icon icon-envelope"></span><span class="text"> rajshirtraders#gmail.com</span></li>
</ul>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
</div>
</div>
</div>
</footer>
<!-- loader -->
<div id="ftco-loader" class="show fullscreen"><svg class="circular" width="48px" height="48px"><circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee"/><circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#F96D00"/></svg></div>
i am trying to link my php to the contact form but facing some issues please help
the format of the cotact us is also a bit messed up after sevral attempts to fix it i coudnt
i am using my sql for the php
i have the php file but dont know where to attach it in the contact us page (html)
i have tried a few solutions looking at youtube
but nothing works
please help
That's how work php/html:
HTML
<form class="=contact-form" action="contact.php" method="post">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name" name="name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Email" name="email">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Subject" name="subject">
</div>
<div class="form-group">
<textarea name="mess" id="" cols="30" rows="7" class="form-control" placeholder="Message" ></textarea>
</div>
<div class="form-group">
<input type="submit" value="Send Message" class="btn btn-primary py-3 px-5">
</div>
</form>
Here user will input data and sent to contact.php, i add name="" and we will create a variable with that.
PHP
// ALL VARIABLE FROM FORM
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];
//NOW YOU CAN SENT EMAIL
$to = "somebody#example.com";
$headers = "From:".$email . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$message,$headers);
I am just trying to create a record in my players table to test that my php works, but each time I click my submit I get a 500 error instead of my url error handlers that should return if my data is not correct for my domain or fields are empty.
I do have a session which is holding my user data.
My user creates php works which is what I based my player create php code off of. I will post my table so you can see the structure and my php include and my HTML please any help would be great
My php include code --------------
<?php
if (isset($_POST['submit'])) {
include_once 'dbh.php';
$player_first = mysqli_real_escape_string($conn, $_POST['player_first']);
$player_last = mysqli_real_escape_string($conn, $_POST['player_last']);
$player_mobile = mysqli_real_escape_string($conn, $_POST['player_mobile']);
$player_address = mysqli_real_escape_string($conn,
$_POST['player_address']);
$player_city = mysqli_real_escape_string($conn, $_POST['player_city']);
$player_state = mysqli_real_escape_string($conn, $_POST['player_state']);
$player_zip = mysqli_real_escape_string($conn, $_POST['player_zip']);
$player_dob = mysqli_real_escape_string($conn, $_POST['player_dob']);
$player_gender = mysqli_real_escape_string($conn, $_POST['player_gender']);
$player_id = mysqli_real_escape_string($conn, $_POST['player_id']);
//Error handlers
//Check for empty fields
if (empty($player_first) || empty($player_last) || empty($player_mobile) ||
empty($player_address) || empty($player_city) || empty($player_state)||
empty($player_zip)|| empty($player_dob)|| empty($player_gender) ||
empty($player_id)) {
header("Location: ../profile.php?profile=empty");
exit();
}
else {
//check if input characters are valid
if (!preg_match("/^[a-zA-Z]*$/", $player_first)
|| !preg_match("/^[a-zA-Z]*$/", $player_last)) {
header("Location: ../profile.php?profile=invalid");
exit();
}
else {
//check if email is valid
if (!filter_var($player_mobile, FILTER_SANITIZE_NUMBER_INT)) {
header("Location: ../profile.php?player=mobile");
exit();
} else {
$sql = "SELECT * FROM players WHERE player_id='$player_id'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
header("Location: ../profile.php?profile=playertaken");
exit();
} else {
//Insert the player into the database
$sql = "INSERT INTO players (player_first, player_last, ,
player_mobile, player_address, player_city, player_state, player_zip,
player_dob, player_gender, player_id) VALUES
('$player_first', '$player_last', '$player_address',
'$player_city', '$player_state', '$player_zip', '$player_dob',
'$player_gender', '$player_id');";
mysqli_query($conn, $sql);
header("Location: ../profile.php");
exit();
}
}
}
}
else {
header("Location: ../profile.php");
exit();
}
--------------------------------------------------------------End of php include
My html/php page code ----------------------------------------------------------
<?php
session_start();
include_once 'header.php';
include 'includes/dbh.php';
?>
<!-- ============================================================== -->
<!-- Page Content -->
<!-- ============================================================== -->
<div id="page-wrapper">
<div class="container-fluid">
<div class="row bg-title">
<div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
<h4 class="page-title">Profile page</h4> </div>
<div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
<button class="right-side-toggle waves-effect waves-
light btn-info btn-circle pull-right m-l-20"><i class="ti-settings text-
white"></i></button>
<ol class="breadcrumb">
<li>Dashboard</li>
<li class="active">Profile page</li>
</ol>
</div>
</div>
<div class="tab-pane active" id="settings">
<form class="form-horizontal form-material"
action="includes/profile-inc.php" method="POST">
<div class="form-group">
<label class="col-md-12">First
Name</label>
<div class="col-md-12">
<input type="text" required=""
name="player_first" value ="<?php echo $user_first ?>" class="form-control
form-control-line"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Last
Name</label>
<div class="col-md-12">
<input type="text" required=""
name="player_last" value ="<?php echo $user_last ?>" class="form-control
form-control-line"> </div>
</div>
<div class="form-group">
<label for="example-email"
class="col-md-12">Mobile</label>
<div class="col-md-12">
<input type="text" required=""
name="player_mobile" value ="<?php echo $player_mobile ?>" class="form-
control form-control-line"> </div>
</div>
<div class="form-group">
<label for="example-email"
class="col-md-12">Address</label>
<div class="col-md-12">
<input type="address"
required="" name="player_address" value ="<?php echo $player_address ?>"
class="form-control form-control-line"> </div>
</div>
<div class="form-group">
<label class="col-md-
12">City</label>
<div class="col-md-12">
<input type="text" required=""
name="player_city" value ="<?php echo $player_city ?>" class="form-control
form-control-line"> </div>
</div>
<div class="form-group">
<label class="col-md-
12">State</label>
<div class="col-md-12">
<input type="text" required=""
name="player_state" value ="<?php echo $player_state ?>" class="form-
control
form-control-line"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Zip</label>
<div class="col-md-12">
<input type="text" required=""
name="player_zip" value ="<?php echo $player_zip ?>" class="form-control
form-control-line"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Date of
Birth</label>
<div class="col-md-12">
<input type="date" required=""
name="player_dob" value ="<?php echo $player_dob ?>" class="form-control
form-control-line"> </div>
</div>
<div class="form-group">
<label class="col-md-
12">Gender</label>
<div class="col-md-12">
<input type="text" required=""
name="player_gender" value ="<?php echo $player_gender ?>" class="form-
control form-control-line"> </div>
</div>
<div class="form-group">
<label class="col-md-
12">User_id</label>
<div class="col-md-12">
<input type="text" required=""
name="player_id" value ="<?php echo $user_id ?>" class="form-control form-
control-line"></div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button class="btn btn-success"
type="submit" name="submit">Update Profile</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- /.row -->
<!--
============================================================== -->
<!-- Right sidebar -->
<!--
============================================================== -->
<!-- .right-sidebar -->
<div class="right-sidebar">
<div class="slimscrollright">
<div class="rpanel-title"> Service Panel <span><i
class="ti-close right-side-toggle"></i></span> </div>
<div class="r-panel-body">
<ul id="themecolors" class="m-t-20">
<li><b>With Light sidebar</b></li>
<li><a href="javascript:void(0)" data-
theme="default" class="default-theme">1</a></li>
<li><a href="javascript:void(0)" data-
theme="green" class="green-theme">2</a></li>
<li><a href="javascript:void(0)" data-
theme="gray" class="yellow-theme">3</a></li>
<li><a href="javascript:void(0)" data-
theme="blue" class="blue-theme">4</a></li>
<li><a href="javascript:void(0)" data-
theme="purple" class="purple-theme">5</a></li>
<li><a href="javascript:void(0)" data-
theme="megna" class="megna-theme">6</a></li>
<li><b>With Dark sidebar</b></li>
<br/>
<li><a href="javascript:void(0)" data-
theme="default-dark" class="default-dark-theme">7</a></li>
<li><a href="javascript:void(0)" data-
theme="green-dark" class="green-dark-theme">8</a></li>
<li><a href="javascript:void(0)" data-
theme="gray-dark" class="yellow-dark-theme">9</a></li>
<li><a href="javascript:void(0)" data-
theme="blue-dark" class="blue-dark-theme">10</a></li>
<li><a href="javascript:void(0)" data-
theme="purple-dark" class="purple-dark-theme">11</a></li>
<li><a href="javascript:void(0)" data-
theme="megna-dark" class="megna-dark-theme working">12</a></li>
</ul>
<ul class="m-t-20 all-demos">
<li><b>Choose other demos</b></li>
</ul>
</div>
</div>
</div>
<!--
============================================================== -->
<!-- End Right sidebar -->
<!--
============================================================== -->
</div>
<!-- /.container-fluid -->
<?php
include_once 'footer.php';
?>
------------------------------------------------------------End of html/php code
I'm using Bootstrap 4 and I've created a two pane form; registration and sign in forms.
I know using AJAX is more suitable for such situations that it won't make the page refresh, however, I'm asking if there is any way of achieving that the page refreshes and previews the same pane using only PHP.
Using PHP in the code. Is there any way that when I submit the form when in registration pane (the one on the right hand side), the page refreshes and stays in the same pane.
<!-- Tabs -->
<nav class="register-nav">
<div class="nav nav-tabs nav-justified" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-signin-tab" data-toggle="tab" href="#nav-signin" role="tab">Sign in</a>
<a class="nav-item nav-link" id="nav-signup-tab" data-toggle="tab" href="#nav-signup" role="tab">Create New Account</a>
</div>
</nav>
<!-- Content of Tabs -->
<div class="tab-content" id="nav-tabContent">
<!-- Sign in Tab Pane -->
<div class="tab-pane fade show active" id="nav-signin" role="tabpanel">
<form action="" method="POST">
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<a class="btn btn-block btn-social btn-facebook">
<span class="fa fa-facebook"></span> Sign in with Facebook
</a>
</div>
<div class="col-sm-6">
<a class="btn btn-block btn-social btn-google">
<span class="fa fa-google"></span> Sign in with Google
</a>
</div>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Username / Email Address">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password">
</div>
<div class="form-group text-center mt-5">
<input type="submit" class="btn btn-outline-info" value="Sign in">
</div>
</form>
</div>
<!-- Sign Up Tab Pane -->
<div class="tab-pane fade" id="nav-signup" role="tabpanel">
<form action="" method="POST">
<div class="form-group">
<input type="text" class="form-control" placeholder="First name" required>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Last name" required>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Username" required>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email Address" required>
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" required>
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Confirm Password" required>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" required>
<label class="form-check-label">By registering to
velocity, you agree to its
terms and conditions
</label>
</div>
<div class="form-group text-center mt-5">
<input id="register-btn" type="submit" class="btn btn-outline-success" value="Register" disabled>
</div>
</form>
</div>
</div>
It is really not a PHP thing, but you could use PHP to manipulate the HTML to move the active class to the other tab.
<?php
$signinTabIsActive = "active";
$signupTabIsActive = "";
if(isset($_POST['firstname'])){
$signinTabIsActive = "";
$signupTabIsActive = "active";
?>
<!-- Tabs -->
<nav class="register-nav">
<div class="nav nav-tabs nav-justified" id="nav-tab" role="tablist">
<a class="nav-item nav-link <?= $signinTabIsActive; ?>" id="nav-signin-tab" data-toggle="tab" href="#nav-signin" role="tab">Sign in</a>
<a class="nav-item nav-link <?= $signupTabIsActive; ?>" id="nav-signup-tab" data-toggle="tab" href="#nav-signup" role="tab">Create New Account</a>
</div>
</nav>
Add a hidden input with a value that indicaties which pane should open. When generating the form (with Php) decide which pane gets an active class based on this value in the $_POST array
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());
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I get getting this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_id = 1' at line 1
I have tried everything in '' or "", even '. .' and "'. .'".
I can't find anything wrong with it. Please help!
It should update the MySQL database but it only outputs that error.
<?
ob_start();
$mid = $_GET['id'];
include 'connect.php';
if($_SESSION['signed_in'] == false | $_SESSION['user_level'] != 2)
{
header('Location: index.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Group 5 Waggle</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="css/local.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div id="wrapper">
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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" href="index.php">Waggle</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<? if($_SESSION['signed_in'] == true && $_SESSION['user_level'] == 2 ) { ?>
<li> </li>
<li><i class="fa fa-table"></i> Add User</li>
<li><i class="fa fa-tasks"></i> Cream Forums</li>
<? } ?>
</ul>
<?
if($_SESSION['signed_in'])
{ ?>
<ul class="nav navbar-nav navbar-right navbar-user">
<li class="dropdown user-dropdown">
<i class="fa fa-user"></i> <?=htmlentities($_SESSION['user_name']); ?> <b class="caret"></b>
<ul class="dropdown-menu">
<li><i class="fa fa-user"></i> Profile</li>
<li><i class="fa fa-gear"></i> Edit Profile</li>
<li class="divider"></li>
<li><i class="fa fa-power-off"></i> Logout</li>
</ul>
</li>
</ul>
<? } ?>
</div>
</nav>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1>Update <small>User</small></h1>
</div>
</div>
<p> </p>
<div class="row">
<? if($_SERVER['REQUEST_METHOD'] != 'POST') {
$result1 = mysql_query("SELECT * FROM users WHERE user_id = '$mid'");
$row = mysql_fetch_array($result1);
?>
<form method="post" action="">
<div class="col-lg-12">
<div>
<label for="firstname" class="col-md-2">
Full Name:
</label>
<div class="col-md-9">
<input type="text" name="user_name" class="form-control" id="firstname" value="<?=$row[user_name];?>">
</div>
<div class="col-md-1">
<i class="fa fa-lock fa-2x"></i>
</div>
</div>
<div>
<label for="emailaddress" class="col-md-2">
Email address:
</label>
<div class="col-md-9">
<input type="text" name="user_email" class="form-control" id="emailaddress" value="<?=$row[user_email];?>">
<p class="help-block">
Example: yourname#domain.com
</p>
</div>
<div class="col-md-1">
<i class="fa fa-lock fa-2x"></i>
</div>
</div>
<div>
<label for="password" class="col-md-2">
Password:
</label>
<div class="col-md-9">
<input type="password" name="user_pass" class="form-control" id="password" placeholder="Enter Password">
<p class="help-block">
Min: 6 characters (Alphanumeric only)
</p>
</div>
<div class="col-md-1">
<i class="fa fa-lock fa-2x"></i>
</div>
</div>
<div>
<label for="password" class="col-md-2">
Password (again):
</label>
<div class="col-md-9">
<input type="password" name="user_pass_check" class="form-control" id="password" placeholder="Enter Password">
<p class="help-block">
Min: 6 characters (Alphanumeric only)
</p>
</div>
<div class="col-md-1">
<i class="fa fa-lock fa-2x"></i>
</div>
</div>
<div>
<label for="website" class="col-md-2">
Website:
</label>
<div class="col-md-9">
<input type="text" name="user_web" class="form-control" id="website" value="<?=$row[user_web];?>">
</div>
<div class="col-md-1">
</div>
</div>
<div>
<label for="twitter" class="col-md-2">
Twitter:
</label>
<div class="col-md-9">
<input type="text" name="user_twitter" class="form-control" id="twitter" value="<?=$row[user_twitter];?>">
</div>
<div class="col-md-1">
</div>
</div>
<div>
<label for="facebook" class="col-md-2">
Facebook:
</label>
<div class="col-md-9">
<input type="text" name="user_facebook" class="form-control" id="facebook" value="<?=$row[user_facebook];?>">
</div>
<div class="col-md-1">
</div>
</div>
<div>
<label for="github" class="col-md-2">
Github:
</label>
<div class="col-md-9">
<input type="text" name="user_github" class="form-control" id="github" value="<?=$row[user_github];?>">
</div>
<div class="col-md-1">
</div>
</div>
<div>
<label for="uploadimage" class="col-md-2">
Profile Image:
</label>
<div class="col-md-10">
<input type="file" name="uploadimage" id="uploadimage">
<p class="help-block">
Allowed Formats: jpeg, jpg, gif, png
</p>
</div>
</div>
<div>
<div class="col-md-2">
</div>
<div class="col-md-10">
<br />
<br />
<button type="submit" class="btn btn-info">
Save Profile
</button>
</div>
</div>
</div>
</form>
<? }
else {
/* so, the form has been posted, we'll process the data in three steps:
1. Check the data
2. Let the user refill the wrong fields (if necessary)
3. Save the data
*/
$errors = array(); /* declare the array for later use */
if(!isset($_POST['user_name']))
{
$errors[] = 'The username field must not be empty.';
}
if(isset($_POST['user_pass']))
{
if($_POST['user_pass'] != $_POST['user_pass_check'])
{
$errors[] = 'The two passwords did not match.';
}
}
else
{
$errors[] = 'The password field cannot be empty.';
}
if(!empty($errors)) /*check for an empty array, if there are errors, they're in this array (note the ! operator)*/
{ ?>
<div class="col-lg-4">
<div class="alert alert-dismissable alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<ul>
<?
foreach($errors as $key => $value) {
echo '<li>' . $value . '</li>';
}
?>
</ul>
</div>
</div>
<br />
<form method="post" action="">
<div class="col-lg-12">
<div>
<label for="firstname" class="col-md-2">
Full Name:
</label>
<div class="col-md-9">
<input type="text" name="user_name" class="form-control" id="firstname" value="<?=$_POST['user_name'];?>">
</div>
<div class="col-md-1">
<i class="fa fa-lock fa-2x"></i>
</div>
</div>
<div>
<label for="emailaddress" class="col-md-2">
Email address:
</label>
<div class="col-md-9">
<input type="text" name="user_email" class="form-control" id="emailaddress" value="<?=$_POST['user_email'];?>">
<p class="help-block">
Example: yourname#domain.com
</p>
</div>
<div class="col-md-1">
<i class="fa fa-lock fa-2x"></i>
</div>
</div>
<div>
<label for="password" class="col-md-2">
Password:
</label>
<div class="col-md-9">
<input type="password" name="user_pass" class="form-control" id="password" placeholder="Enter Password">
<p class="help-block">
Min: 6 characters (Alphanumeric only)
</p>
</div>
<div class="col-md-1">
<i class="fa fa-lock fa-2x"></i>
</div>
</div>
<div>
<label for="password" class="col-md-2">
Password (again):
</label>
<div class="col-md-9">
<input type="password" name="user_pass_check" class="form-control" id="password" placeholder="Enter Password">
<p class="help-block">
Min: 6 characters (Alphanumeric only)
</p>
</div>
<div class="col-md-1">
<i class="fa fa-lock fa-2x"></i>
</div>
</div>
<div>
<label for="website" class="col-md-2">
Website:
</label>
<div class="col-md-9">
<input type="text" name="user_web" class="form-control" id="website" value="<?=$_POST['user_web'];?>">
</div>
<div class="col-md-1">
</div>
</div>
<div>
<label for="twitter" class="col-md-2">
Twitter:
</label>
<div class="col-md-9">
<input type="text" name="user_twitter" class="form-control" id="twitter" value="<?=$_POST['user_twitter'];?>">
</div>
<div class="col-md-1">
</div>
</div>
<div>
<label for="facebook" class="col-md-2">
Facebook:
</label>
<div class="col-md-9">
<input type="text" name="user_facebook" class="form-control" id="facebook" value="<?=$_POST['user_facebook'];?>">
</div>
<div class="col-md-1">
</div>
</div>
<div>
<label for="github" class="col-md-2">
Github:
</label>
<div class="col-md-9">
<input type="text" name="user_github" class="form-control" id="github" value="<?=$_POST['user_github'];?>">
</div>
<div class="col-md-1">
</div>
</div>
<div>
<label for="uploadimage" class="col-md-2">
Profile Image:
</label>
<div class="col-md-10">
<input type="file" name="uploadimage" id="uploadimage">
<p class="help-block">
Allowed Formats: jpeg, jpg, gif, png
</p>
</div>
</div>
<div>
<div class="col-md-2">
</div>
<div class="col-md-10">
<br />
<br />
<button type="submit" class="btn btn-info">
Save Profile
</button>
</div>
</div>
</div>
</form>
<? }
else
{
$new_name = mysql_real_escape_string($_POST['user_name']);
$new_pass = sha1($_POST['user_pass']);
$new_email = mysql_real_escape_string($_POST['user_email']);
$new_web = mysql_real_escape_string($_POST['user_web']);
$new_twitter = mysql_real_escape_string($_POST['user_twitter']);
$new_facebook = mysql_real_escape_string($_POST['user_facebook']);
$new_github = mysql_real_escape_string($_POST['user_github']);
//the form has been posted without, so save it
//notice the use of mysql_real_escape_string, keep everything safe!
//also notice the sha1 function which hashes the password
$sql = "UPDATE `users` SET `user_name` = '$new_name', `user_pass` = '$new_pass', `user_email` = '$new_email', `user_web` = '$new_web', `user_twitter` = '$new_twitter', `user_facebook` = '$new_facebook', `user_github` = '$new_github', `user_level` = '0', WHERE user_id = $mid";
$result = mysql_query($sql);
if(!$result)
{
//something went wrong, display the error
echo $mid;
echo '<div class="well well-lg">Something went wrong while registering. Please try again later.</div>';
echo mysql_error(); //debugging purposes, uncomment when needed
}
else
{
header('Location: index.php');
}
}
}
?>
</div>
</div>
</div>
</body>
</html>
Your problem is in this query:
$sql = "UPDATE `users`
SET `user_name` = '$new_name', `user_pass` = '$new_pass', `user_email` = '$new_email', `user_web` = '$new_web', `user_twitter` = '$new_twitter', `user_facebook` = '$new_facebook', `user_github` = '$new_github', `user_level` = '0', WHERE user_id = $mid";
Particularly in this last part:
`user_level` = '0', WHERE user_id = $mid";
That last comma before the where should be removed.