store the data into database through php form - php

I am trying to store the form data into database using ajax but it doesn't shows any success neither any error.
Here is my code.
<form method="POST" id="add_user" name='reg' >
<fieldset>
<legend>Student information:-</legend>
<ul>
<li>
<label> FirstName: </label><input type="text" id="name" name="name" required>
<span id='error' style="display:none;color:red;"> Only alphabets </span>
</li>
<li>
<label> LastName: </label><input type="text" id="lname" name="lname" required>
<span id='error1' style="display:none;color:red;"> Only alphabets </span>
</li>
<li>
<label>Username:</label>
<input type="text" id="username" name="username"/>
< /li>
<li>
<label>Password:</label>
<input type="password" id="password" name="password"/>
</li>
<label>
Gender: </label>
<input type="radio" id='gender' name="gender" value="male" required> Male
<input type="radio" name="gender" id='gender' value="female" required> Female
<input type="radio" name="gender" id='gender' value="other" required> Other
<li>
<label>
Email: </label>
<input id="email" type="text" name="email" required>
<span id='error2' style="display:none;color:red;"> Invalid email </span>
</li>
<li>
<label> Mobile:</label>
<input id="mobile" type="text" maxlength="10" name="mobile" required >
<span id='error3' style="display:none;color:red;"> only digits </span>
</li>
<li>
address: <textarea name="address" type="text" rows="3" cols="40"> </textarea>
</li>
</ul>
<p><button class = 'button' type="submit" id='submit'>Add User</button></p>
</fieldset>
</form>
This form in which i enter any values it got stored into database.
Here is my js file which uses ajax function to send data inext file which stores the result into database
serve.js
$(document).ready(function(){
$(document).on('submit','#add_user',function(e){
var form_data = $('#add_user').serialize();
var request = $.ajax({
url: 'fun.php?job=add',
cache : false,
data : form_data,
dataType : 'json',
contentType : 'application/json; charset=utf-8',
type : 'get'
});
request.done(function(output){
if (output.result == 'success'){
var name = $('#fname').val();
show_message("User '" + name + "' added successfully.", 'success' );
}, true);
} else{
show_message('Add request failed','error');
};
});
});
fun.php
if ($job != ''){
// Connect to database
$db_connection = mysqli_connect($db_server, $db_username, $db_password, $db_name);
if (mysqli_connect_errno()){
$result = 'error';
$message = 'Failed to connect to database: ' . mysqli_connect_error();
$job = '';
}
if ($job == 'add'){
/ / Add user
$query = "INSERT INTO oops ";
if (isset($_GET['name'])) { $query .= "name = '" . mysqli_real_escape_string($db_connection, $_GET['name']) . "', "; }
if (isset($_GET['lname'])) { $query .= "lname = '" . mysqli_real_escape_string($db_connection, $_GET['lname']) . "', "; }
if (isset($_GET['username'])) { $query .= "username = '" . mysqli_real_escape_string($db_connection, $_GET['username']) . "', "; }
if (isset($_GET['password'])) { $query .= "password = '" . mysqli_real_escape_string($db_connection, $_GET['password']) . "', "; }
if (isset($_GET['gender'])) { $query .= "gender = '" . mysqli_real_escape_string($db_connection, $_GET['gender']) . "', "; }
if (isset($_GET['email'])) { $query .= "email = '" . mysqli_real_escape_string($db_connection, $_GET['email']) . "', "; }
if (isset($_GET['mobile'])) { $query .= "mobile = '" . mysqli_real_escape_string($db_connection, $_GET['mobile']) . "', "; }
if (isset($_GET['address'])) { $query .= "address = '" . mysqli_real_escape_string($db_connection, $_GET['address']) . "'"; }
$query = mysqli_query($db_connection, $query);
if (!$query){
$result = 'error';
$message = 'query error';
} else {
$result = 'success';
$message = 'query success';
}
}
// Close database connection
mysqli_close($db_connection);
}
// Prepare data
$data = array(
"result" => $result,
"message" => $message,
"data" => $mysql_data
);
// Convert PHP array to JSON array
$json_data = json_encode($data);
print $json_data;
?>
Am I missing something please help if you found any fault in my code.

because you are using post method in your form:
<form method="POST" id="add_user" name='reg' >
and trying to receive params via get:
isset($_GET['name'])
just use post method everywhere
and also in jQuery you need to set:
type: "POST"

