Implemented userInfo submition but is don't work yet
This commit is contained in:
parent
d5b349342a
commit
9891cf1dc4
61
php/functions.php
Normal file
61
php/functions.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
function query_username($conn, $uid) {
|
||||||
|
$sql = "Select * From account Where C_ID= ? ";
|
||||||
|
$stmt = mysqli_stmt_init($conn);
|
||||||
|
if (!mysqli_stmt_prepare($stmt, $sql)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_stmt_bind_param($stmt, "s", $uid);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
|
||||||
|
$resultData = mysqli_stmt_get_result($stmt);
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
return $resultData;
|
||||||
|
}
|
||||||
|
|
||||||
|
function query_addUser($conn, $uid, $upass) {
|
||||||
|
$sql = "INSERT INTO account(C_ID,C_Password) VALUES( ? , ? )";
|
||||||
|
$stmt = mysqli_stmt_init($conn);
|
||||||
|
if (!mysqli_stmt_prepare($stmt, $sql)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_stmt_bind_param($stmt, "ss", $uid, $upass);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
|
||||||
|
$error = mysqli_stmt_errno($stmt);
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
function query_addUserInfo($conn, $uid) {
|
||||||
|
$sql = "INSERT INTO userInfo(C_ID,C_EMAIL,C_PHONE,C_ADDRESS,C_UNIT,C_CITY,C_COUNTRY,C_ZIP) VALUES( ? , '' , '' , '' , '' , '' , '' , '')";
|
||||||
|
$stmt = mysqli_stmt_init($conn);
|
||||||
|
if (!mysqli_stmt_prepare($stmt, $sql)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_stmt_bind_param($stmt, "s", $uid);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
|
||||||
|
$error = mysqli_stmt_errno($stmt);
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
function qeury_updateUserInfo($conn, $uid, $email, $phone, $address, $unit, $city, $country, $zip) {
|
||||||
|
$sql = "UPDATE userInfo SET C_EMAIL = ' ? ',C_PHONE = ' ? ',C_ADDRESS = ' ? ',C_UNIT = ' ? ',C_CITY = ' ? ',C_COUNTRY = ' ? ',C_ZIP = ' ? ' WHERE C_ID = ' ? '";
|
||||||
|
$stmt = mysqli_stmt_init($conn);
|
||||||
|
if (!mysqli_stmt_prepare($stmt, $sql)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_stmt_bind_param($stmt, "ssssssss", $email, $phone, $address, $unit, $city, $country, $zip, $uid);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
|
||||||
|
$error = mysqli_stmt_errno($stmt);
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@ -1,25 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'connection.php';
|
require_once 'connection.php';
|
||||||
|
require_once 'functions.php';
|
||||||
$conn = connectMysql();
|
$conn = connectMysql();
|
||||||
session_start();
|
session_start();
|
||||||
$userName = $_POST['username'];
|
$userName = $_POST['username'];
|
||||||
$passWord_user = $_POST['password'];
|
$passWord_user = $_POST['password'];
|
||||||
|
|
||||||
function query_username($conn, $uid) {
|
|
||||||
$sql = "Select * From account Where C_ID= ? ";
|
|
||||||
$stmt = mysqli_stmt_init($conn);
|
|
||||||
if (!mysqli_stmt_prepare($stmt, $sql)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
mysqli_stmt_bind_param($stmt, "s", $uid);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
|
|
||||||
$resultData = mysqli_stmt_get_result($stmt);
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
return $resultData;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = query_username($conn, $userName);
|
$result = query_username($conn, $userName);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,26 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'connection.php';
|
include 'connection.php';
|
||||||
|
require_once 'functions.php';
|
||||||
$conn = connectMysql();
|
$conn = connectMysql();
|
||||||
$userName = $_POST['username'];
|
$userName = $_POST['username'];
|
||||||
$passWord = $_POST['password'];
|
$passWord = $_POST['password'];
|
||||||
$passWord_hashed = password_hash($passWord, PASSWORD_DEFAULT);
|
$passWord_hashed = password_hash($passWord, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
function query_addUser($conn, $uid, $upass) {
|
|
||||||
$sql = "INSERT INTO account(C_ID,C_Password) VALUES( ? , ? )";
|
|
||||||
$stmt = mysqli_stmt_init($conn);
|
|
||||||
if (!mysqli_stmt_prepare($stmt, $sql)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
mysqli_stmt_bind_param($stmt, "ss", $uid, $upass);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
|
|
||||||
$error = mysqli_stmt_errno($stmt);
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// $query = "INSERT INTO account(C_ID,C_Password) VALUES('$userName','$passWord')";
|
// $query = "INSERT INTO account(C_ID,C_Password) VALUES('$userName','$passWord')";
|
||||||
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
|
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
|
||||||
|
|
||||||
@ -35,7 +20,14 @@ if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response
|
|||||||
echo "Verification success.";
|
echo "Verification success.";
|
||||||
$error = query_addUser($conn, $userName, $passWord_hashed);
|
$error = query_addUser($conn, $userName, $passWord_hashed);
|
||||||
if ($error === 0) {
|
if ($error === 0) {
|
||||||
|
|
||||||
|
$error = query_addUserInfo($conn, $userName);
|
||||||
|
if ($error === 0) {
|
||||||
echo "<script> alert('New account created successfully!');location.href='../index.php'; </script>";
|
echo "<script> alert('New account created successfully!');location.href='../index.php'; </script>";
|
||||||
|
} else {
|
||||||
|
echo "<script> alert('Error creating userInfo.');location.href='../index.php'; </script>";
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo "<script> alert('Username already exists.');location.href='../index.php'; </script>";
|
echo "<script> alert('Username already exists.');location.href='../index.php'; </script>";
|
||||||
}
|
}
|
||||||
|
|||||||
24
php/saveUserInfo.php
Normal file
24
php/saveUserInfo.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'connection.php';
|
||||||
|
require_once 'functions.php';
|
||||||
|
$conn = connectMysql();
|
||||||
|
require_once 'logged_in_header.php';
|
||||||
|
$userName = $_SESSION['username'];
|
||||||
|
$email = $_POST['email'];
|
||||||
|
$phone = $_POST['phone'];
|
||||||
|
$address = $_POST['address'];
|
||||||
|
$unit = $_POST['unit'];
|
||||||
|
$city = $_POST['city'];
|
||||||
|
$country = $_POST['country'];
|
||||||
|
$zip = $_POST['zip'];
|
||||||
|
$isChecked = $_POST['isChecked'];
|
||||||
|
|
||||||
|
if (isset($_POST['isChecked'])) {
|
||||||
|
$error = qeury_updateUserInfo($conn, $userName, $email, $phone, $address, $unit, $city, $country, $zip);
|
||||||
|
header("Location: ../shopping/userInfo.php?error=$error");
|
||||||
|
} else {
|
||||||
|
header("Location: ../shopping/userInfo.php?error=notChecked");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@ -3,7 +3,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once '../php/connection.php';
|
require_once '../php/connection.php';
|
||||||
$conn = connectMysql();
|
$conn = connectMysql();
|
||||||
session_start();
|
require_once '../php/logged_in_header.php';
|
||||||
?>
|
?>
|
||||||
<head>
|
<head>
|
||||||
<!-- Required meta tags -->
|
<!-- Required meta tags -->
|
||||||
@ -94,7 +94,7 @@
|
|||||||
|
|
||||||
<br>
|
<br>
|
||||||
<div class="d-grid gap-2 col-4 mx-auto">
|
<div class="d-grid gap-2 col-4 mx-auto">
|
||||||
<button class="btn btn-primary cart_button_1" type="button"> ❮ Continue Shopping</button>
|
<a class="btn btn-primary cart_button_1" type="button" href="shopping.php"> ❮ Continue Shopping</a>
|
||||||
<input class="btn btn-primary cart_button_2" type="submit" value="Go To Checkout" name="placeorder">
|
<input class="btn btn-primary cart_button_2" type="submit" value="Go To Checkout" name="placeorder">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once '../php/connection.php';
|
require_once '../php/connection.php';
|
||||||
$conn = connectMysql();
|
$conn = connectMysql();
|
||||||
session_start();
|
require_once '../php/logged_in_header.php';
|
||||||
?>
|
?>
|
||||||
<head>
|
<head>
|
||||||
<!-- Required meta tags -->
|
<!-- Required meta tags -->
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once '../php/connection.php';
|
require_once '../php/connection.php';
|
||||||
$conn = connectMysql();
|
$conn = connectMysql();
|
||||||
session_start();
|
require_once '../php/logged_in_header.php';
|
||||||
?>
|
?>
|
||||||
<head>
|
<head>
|
||||||
<!-- Required meta tags -->
|
<!-- Required meta tags -->
|
||||||
@ -38,41 +38,41 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12" id="">
|
<div class="col-sm-12" id="">
|
||||||
<h1>My billing address</h1>
|
<h1>My billing address</h1>
|
||||||
<form class="row g-3">
|
<form class="row g-3" action="../php/saveUserInfo.php" method="post">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<label for="inputEmail4" class="form-label">Email</label>
|
<label for="inputEmail4" class="form-label">Email</label>
|
||||||
<input type="email" class="form-control" id="inputEmail">
|
<input type="email" class="form-control" name="email" id="inputEmail">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<label for="inputPassword4" class="form-label">Phone</label>
|
<label for="inputPhone4" class="form-label">Phone</label>
|
||||||
<input type="tel" class="form-control" id="inputPhone" placeholder="123-456-7890" maxlength="12">
|
<input type="tel" class="form-control" name="phone" id="inputPhone" placeholder="123-456-7890" maxlength="12">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<label for="inputAddress" class="form-label">Address</label>
|
<label for="inputAddress" class="form-label">Address</label>
|
||||||
<input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
|
<input type="text" class="form-control" name="address" id="inputAddress" placeholder="1234 Main St">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<label for="inputAddress2" class="form-label"></label>
|
<label for="inputAddress2" class="form-label"></label>
|
||||||
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
|
<input type="text" class="form-control" name="unit" id="inputAddress2" placeholder="Apartment, studio, or floor">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<label for="inputCity" class="form-label">City</label>
|
<label for="inputCity" class="form-label">City</label>
|
||||||
<input type="text" class="form-control" id="inputCity">
|
<input type="text" class="form-control" name="city" id="inputCity">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<label for="inputState" class="form-label">State</label>
|
<label for="inputState" class="form-label">State</label>
|
||||||
<select id="inputState" class="form-select">
|
<select id="inputState" class="form-select" name="country">
|
||||||
<option selected>Choose...</option>
|
<option selected>Choose...</option>
|
||||||
<option>...</option>
|
<option>...</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
<label for="inputZip" class="form-label">Zip</label>
|
<label for="inputZip" class="form-label">Zip</label>
|
||||||
<input type="text" class="form-control" id="inputZip">
|
<input type="text" class="form-control" name="zip" id="inputZip">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input" type="checkbox" id="gridCheck">
|
<input class="form-check-input" type="checkbox" name="isChecked" id="gridCheck">
|
||||||
<label class="form-check-label" for="gridCheck">
|
<label class="form-check-label" for="gridCheck">
|
||||||
Check me out
|
Check me out
|
||||||
</label>
|
</label>
|
||||||
@ -80,6 +80,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<button type="submit" class="btn btn-primary">Save</button>
|
<button type="submit" class="btn btn-primary">Save</button>
|
||||||
|
<?php
|
||||||
|
if($_GET['error'] === "notChecked") {
|
||||||
|
echo '<div class="errorFont">Please check the box!</div>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@ -26,3 +26,5 @@ video
|
|||||||
z-index: -100
|
z-index: -100
|
||||||
object-fit: cover
|
object-fit: cover
|
||||||
|
|
||||||
|
.errorFont
|
||||||
|
color: red
|
||||||
@ -31,6 +31,10 @@ video {
|
|||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.errorFont {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
.index-page {
|
.index-page {
|
||||||
background-color: #edeae8;
|
background-color: #edeae8;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user