Undefined index when no data entered - php

Im working on a v2 of signing up.
I added some new input fields in various input types and the one that i use in v1 are now working properly, but the new ones don't. I noticed that it are only like the special input fields (checkboxes, selection menu, radio buttons, ...). I was testing out and when nothing is entered it just gives me this undefined index error (while i tried to define it). Note: the inputs that aren't working are not required fields!
Anyway, here is the PHP code:
// Initializing variables
$username = "";
$email = "";
$errors = array();
// Connect to the database
$conn = mysqli_connect($database['host'], $database['user'], $database['password'], $database['db'], $database['port']);
$email_show = $_POST['emailshow'];
// REGISTER USER
if (isset($_POST['reg_user'])) {
// Receive all input values from the form
$username = mysqli_real_escape_string($conn, $_POST['username']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$email_show = mysqli_real_escape_string($conn, $_POST['emailshow']);
$password_1 = mysqli_real_escape_string($conn, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($conn, $_POST['password_2']);
$fname = mysqli_real_escape_string($conn, $_POST['fname']);
$fname_show = mysqli_real_escape_string($conn, $_POST['fnameshow']);
$lname = mysqli_real_escape_string($conn, $_POST['lname']);
$lname_show = mysqli_real_escape_string($conn, $_POST['lnameshow']);
$sex = mysqli_real_escape_string ($conn, $_POST['sex']);
$bday = mysqli_real_escape_string($conn, $_POST['bday']);
$country = mysqli_real_escape_string($conn, $_POST['country']);
$private_account = mysqli_real_escape_string($conn, $_POST['privateacc']);
$profile_style = mysqli_real_escape_string($conn, $_POST['profilestyle']);
// Form validation: ensure that the form is correctly filled ...
// By adding (array_push()) corresponding error unto $errors array
if (empty($username)) { array_push($errors, "Username is required"); }
if (empty($email)) { array_push($errors, "Email is required"); }
if (empty($password_1)) { array_push($errors, "Password is required"); }
if (empty($fname)) { array_push($errors, "Firstname is required"); }
if (empty($lname)) { array_push($errors, "Lastname is required"); }
if (empty($sex)) { array_push($errors, "What is your gender?"); }
if (empty($bday)) { array_push($errors, "When is your birthday?"); }
if (empty($_POST['country'])) { array_push($errors, "Test"); }
if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}
HTML input:
<div class="box-title"><h1>Sign up</h1></div>
<div class="required-fields"><em>- Required fields are marked with *</em></div>
<div class="account-wrapper">
<div class="account-title">YOUR ACCOUNT</div>
<form method="post" class="accountform" action="/sign-up">
<input type="text" placeholder="Username*" name="username" onfocus="showDesc1()">
<div id="desc1">How others will see you <i id="close" onclick="closeDesc1()" class="fas fa-times-circle"></i></div>
<input type="email" placeholder="Email*" name="email" onfocus="showDesc2()">
<div id="desc2">We need this for important use <i id="close" onclick="closeDesc2()" class="fas fa-times-circle"></i><br><a style="color: blue;"> Read more (soon)</a></div>
<div id="emailshow"><input type="checkbox" id="emailshow-input" name="emailshow" value="showemail"><label style="text-decoration: underline;" data-tooltip="When this option is enabled, other users will be able to see your email on your profile." for="emailshow-input">Show on profile</label></div>
<input id="passwordfield" type="password" placeholder="Password*" name="password_1">
<div onclick="passwordVisb()" class="visb-innerhtml"><i id="visbcon" class="fas fa-eye"></i><label style="cursor: pointer;" id="visb-innerhtml"> Show password</label></div>
<input type="password" placeholder="Confirm password*" name="password_2" onfocus="showDesc3()">
<div id="desc3">Remember the entered password? <i id="close" onclick="closeDesc3()" class="fas fa-times-circle"></i></div>
</div>
</div>
<div class="details-wrapper">
<div class="details-title">YOUR DETAILS</div>
<div class="details-fields1">
<input type="text" placeholder="Firstname*" name="fname" onfocus="showDesc4()">
<div id="desc4">Your firstname <i id="close" onclick="closeDesc4()" class="fas fa-times-circle"></i></div>
<div id="fnameshow"><input type="checkbox" id="fnameshow-input" name="fnameshow" value="1"><label style="text-decoration: underline;" data-tooltip="When this option is enabled, other users will be able to see your firstname on your profile." for="fnameshow-input">Show on profile</label></div>
<input type="text" placeholder="Lastname*" name="lname" onfocus="showDesc5()">
<div id="desc5">Your lastname <i id="close" onclick="closeDesc5()" class="fas fa-times-circle"></i></div>
<div id="lnameshow"><input type="checkbox" id="lnameshow-input" name="lnameshow" value="1"><label style="text-decoration: underline;" data-tooltip="When this option is enabled, other users will be able to see your lastname on your profile." for="lnameshow-input">Show on profile</label></div>
<div class="gendersec">
<input id="genm" type="radio" name="sex" value="male">
<label for="genm">Male</label>
<input id="genf" type="radio" name="sex" required value="female">
<label for="genf">Female</label>
<input id="genc" type="radio" name="sex" value="custom">
<label for="genc" style="text-decoration: underline;" data-tooltip="Select this option if you do not want to tell us what your gender is or if you do have another gender not listed here." data-tooltip-location="top">Custom</label>
</div>
<input type="text" onkeypress="return false;" name="bday" autocomplete="off" placeholder="Birthday*" id="birthdaypicker">
</div>
<div class="details-fields2">
<?php include_once 'C:/xampp2/htdocs/includes/lang-select.php' ?>
<!-- <div id="tags-input">
<span>Socialhub</span>
<input type="text" disabled value="" placeholder="Interests (coming soon)">
</div> !-->
<p style="color: orange;">More options coming soon!</p>
</div>
</div>
<div class="settings-wrapper">
<div class="settings-title">QUICK SETTINGS</div>
<div class="settings-fields1">
<input type="checkbox" id="privateacc-input" name="privateacc" value="privateacctrue"><label for="privateacc-input" style="text-decoration: underline;" data-tooltip="If you enable this option, then the content of your account will be hidden for other users (they can still visit your account but they can't see the content). From your profile picture to your latest post will be hidden.">Private account</label>
<select class="profilestyle" name="profilestyle">
<option selected disabled>Select a style for your profile...</option>
<option value="default">Default (orange & green)</option>
<option value="red">Red</option>
<option value="black">Black</option>
<option disabled>These are coming soon for sure, stay tuned!</option>
<option disabled>Yellow</option>
<option disabled>Blue</option>
<option disabled>Pink</option>
<option disabled>...</option>
</select>
<p style="margin-top: 50px; color: orange;">More settings coming soon!</p>
</div>
</div>
<div class="bottom-wrapper">
<div class="bottom-topframe">
<i class="fas fa-arrow-left"></i> Nevermind!
<div class="agree-wrapper">
<input type="checkbox" id="agreetos-input" name="agreetos" value="tosagreed" onchange="document.getElementById('btnsubmit_reg').disabled = !this.checked;"><label for="agreetos-input">I agree with the Terms of Service (coming soon)</label>
<input type="checkbox" id="verifyage-input" name="verifyage" value="ageverified"><label for="verifyage-input">I am 13 years or older</label>
</div>
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">
<button type="submit" disabled name="reg_user" id="btnsubmit_reg" class="btnsubmit_reg">Sign up</button>
</div>
Thanks already. (Sorry for the search, big form)

This will help you, and like #Moayad .AlMoghrabi said you really should use better security also when it is local. Learn yourself always to write secure code.
$email = mysqli_real_escape_string($conn, $_POST['email']);
$email = isset($_POST['email']) ? mysqli_real_escape_string($conn, $_POST['email']) : '';
By checking your post values like this your variable will always have a value or a empty string.

I recommend you in order to fix this issue and to have more security as this code can be used in Mysql Injection easily, You have to escape all values from POST then you have to check if it is empty give it a default values.

Related

How to take user input php

I'm making an event management system. I dont know what's wrong, it just keeps reloading after I click submit button.
Here's my HTML codes
<?php
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: login.php");
}
<div class="header">
<h2>Create Event</h2>
</div>
<form method="post" action="create_event.php">
<div class="input-group">
<label>Event Title</label>
<input type="text" name="event_title" >
</div>
<div class="input-group">
<label>Pick Location</label>
<select name="location">
<option>Alabang</option>
<option>South City</option>
<option>Batangas</option>
<option>Cavite</option>
<option>Laguna</option>
</select>
<div class="input-group">
<label>Address</label>
<textarea rows="4" cols="50" name="address"></textarea>
</div>
<div class="date">
<label>Pick date and time</label>
<input type="date" name="date"></br>
<input type="time" name="time">
</div>
<div class="event_info">
<label>Event Information</label>
<textarea rows="4" cols="50" name="event_info"></textarea>
</div>
<div class="input-group">
<button type="submit" class="btn" name="create_event">Create Event</button>
</div>
</form>
PHP code:
// Create Event
if (isset($_POST['create_event'])) {
// receive all input values from the form
$event_title = mysql_real_escape_string($_POST['event_title']);
$location = mysql_real_escape_string($_POST['location']);
$address = mysql_real_escape_string($_POST['address']);
$date = mysql_real_escape_string($_POST['date']);
$time = mysql_real_escape_string($_POST['time']);
$event_info = mysql_real_escape_string($_POST['event_info']);
$query="select * from `event` where event_title='$_POST[event_title]' or time='$_POST[time]' or date='$_POST[date]'";
$result=mysql_query($query);
$count=mysql_num_rows($result);
if($count>0)
{
array_push($errors, "Already used");
}
// form validation: ensure that the form is correctly filled
if (empty($event_title)) { array_push($errors, "Please input title"); }
if (empty($location)) { array_push($errors, "Location is required"); }
if (empty($address)) { array_push($errors, "Location is required"); }
if (empty($time)) { array_push($errors, "Time is required"); }
if (empty($date)) { array_push($errors, "Date is required"); }
if (empty($event_info)) { array_push($errors, "Date is required"); }
// register user if there are no errors in the form
if (count($errors) == 0) {
$query = "INSERT INTO `event` (event_title,location,address,time,date,event_info) VALUES ('$event_title', '$location','$address','$time','$date','$event_info')";
$result = mysql_query($query);
echo("success");
}
}
I don't think there is anything wrong because if I click the submit button, no errors popup. It just reloads but no data is sent to my database.
Amend in form your submit button like this:
<input type = "submit" name = "create_event" value="create event"/>
Also in action use $_SERVER['PHP_SELF'] variable. Like this...
<form action ="<?php echo
htmlspecialchars($_SERVER['PHP_SELF']);
?>" method = "post">
In database query please use PDO statement it's easy and safe. And also sanitize user input before using it.

Registration Form that Submits to Database and Sends a Confirmation Email to the User with Their Info - 2 Actions, 1 Button

I thought the solution would be easy to find, but I cannot find it. I want my registration form to submit to the database and send the form data to the user's email, as a confirmation email, at the same time and using the same submit button. It seems logical that the form would have two actions, but I'm finding no example of such a thing. Perhaps some PHP code on the registration page that will recognize the successful submission and send the data to a php file that will process an email at the same time the data is being inserted into the database table??
register.php, the PHP above the HTML
<?php
session_start();
if (!isset($_SESSION['usr_id']) && empty($_SESSION['usr_id']) ) {
} else {
header('Location: mustlogout.php'); #redirect URL
}
?>
<?php
include_once 'db.php';
//set validation error flag as false
$error = false;
//check if form is submitted
if (isset($_POST['signup'])) {
$name = mysqli_real_escape_string($con, $_POST['name']);
$user_name = mysqli_real_escape_string($con, $_POST['user_name']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$cpassword = mysqli_real_escape_string($con, $_POST['cpassword']);
$name = stripslashes($name);
$user_name = stripslashes($user_name);
$email = stripslashes($email);
$password = stripslashes($password);
$cpassword = stripslashes($cpassword);
if (!preg_match("/^[a-zA-Z ]+$/",$name)) { /* name can contain only alpha characters and space */
$error = true;
$name_error = "Name must contain only letters";
}
if (!preg_match("/^[a-zA-Z-0-9 ]+$/",$user_name)) { /* letters and numbers */
$error = true;
$user_name_error = "User name can contain only letters and numbers";
}
if(!filter_var($email,FILTER_VALIDATE_EMAIL)) { /* will accept only email addresses */
$error = true;
$email_error = "Please Enter Valid Email ID";
}
if(strlen($password) <6 ) { /* must be 6 or more characters */
$error = true;
$password_error = "Password must be minimum of 6 characters";
}
if($password != $cpassword) { /* must match the first password entry */
$error = true;
$cpassword_error = "Password and Confirm Password doesn't match";
}
if (!$error) {
if(mysqli_query($con, "INSERT INTO forumusers(name,user_name,email,password) VALUES('" . $name . "', '" . $user_name . "', '" . $email . "', '" . md5($password) . "')")) {
$successmsg = "Successfully Registered! <a href='login.php'>Click here to Login</a>"; /* if register is successful */
} else {
$errormsg = "Error in registering...Please try again later!"; /* if register is not successful */
}
}
}
?>
<!doctype html>
<html><!-- InstanceBegin template="/Templates/index.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
register.php, the form in the HTML
<!-- InstanceBeginEditable name="EditRegion3" -->
<div class="title-bar"><n6>Forum Registration</n6></div>
<div class="main-content">
<div class="form-reg" style="margin-bottom: 4em;"><!-- Begin div to contain form -->
<table width="50%" style="padding-left: 20px;">
<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="signupform">
<fieldset>
<tr>
<td>
<div style="margin-top: 0px; margin-bottom: 5px;">
<label for="name" class="formfield-names">Name</label>
<input type="text" name="name" placeholder="Enter Your Full Name" required value="<?php if($error) echo $name; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($name_error)) echo $name_error; ?></span>
</div>
</td>
</tr>
<tr>
<td>
<div style="margin-top: 0px; margin-bottom: 5px;">
<label for="name" class="formfield-names">User Name</label>
<input type="text" name="user_name" minlength="5" maxlength="15" placeholder="5 to 15 Letters/Numbers" required value="<?php if($error) echo $user_name; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($user_name_error)) echo $user_name_error; ?></span>
</div>
</td>
</tr>
<tr>
<td>
<div style="margin-top: 10px; margin-bottom: 5px;">
<label for="name" class="formfield-names">Email</label>
<input type="text" name="email" placeholder="Enter a Valid Email" required value="<?php if($error) echo $email; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($email_error)) echo $email_error; ?></span>
</div>
</td>
</tr>
<tr>
<td>
<div style="margin-top: 10px; margin-bottom: 5px;">
<label for="name" class="formfield-names">Password</label>
<input type="password" name="password" minlength="6" maxlength="16" placeholder="6 to 16 Chracters" required class="form-control" />
<span class="text-danger"><?php if (isset($password_error)) echo $password_error; ?></span>
</div>
</td>
</tr>
<tr>
<td>
<div style="margin-top: 10px; margin-bottom: 5px;">
<label for="name" class="formfield-names">Confirm Password</label>
<input type="password" name="cpassword" placeholder="Confirm Password" required class="form-control" />
<span class="text-danger"><?php if (isset($cpassword_error)) echo $cpassword_error; ?></span>
</div>
</td>
</tr>
<tr>
<td>
<div style="margin-top: 10px; margin-bottom: 5px;">
<input type="submit" name="signup" value="Register" class="button" />
</div>
</fieldset>
</form>
</td>
</tr>
<tr><td><div style="margin-top: 10px; margin-bottom: 5px;" class="formfield-names">Already Registered? Login Here</div></td></tr>
</table>
<span class="formfield-names"><?php if (isset($successmsg)) { echo $successmsg; } ?></span>
<span class="formfield-names"><?php if (isset($errormsg)) { echo $errormsg; } ?></span>
</div><!-- End div to contain form -->
</div>
<!-- InstanceEndEditable -->
I found alot of "form with two buttons" and various "how to submit a form to a database" and "how to send email with a form" and displaying various confirmation messages and the one I found with the 2 actions appears to be incomplete. Help would be greatly appreciated.
It is quite a simple question, you should try thinking out the process before coding it.
some code ....
if(mysqli_query($con, "INSERT INTO forumusers(name,user_name,email,password) VALUES('" . $name . "', '" . $user_name . "', '" . $email . "', '" . md5($password) . "')")) {
$successmsg = "Successfully Registered! <a href='login.php'>Click here to Login</a>"; /* if register is successful */
// add email here.
}
some code ....
It seems logical that the form would have two actions
No. The action attribute determines the URL to which the data will be sent. HTML is not designed to send data to multiple places (because it is geared up to display one page at a time).
If you want to do more than one thing with the data, you just need to make the program at that URL do more than one thing.
Your existing PHP already does two things:
Inserts data into a database
Outputs an HTML page back to the browser
You just need to insert the code to send the email into the same program.
Perhaps some PHP code on the registration page that will recognize the successful submission and send the data to a php file that will process an email at the same time the data is being inserted into the database table
If you want to divide your code up into smaller, logically grouped, chunks: You can use includes, functions and classes.

Forgot password reset not displaying correct email address and not updating password if any error made by user during for submission

I am currently working on PHP forgot password reset, which partially doing the job but seeking some assistance to improve it further.
1st issue: It is not displaying the correct email address on the
submission form. It updates the password correctly but doesn't
display correct email address.
2nd issue: Also if the user makes an error while submitting the form on reloading the page doesn't update the password hence the user has to go back to his email to click back on the link.
<?php
include('../config/connection.php');
if(isset($_POST['submit'])){
$password = mysqli_real_escape_string($dbc,$_POST['password']);
$Rpassword = mysqli_real_escape_string($dbc,$_POST['Rpassword']);
$acode=$_POST['encrypt'];
$passmd = md5(SHA1($password));
if (empty($password) OR empty($Rpassword)) {
$error = 'One or either field is missing';
} if ($password != $Rpassword) {
$error = 'Passwords don\'t match';
} if(strlen($password)<6 OR strlen($Rpassword)>20) {
$error = 'Password must be between 6 to 20 characters';
}
else {
$query = mysqli_query($dbc,"select * from users where passreset='$acode'") or die(mysqli_error($dbc));
if (mysqli_num_rows ($query)==1)
{
$query3 = mysqli_query($dbc,"UPDATE users SET password='$passmd',passreset=0 WHERE passreset='$acode'")
or die(mysqli_error($dbc));
$sent = 'Password has been Changed successfully, Please sign in for loging in.';
}
else
{
$error = 'Please click back on the Forgot password link to reset your password ';
}
}
}
?>
<body>
<?php if(!isset($_POST['submit']) OR $error != '' OR isset($error)) { ?>
<?php if(isset($error) AND $error !='')
{
echo '<p style="color:#c43235">'.$error.'</p>';
}
?>
<form action="reset.php" method="post" role="form">
<div class="form-group">
<label for="password">Email</label>
<input type="text" class="form-control" id="email" name="email" value="
<?php
$acode=$_POST['encrypt'];
$query5 = mysqli_query($dbc,"SELECT * FROM users where passreset='$acode'") or die(mysqli_error($dbc));
$list = mysqli_fetch_array($query5); /* Error-----*/
$val = $list['email'];
echo $val;?>" >
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password" >
</div>
<div class="form-group">
<label for="password">Re-enter Password</label>
<input type="password" class="form-control" id="password" name="Rpassword" placeholder="Password" >
</div>
<input type="hidden" class="form-control" name="encrypt" value="<?php echo $_GET['encrypt'];?>" >
<button class="btn btn-success" type="submit" name="submit" />Submit</button>
</form>

Mysqli Insert not working after i added php validatation [closed]

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 8 years ago.
Improve this question
Goodday house,i'm developing this site that has a registration/login page as my first project and i'm stucked right now.
I added php validation to my registration form but the database insert statement refuses to work after,though all conditional statements were fulfilled,i tried putting a redirect loop immediately after the insert statement but my script automatically (somehow) jumps the "Insert statement" and processes the redirect code..
This is the code below
<!-- Php validation-->
<?php
include 'var.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors = array(); // Starts an array to store errors.
//Validation rules involves trimming,validating and sanitizating
$name = trim($_POST['name']);
$strippedname = mysqli_real_escape_string($con, strip_tags($name)) ;
$length = mb_strlen($strippedname, 'utf-8') ;
if ($length < 8 ) {
$errors[]= 'Your full name shouldn\'t be less than 8 letters' ;
} else {
$name = $strippedname ;
}
$email = FALSE ;
if (empty($_POST['email'])) {
$errors[] = 'You didn\'t provide any email address' ;
} // Next is removal of spaces and validation.
if (filter_var((trim($_POST['email'])), FILTER_VALIDATE_EMAIL)) {
$email = mysqli_real_escape_string($con, (trim($_POST['email'])));
}
else {
$errors[] = 'Email address was provided in the wrong format';
}
$pho = trim($_POST['phone']) ; // next line of code removes all characters that aren't digits
$phon = preg_replace('/\D+/', '', ($_POST['phone']));
$strippedphone = mysqli_real_escape_string($con, strip_tags($phon));
$length = mb_strlen($strippedphone, 'utf-8') ;
if ($length <> 11 ) {
$errors[] = 'Phone number should contain only eleven digits';
}
else {
$phone = $strippedphone ;
}
$add = trim($_POST['address']) ;
$strippedadd = mysqli_real_escape_string($con, strip_tags($add)) ;
$length = mb_strlen($strippedadd, 'utf-8') ;
if ($length < 15) {
$errors[]= 'Address should not be lesser than 15 letters' ;
} else {
$address = $strippedadd ;
}
if (empty($_POST['gender'])) {
$errors[] = 'You didn\'t select a gender';
} else {
$gend = trim($_POST['gender']);
}
$user = trim($_POST['username']);
$strippeduser = mysqli_real_escape_string($con, strip_tags($user)) ;
$length = mb_strlen($strippeduser, 'utf-8') ;
if ($length < 6) {
$errors[] = 'Username should contain a minimum of 6 letters and maximum of 18';
} else {
$confirmeduser = $strippeduser ;
}
if (empty($_POST['password'])){
$errors[] ='Please enter a valid password';
}
if(!preg_match('/^\w{10,40}$/', $_POST['password'])) {
$errors[] = 'Invalid password, use 10 to 40 characters without applying spacing.';
} else{
$password = $_POST['password'];
}
if($_POST['password'] == $_POST['confirm_password']) {
$pass = mysqli_real_escape_string($con, trim($password));
$newpass = password_hash($pass, PASSWORD_DEFAULT) ;
}else{
$errors[] = 'passwords don\'t match.';
}
if(empty($errors)) { // If no problems occurred
//Determine whether the email address has already been registered for a user
$query = mysqli_query($con, "INSERT INTO `customer`(`name`, `email`,
`phone`, `address`, `gender`, `username`, `password`) VALUES($name,$email,$phone,
$address,$gend,$confirmeduser,$newpass)") ;
echo "Done";
// end of mysqli_num_Rows
} // End of if (empty($errors))
else{ // Display the errors if any are found.
echo '
<p class="error">The following error(s) were found in the submitted form :<br>';
foreach ($errors as $msg) { // Echo each error
echo " $msg<br>";
}
}
}
?>
This is the html form
<form action="register.php" method="POST" class="form-horizontal" style="margin-top:30px" id="signup">
<fieldset> <div class="form-group">
<legend> Customer Details </legend>
</div>
<div class="form-group">
<label for="name" class="control-label"> Full Name : </label>
<input type="text" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>"
name="name" placeholder="Your Full Name" class="required" title="Please type in your name" >
</div>
<div class="form-group">
<label for="email" class="control-label"> Email address </label>
<input type="text" name="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"
placeholder="someone#example.com">
</div>
<div class="form-group">
<label for="phone" class="control-label"> Phone Number :</label>
<input type="tel" name="phone" value="<?php if (isset($_POST['phone'])) echo $_POST['phone']; ?>"
placeholder="08137871320" class="required digits">
</div>
<div class="form-group">
<label for="address" class="control-label"> Contact Address : </label>
<input type="text" name="address" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>"
placeholder="No 4,street name,ikeja"
class="required" title="Please type in contact address plus your city's name">
</div>
<!--<div class="form-group">
Drop down menu for selecting a state from the 36 states to be provided
</div>-->
<div class="form-group">
<label for="name">Select Your gender :</label>
<select name="gender" class="form-control">
<option value="male" > Male </option>
<option value="female">Female </option>
</select>
</div>
</fieldset>
<fieldset> <div class="form-group">
<legend> Login Information </legend>
</div>
<div class="form-group">
<label for="username" class="control-label"> Username : </label>
<input type="text" name="username" placeholder="e.g Lords" value="<?php if (isset($_POST['username']))
echo $_POST['username']; ?>">
</div>
<div class="form-group">
<label for="password" class="control-label"> Password : </label>
<input type="password" name="password" id="password" placeholder="Your Password Here">
</div>
<div class="form-group">
<label for="cpassword" class="control-label">Confirm Password : </label>
<input type="password" name="confirm_password" placeholder="Confirm Your Password Here">
</div>
</fieldset>
</div>
</div>
</div>
<div class="form-group" style="text-align:center">
<button type="submit" class="btn btn-success" name="submit"> REGISTER </button>
<button type="reset" id="fat-btn" class="btn btn-danger" data-loading-text="Loading..."> RESET </button> <br>
<p class="lead">
Already a registered user ?,do make use of the
<a href="login.php" class="navbar-link" data-toggle="tooltip" title="When clicked upon,
a page requesting for your username and password is generated,allowing you to book orders">
login page </a>
</p>
</div>
</form>
Thanks a lot for your reply
Since we're more than likely dealing with strings, these variables in your VALUES
($name,$email,$phone,$address,$gend,$confirmeduser,$newpass)
needs to be quoted:
('$name','$email','$phone','$address','$gend','$confirmeduser','$newpass')
Had you checked for errors using or die(mysqli_error($con)) to mysqli_query()
would have signaled the quotes errors.
Sidenote:
You should use prepared statements, or PDO with prepared statements, they're much safer.
Additional note that Barmar spotted:
<?phpinclude 'var.php';
there needs to be a space in there between php and include
<?php include 'var.php';
unless that's a copy/paste error or typo.
and >? again, another spotted error which should be ?>
On the PHP side of things:
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.

php register user type

Hi i try to make a 2 register form. First register form for normal user and second register page is for business user.
I am using one mysql table for users. this table for same like normaluser and business user.
This is user type module. Normal user type is 0 it is ok but when the registered business user in my website his type same 0 not 1 .
I am asking this because normal user profile page is normal user profile. When normal user loged in my website he see automatically normal user profile and also when business user loged in my website he see business user profile. There are 2 profile page .
What can i do automatically user type 1 when business user registered and also when normal user registered in my website his user type is automatically 0 ?
What i am adding in my code for user type automatiacally 1 for business user ?
My code is this :
This is my HTML code
<form method="post" action="kaydol.php">
<div class="registiration_form1">
<div class="name_surname">
<div class="name">
<input onfocus="this.value=''" type="text" name="vname" autocomplete="off" value="NAME"/> </div>
<div class="surname">
<input onfocus="this.value=''" type="text" name="vsurname" autocomplete="off" value="USERNAME"/>
</div>
</div>
<div class="email"><input onfocus="this.value=''" type="text" name="vemail" value="E-Mail"/></div>
<div class="email-tekrar"><input onfocus="this.value=''" type="text" name="vemailagain" value="Re-Email" /></div>
<div class="password"><input onfocus="this.value=''" type="password" name="vpassword" value="PASSWORD" /></div>
<div class="dogum_tarihi_text">
BIRTHDAY
</div>
<div class="birthday_div">
<div class="d"><select> <option value="" selected>Day</option></select></div>
<div class="m"><select> <option value="" selected>MO</option></select></div>
<div class="y"><select> <option value="" selected>YEAR</option></select></div>
<div class="neden">....... ?</div>
</div>
<div class="ekt">Cinsiyet</div>
<div class="erkek_kadin"><div class="erkek"><div class="check"><input type="radio" name="gender"
<?php if (isset($gender) && $gender=="female") echo "checked";?>
value="female"></div><div class="k_etxt">Erkek</div></div>
<div class="kadin"><div class="check"><input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") echo "checked";?>
value="male"></div><div class="k_etxt">Kadın</div></div></div>
<div class="attantion">Hesap Aç düğmesine tıklayarak, Çerez Kullanımı dahil Veri Kullanımı İlkemizi okuduğunu ve Koşullarımızı kabul etmiş olursun.</div>
<div class="kaydol">
<div class="kaydol_buton">
<input type="submit" name="submit" value="Hesap Aç"/> </div>
</div>
</div>
</form>
And this is my PHP code:
<?php
include("includes/connect.php");
if(isset($_POST['submit'])){
$name = $_POST['name'];
$surname = $_POST['surname'];
$business_name = $_POST['business_name'];
$email = $_POST['email'];
$emailagain = $_POST['emailagain'];
$password = $_POST['password'];
$business_category = $_POST['business_category'];
$country = $_POST['country'];
$city = $_POST['city'];
$type = $_POST['type'];
if($name==''){
echo"<div class='error_name'>Write name!</div>";
exit();
}
if($surname==''){
echo"<div class='error_name'>Write surname!</div>";
exit();
}
if($business_name==''){
echo"<div class='error_name'>Write name write business name!</div>";
exit();
}
if($email==''){
echo"<div class='error_name'>write email!</div>";
exit();
}
if($_POST['email'] !== $_POST['emailagain']){
echo"<div class='error_name'>it is not much!</div>";
exit();
}
$check_email = "SELECT * FROM users WHERE email='$email'";
$run = mysql_query($check_email);
if(mysql_num_rows($run)>0){
echo "<div class='error_name'>this email alredy exist!</div>";
exit();
}
$query ="INSERT INTO `users` (`name`,`surname`,`business_name`, `email`,`emailagain`,`password`,`business_category`,`country`,`city`,`type`) VALUES ('$name','$surname','$business_name', '$email','$emailagain','$password','$business_category','$country','$city','type')";
$result = mysql_query($query) or die(mysql_error());
if($result){
echo("<center><h1>Success!</h1></center>");
}
else {
echo("<center><h1>Something wrong!</h1></center>");
}
}
?>
I noticed you have "type" in your SQL... why is it not 1 for business user?
$query ="...VALUES ('$name','$surname','$business_name', '$email','$emailagain','$password','$business_category','$country','$city','type')";

Categories