Related

How to Send Email verification using angularjs and php?

I created registration form and corresponding controller and backend php code.
The registered data is storing correctly . But i am not reciving mail in my email id. Please help me with this..
My html Code
<div class="col-lg-6 col-lg-offset-3 well " style="margin-top:1em; background-color:black; ">
<h4 style="color:white; text-align:center;"> <strong> FILL UP REGISTRAION FORM </strong> </h4>
</div>
<div class="col-lg-6 col-lg-offset-3 well" style="margin-bottom:10em;">
<form name="register" ng-app="TempleWebApp" ng-controller="RegisterCtrl" ng-submit="SignUp(register.$valid)" novalidate>
<!-- First Name -->
<div class="form-group col-lg-6" ng-class="{ 'has-error' : register.fname.$invalid && (register.fname.$dirty || submitted)}">
<label>First Name</label>
<input class="form-control" type="text" name="fname" ng-model="fname" placeholder="First Name" ng-required="true">
<span class="help-block" ng-show="register.fname.$invalid && register.fname.$error.required && (register.fname.$dirty || submitted)">
First Name is required.</span>
</div>
<!-- Last Name -->
<div class="form-group col-lg-6" ng-class="{ 'has-error' : register.lname.$invalid && (register.lname.$dirty || submitted)}">
<label>Last Name</label>
<input class="form-control" type="text" name="lname" ng-model="lname" placeholder="Last Name" ng-required="true">
<span class="help-block" ng-show="register.lname.$invalid && register.lname.$error.required && (register.lname.$dirty || submitted)">
Last Name is required.</span>
</div>
<!-- City -->
<div class="form-group col-lg-6" ng-class="{ 'has-error' : register.city.$invalid && (register.city.$dirty || submitted)}">
<label>City</label>
<input class="form-control" type="text" name="city" ng-model="city" placeholder="City" ng-required="true">
<span class="help-block" ng-show="register.city.$invalid && register.city.$error.required && (register.city.$dirty || submitted)">
City is required.</span>
</div>
<!-- Gender -->
<div class="form-group col-lg-6" ng-class="{ 'has-error' : register.gender.$invalid && (register.gender.$dirty || submitted)}">
<label>Gender</label> <br>
<input type="radio" name="gender" ng-model="gender" value="male" ng-required="true"> Male
<input type="radio" name="gender" ng-model="gender" value="female" ng-required="true" style="margin-left:5em;"> Female
<span class="help-block" ng-show="register.gender.$invalid && register.gender.$error.required && (register.gender.$dirty || submitted)">
Gender is required.</span>
</div>
<!-- Email -->
<div class="form-group col-lg-12" ng-class="{ 'has-error' : register.email.$invalid && (register.email.$dirty || submitted)}">
<label>Email</label>
<input class="form-control" type="text" name="email" ng-model="useremail" placeholder="Email" ng-pattern="/^[^\s#]+#[^\s#]+\.[^\s#]{2,}$/" ng-required="true">
<span class="help-block" ng-show="register.email.$invalid && register.email.$error.required && (register.email.$dirty || submitted)">
Email is required.</span>
<span class="help-block" ng-show="register.email.$error.pattern">
Enter Valid Email .</span>
</div>
<!-- Password -->
<div class="form-group col-lg-6" ng-class="{ 'has-error' : register.password.$invalid && (register.password.$dirty || submitted)}">
<label>Password</label>
<input class="form-control" type="password" name="password" ng-model="userpassword" placeholder="Password" ng-required="true">
<span class="help-block" ng-show="register.password.$invalid && register.password.$error.required && (register.password.$dirty || submitted)">
Password is required.</span>
</div>
<!-- CONFIRM PASSWORD -->
<div class="form-group col-lg-6" ng-class="{ 'has-error' : register.confirmPassword.$invalid && (register.confirmPassword.$dirty || submitted)}">
<label>Confirm Password</label>
<input type="Password" name="confirmPassword" class="form-control" ng-model="confirmPassword" placeholder="Confirm Your Password" ng-compare="password" ng-required="true">
<p ng-show="register.confirmPassword.$error.required && (register.confirmPassword.$dirty || submitted)" class="help-block">confirm password is required.</p>
<p ng-show="register.confirmPassword.$error.compare && (register.confirmPassword.$dirty || submitted)" class="help-block">Confirm password doesnot match.</p>
</div>
<div class="col-lg-12 well " ng-repeat="error in errors" style="background-color:red; margin-top:0.5em;"> {{ error}} </div>
<div class="col-lg-12 well" ng-repeat="msg in msgs" style="margin-top:0.5em;">
<h5 style="color:green;">{{ msg}} </h5>
</div>
<button type="submit" class="btn btn-success col-lg-12">
<span ng-show="searchButtonText == 'REGISTERING'"><i class="glyphicon glyphicon-refresh spinning"></i></span>
{{ searchButtonText }}
</button>
</form>
</div>
My controller
app.controller('RegisterCtrl', function ($scope,$location, $http,$timeout) {
$scope.gender = '';
$scope.errors = [];
$scope.msgs = [];
$scope.searchButtonText = "REGISTER DETAILS";
$scope.test = "false";
$scope.SignUp = function(isValid) {
// Set the 'submitted' flag to true
$scope.submitted = true;
$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);
if (isValid) {
$http.post('php/register.php',
{ 'fname': $scope.fname,
'lname': $scope.lname,
'city': $scope.city,
'gender': $scope.gender,
'pswd' : $scope.userpassword,
'email': $scope.useremail
})
.success(function(data, status, headers, config) {
if (data.msg != '')
{
$scope.msgs.push(data.msg);
$scope.test = "true";
$scope.searchButtonText = "REGISTERING";
//var goTopayment = function() { $scope.searchButtonText = "REGISTER DETAILS"; $location.path('/login'); };
// $timeout(goTopayment, 3000);
}
else
{
$scope.errors.push(data.error);
}
})
.error(function(data, status) { // called asynchronously if an error occurs or server returns response with an error status.
$scope.errors.push(status);
});
} // closing bracket for IF(isvalid)
} // closing bracket for $scope.SIGNUP = function
}); // closing bracket for register
My php Code is
<?php
$data = json_decode(file_get_contents("php://input"));
$fname = mysql_real_escape_string($data->fname);
$lname = mysql_real_escape_string($data->lname);
$city = mysql_real_escape_string($data->city);
$gender = mysql_real_escape_string($data->gender);
$upswd = mysql_real_escape_string($data->pswd);
$uemail = mysql_real_escape_string($data->email);
$con = mysql_connect('localhost', 'root', '');
mysql_select_db('registraion', $con);
$qry_em = 'select count(*) as cnt from users where Email ="' . $uemail . '"';
$qry_res = mysql_query($qry_em);
$res = mysql_fetch_assoc($qry_res);
if($res['cnt']==0){
$qry = 'INSERT INTO users (Firstname,Lastname,City,Gender,Password,Email) values
("' . $fname . '","' . $lname . '","' . $city . '","' . $gender . '","' . $upswd . '","' . $uemail . '")';
$qry_res1 = mysql_query($qry);
if (!$qry_res1) {
die('Invalid query: ' . mysql_error());
} else {
return mysql_insert_id();
}
$current_id = mysql_insert_id(); //last insert id
if(!empty($current_id)) {
$actual_link = "http://localhost/angular/php/"."activate.php?uid=" . $current_id;
$EmailTo = $uemail ;
$Subject = "User Registration Activation Email";
$Content = "Click this link to activate your account. <a href='" . $actual_link . "'>" . $actual_link . "</a>";
$MailHeaders = "From: Admin\r\n";
$success = mail($EmailTo, $Subject, $Content, $MailHeaders);
if($success ) {
$arr = array('msg' => "You have registered and the activation mail is sent to your email. Click the activation link to activate you account.", 'error' => '');
$jsn = json_encode($arr);
print_r($jsn);
}
}
}
else
{
$arr = array('msg' => "", 'error' => 'User Already exists with same email');
$jsn = json_encode($arr);
print_r($jsn);
}
?>
Finally I solved it. The problem was finding last inserted id value for $current_id variable.Since i was not getting correct value for this variable, value for $Emailto variable is not assigned with email id. So I changed php code to following way.
<?php
$data = json_decode(file_get_contents("php://input"));
$fname = mysql_real_escape_string($data->fname);
$lname = mysql_real_escape_string($data->lname);
$city = mysql_real_escape_string($data->city);
$gender = mysql_real_escape_string($data->gender);
$upswd = mysql_real_escape_string($data->pswd);
$uemail = mysql_real_escape_string($data->email);
$con = mysql_connect('localhost', 'root', '');
mysql_select_db('registraion', $con);
$qry_em = 'select count(*) as cnt from users where Email ="' . $uemail . '"';
$qry_res = mysql_query($qry_em);
$res = mysql_fetch_assoc($qry_res);
if($res['cnt']==0){
$qry = 'INSERT INTO users (Firstname,Lastname,City,Gender,Password,Email) values
("' . $fname . '","' . $lname . '","' . $city . '","' . $gender . '","' . $upswd . '","' . $uemail . '")';
$qry_res1 = mysql_query($qry);
//changed current_id value finding method.
$current_id = mysql_query("select uid from users ORDER BY uid DESC LIMIT 1"); //last insert id
if(!empty($current_id)) {
$actual_link = "http://localhost/angular/php/"."activate.php?uid=" . $current_id;
$EmailTo = $uemail;
$Subject = "User Registration Activation Email";
$Content = "Click this link to activate your account. <a href='" . $actual_link . "'>" . $actual_link . "</a>";
$MailHeaders = "From: Admin\r\n";
if(mail($EmailTo, $Subject, $Content, $MailHeaders) ) {
$arr = array('msg' => "You have registered and the activation mail is sent to your email. Click the activation link to activate you account.", 'error' => '');
$jsn = json_encode($arr);
print_r($jsn);
}
}
}
else
{
$arr = array('msg' => "", 'error' => 'User Already exists with same email');
$jsn = json_encode($arr);
print_r($jsn);
}
?>

Parse value of input field to query parameters

Can I parse the value of an input field to a query parameter to get the values of a select field within the same form?
The code is following:
<FORM ACTION="login.php" METHOD=get>
<label for="email">Email: </label>
<input id="email" name="email" type="text" ><br>
<label for="pin">Password: </label>
<input id="pin" name="pin" type="password" ><br>
<label for="company">Company</label>
<select name="Company" id="company">
<option>Select Company:</option>
<?php
$conn= new mysqli($servername,$username,$password,$db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connet_error);
}
$email = isset($_GET['email'])?$_GET['email']:"";
$sql="select company from accounts WHERE email = '$email';";
$results = mysqli_query($conn, $sql);
if ($results->num_rows > 0){
while ($row = mysqli_fetch_array($results)){
echo "<option value=\"company1\">" .$row['company'] . "</option>";
}
}
?>
</select>
<input class="submit_btn" type="submit" value="Login"></input><br>
<a id="cust-nopin" href="javascript:;"><p class="text_centered_pass">Click here if you don't have a password</p></a>
</FORM>
Is that not possible?
In this scenario your best bet would be Ajax.
Your Form Page:
<form action="login.php" method=get>
<label for="email">Email: </label>
<input id="email" name="email" type="text" ><br>
<label for="pin">Password: </label>
<input id="pin" name="pin" type="password" ><br>
<label for="company">Company</label>
<select name="Company" id="company">
<option value="">Select Company:</option>
</select>
<input class="submit_btn" type="submit" value="Login"></input><br>
<a id="cust-nopin" href="javascript:void(0);"><p class="text_centered_pass">Click here if you don't have a password</p></a>
</form>
Now the JQuery Part:
$(function () {
$(document).on("change, blur, keydown", "#email", function () {
$.ajax({
url: 'path/to/ajaxfile.php',
type: 'GET',
dataType: 'json',
data: {email: $(this).val()},
})
.done(function(response) {
if (response.status) {
var html = '<option value="">Select Company:</option>' + response.html;
$("#company").html(html);
} else {
console.log(status.message);
}
})
.fail(function(data) {
alert("Something went wrong please try again later.");
console.log(data.responseText);
});
});
});
And then the path/to/ajaxfile.php:
$conn = new mysqli($servername,$username,$password,$db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connet_error);
}
if (! empty($_GET['email'])) {
$email = mysqli_real_escape_string($conn, $_GET['email']);
$sql = "SELECT company FROM accounts WHERE email = '$email'";
$results = mysqli_query($conn, $sql);
if ($results->num_rows > 0){
$html = "";
while ($row = mysqli_fetch_array($results)){
$html .= '<option value="' . $row['company'] . '">' . $row['company'] . '</option>';
}
echo json_encode(array("status" => true, "html" => $html));
} else {
echo json_encode(array("status" => false, "message" => "There is no company with that email address."));
}
} else {
echo json_encode(array("status" => false, "message" => "No email is there to lookup."));
}
This should help you achieve what you are trying to do...
I hope it helps.
Yes of course you can use an input field's value as a parameter for your query. It is a very common scenario.
Your query does not work because you have included the $email variable inside single quotes. So this should work:
$sql="select company from accounts WHERE email = $email";
(the semicolon at the end is not needed).
BUT
This way of using user input to query the database is a bad practice as it makes your code vulnerable to SQL Injection.
To safeguard against SQL Injection it is recommended to use Prepared Statements
So you should query the database like this:
$sql="select company from accounts WHERE email = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $email);
$stmt->execute();

Cannot post data to MySql database from my ionic app

I am not able to post data to MySql database. I am running the project on chrome browser(windows7). Here I can see the params but they are not sent to the database table. What actually is the problem with my code?
My php code is:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
$postdata = file_get_contents("php://input");
$email = $postdata->email;
$password = $postdata->password;
$username = $postdata->username;
$con = mysqli_connect("localhost","root",'') or die ("Could not connect: " . mysql_error());;
mysqli_select_db($con, 'db_lastLog');
$qry_em = 'select count(*) as cnt from users where email ="' . $email . '"';
$qry_res = mysqli_query($con, $qry_em);
$res = mysqli_fetch_assoc($qry_res);
if($res['cnt']==0){
$qry = 'INSERT INTO users (name,pass,email) values ("' . $username . '","' . $password . '","' . $email . '")';
$qry_res = mysqli_query($con, $qry);
if ($qry_res) {
echo "1";
} else {
echo "2";;
}
}
else
{
echo "0";
}
?>
My controller code is:
.controller('SignupCtrl', function($scope, $http) {
$scope.signup = function (userdata) {
var request = $http({
method: "POST",
url: "http://localhost/lastLog.php",
crossDomain : true,
data: {
username : userdata.username,
password : userdata.password,
email : userdata.email
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
/* Successful HTTP post request or not */
request.success(function(data) {
if(data == "1"){
$scope.responseMessage = "Successfully Created Account";
}
if(data == "2"){
$scope.responseMessage = "Cannot Create Account";
}
else if(data == "0") {
$scope.responseMessage = "Email Already Exist"
}
});
}
})
My html code is:
<ion-pane>
<ion-header-bar class="bar-positive">
<h2 class="title">SignUp</h2>
</ion-header-bar>
<ion-view view-title="SignUp" name="signup-view">
<ion-content class="has-header" ng-controller="SignupCtrl">
<div class="list list-inset">
<label class="item item-input">
<input class="form-control" type="text" ng-model="userdata.username" placeholder="Enter Username">
</label>
<label class="item item-input">
<input type="text" ng-model="userdata.email" placeholder="Enter Your Email">
</label>
<label class="item item-input">
<input class="form-control" type="password" ng-model="userdata.password" placeholder="Enter Your Password">
</label>
<button class="button button-block button-positive" ng-click="signup(userdata)">SignUp</button><br>
<span>{{responseMessage}}</span>
</div>
</ion-content>
</ion-view>
</ion-pane>

When I try to insert data into database through angularjs, neither it gives error nor gives any result. How to solve it?

I am new to angularjs. When I try to insert data into database through angularjs, neither it reports error nor gives any result.
I have included 3 files here. I am trying to insert data with this code.
index.html
<form name="add_product" method="post">
<div class="lable_left">
<p>First Name :</p>
<p>Last Name :</p>
<p>Address :</p>
<p>Age :</p>
<p>Department :</p>
</div>
<div class="input_left">
<p><input type="text" name="fname" ng-model="fname"></p>
<p><input type="text" name="lname" ng-model="lname"></p>
<p><input type="text" name="address" ng-model="address"></p>
<p><input type="text" name="age" ng-model="age"></p>
<p><input type="text" name="dept" ng-model="dept"></p>
<input type="hidden" name="eid" ng-model="eid" />
<input type="button" name="submit_product" ng-show='add_prod' value="Submit" ng-click="product_submit()" class="submitbutton">
<input type="button" name="update_product" ng-show='update_prod' value="Update" ng-click="update_product()" class="submitbutton">
</div>
</form>
db.php
<?php
include('config.php');
switch($_GET['action']) {
case 'add_product' :
add_product();
break;
}
function add_product() {
$data = json_decode(file_get_contents("php://input"));
$fname = $data->fname;
$lname = $data->lname;
$address = $data->address;
$age = $data->age;
$dept = $data->dept;
print_r($data);
$qry = 'INSERT INTO employee (efname,elname,eaddress,eage,edept) values ("' . $fname . '","' . $lname . '",' .$address . ','.$age.','.$dept.')';
$qry_res = mysql_query($qry);
if ($qry_res) {
$arr = array('msg' => "Product Added Successfully!!!", 'error' => '');
$jsn = json_encode($arr);
// print_r($jsn);
}
else {
$arr = array('msg' => "", 'error' => 'Error In inserting record');
$jsn = json_encode($arr);
// print_r($jsn);
}
}
?>
controller.js
var listApp = angular.module('listpp', []);
listApp.controller('PhoneListCtrl', function ($scope,$http) {
/** function to get detail of product added in mysql referencing php **/
$scope.get_product = function() {
$http.get("db.php?action=get_product").success(function(data)
{
//$scope.product_detail = data;
$scope.pagedItems = data;
});
}
/** function to add details for products in mysql referecing php **/
$scope.product_submit = function() {
$http.post("db.php?action=add_product",
{
'efname' : $scope.fname,
'elname' : $scope.lname,
'eaddress' : $scope.address,
'eage' : $scope.age,
'edept' : $scope.dept
}
)
.success(function (data, status, headers, config) {
$scope.get_product();
})
.error(function(data, status, headers, config){
});
}
Any help will be highly appreciated,
Thanks

Page redirecting back to login page after insert to db

My site has a simplistic login that when you go to an adminSLP page it redirects to the admin login page if the user isnt logged in. Problem is that when you are logged in to the page and try say inserting a record with the form i posted below it redirects you back to the login page. I cant see where I am going wrong.
ADMIN SLP
session_start();
// Call this function so your page
// can access session variables
if ($_SESSION['adminloggedin'] != 1) {
// If the 'loggedin' session variable
// is not equal to 1, then you must
// not let the user see the page.
// So, we'll redirect them to the
// login page (login.php).
header("Location: adminLogin.php");
exit;
}
ADMIN LOGIN
session_start();
if ($_GET['login']) {
// Only load the
code below if the GET
// variable 'login' is set. You will
// set this when you submit the form
if ($_POST['adminusername'] == '******'
&& $_POST['adminpassword'] == '*******') {
// Load code below if both username
// and password submitted are correct
$_SESSION['adminloggedin'] = 1;
// Set session variable
header("Location: adminSLP.php");
exit;
// Redirect to a protected page
} else echo '<style>#falseLogin{display: block!important;}</style>';
// Otherwise, echo the error message
}
LOGIN FORM
<form method="POST" action="adminLogin.php?login=true" id="adminlogin" style="padding:0">
<label for="adminusername">Username:</label>
<input type="text" name="adminusername" autocomplete="off"><br/>
<label for="adminpassword">Password:</label>
<input type="password" name="adminpassword" autocomplete="off" /><br/>
<input type="submit" value="Login">
</form>
FORM MADE FOR INSERTING RECORDS TO A DB
<form id="trainingForm" method="post" action="" style="display:block;">
<div>
<h2 id="title" style="color:#c89d64;font-size:36px;font-family: 'RokkittRegular'; margin:0 0 15px; padding:30px 0 30px 0;font-weight:normal;">Add New SLP</h2>
<label for="first_name">First Name</label><input id="first_name" name="first_name" data-required="false" data-validation="length" data-validation-length="min4" type="text">
<label for="last_name">Last Name</label><input id="last_name" name="last_name" data-required="false" data-validation="length" data-validation-length="min4" type="text">
<label for="title">Title</label><input id="title" name="title" data-required="false" data-validation="length" data-validation-length="min4" type="text">
<label for="user_phone">Phone*</label><input id="user_phone" name="user_phone" type="tel" value="(123) 456-7890" data-required="true" onFocus="if(this.value == '(123) 456-7890') this.value='';">
<label for="user_email">Email*</label><input id="user_email" name="user_email" type="email" value="name#something.com" data-required="true" data-validation="email" onFocus="if(this.value == 'name#something.com') this.value='';">
<label for="state_name">License Held In:</label><select name='state_name[]' id="state_name" multiple>
<?php
$result = mysqli_query($con,'SELECT * FROM license_state');
$count = 1;
while($row = mysqli_fetch_array($result))
{
echo '<option value=' . $row['state_name'] . '>' . $row['state_name'] . '</option>';
}
?>
</select>
<span><label for="isChecked">May we post your information on our site?:</label>
<input type="radio" name="isChecked" value="1" checked="checked"><p>Yes</p>
<input type="radio" name="isChecked" value="0"><p>No</p></span>
<label for="asha_number">Asha# (Will Not Be Published)*</label><input id="asha_number" name="asha_number" data-required="true" data-validation="length" data-validation-length="min4" type="text">
<label for="practice_name">Practice Name*</label><input id="practice_name" name="practice_name" data-required="true" data-validation="length" data-validation-length="min4" type="text">
<label for="practice_location">Practice Location*</label><input id="practice_location" name="practice_location" data-required="true" data-validation="length" data-validation-length="min4" type="text">
<span><label for="telepracticeProvider">Are you a telepractice provider?:</label>
<input type="radio" name="telepracticeProvider" id="yes" value="Yes" ><p>Yes</p>
<input type="radio" name="telepracticeProvider" id="no" value="No" checked="checked"><p>No</p></span><br/>
<input type="hidden" id='user_id' name='user_id'/>
<br/><button name="submit" id="submit" type="submit">Submit</button>
</div>
</form>
insert to db
if(isset($_POST['submit']))
{// Create connection
$con=mysqli_connect("Speechvive.db.11357591.hostedresource.com","****","*****!","Speechvive");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$title = $_POST['title'];
$state_name = $_POST['state_name'];
$asha_number = $_POST['asha_number'];
$practice_name = $_POST['practice_name'];
$practice_location = $_POST['practice_location'];
$user_phone = $_POST['user_phone'];
$user_email = $_POST['user_email'];
$isChecked = $_POST['isChecked'];
$telepracticeProvider = $_POST['telepracticeProvider'];
$implodeStates = implode(', ',$state_name);
$insert = "INSERT INTO users ".
"(first_name,last_name, title, state_name, asha_number, practice_name, practice_location, user_phone, user_email, isChecked, telepracticeProvider) ".
"VALUES('$first_name','$last_name', '$title', '$implodeStates', $asha_number, '$practice_name', '$practice_location', '$user_phone', '$user_email', '$isChecked', '$telepracticeProvider')";
$insertData = mysqli_query( $con,$insert );
if(! $insertData )
{
die('Could not enter data: ' . mysql_error());
}
mysqli_close($con);?>
<script>window.location = "http://www.speechvive.com/adminSLP.php";//RELOAD THE CURRENT PAGE</script><?php
} else if(isset($_POST['save'])){
// Create connection
$con=mysqli_connect("Speechvive.db.11357591.hostedresource.com","Speechvive","Slp2014!","Speechvive");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$user_id = $_POST['user_id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$title = $_POST['title'];
$state_name = $_POST['state_name'];
$asha_number = $_POST['asha_number'];
$practice_name = $_POST['practice_name'];
$practice_location = $_POST['practice_location'];
$user_phone = $_POST['user_phone'];
$user_email = $_POST['user_email'];
$isChecked = $_POST['isChecked'];
$telepracticeProvider = $_POST['telepracticeProvider'];
$implodeStates = implode(', ',$state_name);
$update = ("UPDATE users SET first_name='$first_name',last_name='$last_name', title='$title', state_name='$implodeStates', asha_number='$asha_number', practice_name='$practice_name', practice_location='$practice_location', user_phone='$user_phone', user_email='$user_email', isChecked='$isChecked', telepracticeProvider='$telepracticeProvider' WHERE user_id = $user_id");
$updateData = mysqli_query( $con,$update );
if(! $updateData )
{
die('Could not enter data: ' . mysqli_error($con));
}
mysqli_close($con);?>
<script>window.location = "http://www.speechvive.com/adminSLP.php";</script><?php
}
window.location = "http://www.speechvive.com/adminSLP.php";
why did you wrote this in insert to db part.. I think this is creating the problem

Categories