-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert.php
75 lines (51 loc) · 2.33 KB
/
insert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
session_start();
if (isset($_POST['Register'])){
$CUSTOMER_NAME = $_POST['CUSTOMER_NAME'];
$CUSTOMER_EMAIL = $_POST['CUSTOMER_EMAIL'];
$PASSWORD = $_POST['PASSWORD'];
$HOME_ADDRESS = $_POST['HOME_ADDRESS'];
$POST_CODE = $_POST['POST_CODE'];
$PHONE = $_POST['PHONE'];
}
$CUSTOMER_NAME= stripcslashes($CUSTOMER_NAME);
$CUSTOMER_EMAIL= stripcslashes($CUSTOMER_EMAIL);
$PASSWORD= stripcslashes($PASSWORD);
$HOME_ADDRESS= stripcslashes($HOME_ADDRESS);
$POST_CODE= stripcslashes($POST_CODE);
$PHONE= stripcslashes($PHONE);
//create connection $sql = "INSERT INTO customer(CUSTOMER_NAME,CUSTOMER_EMAIL,PASSWORD,HOME_ADDRESS,POST_CODE,PHONE)VALUES('$CUSTOMER_NAME','$CUSTOMER_EMAIL', '$PASSWORD','$HOME_ADDRESS','$POST_CODE','$PHONE')";
$conn=mysqli_connect("localhost","root","","ecom");
if($conn === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}
else{
$CUSTOMER_NAME = mysqli_real_escape_string($conn, $CUSTOMER_NAME);
$CUSTOMER_EMAIL = mysqli_real_escape_string($conn, $CUSTOMER_EMAIL);
$PASSWORD= mysqli_real_escape_string($conn, $PASSWORD);
$HOME_ADDRESS = mysqli_real_escape_string($conn, $HOME_ADDRESS);
$POST_CODE = mysqli_real_escape_string($conn, $POST_CODE);
$PHONE = mysqli_real_escape_string($conn, $PHONE);
$s="SELECT * FROM customer where CUSTOMER_EMAIL='$CUSTOMER_EMAIL'";
$result = mysqli_query($conn,$s);
$num= mysqli_num_rows($result);
if($num ==1)
{
echo "username already taken";
}
if(strlen($PHONE)!=10)
{
echo "<script> alert('Invalid Phone Number, Please Enter Valid 10-digit Phone Number');window.location='index.php'</script>";
}
if(strlen($POST_CODE)!=6)
{
echo "<script> alert('Invalid Phone Number, Please Enter Valid 6-digit Post Code');window.location='index.php'</script>";
}
else{
$sql = "INSERT INTO customer(CUSTOMER_ID,CUSTOMER_NAME,CUSTOMER_EMAIL,PASSWORD,HOME_ADDRESS,POST_CODE,PHONE)VALUES('','$CUSTOMER_NAME','$CUSTOMER_EMAIL', '$PASSWORD','$HOME_ADDRESS','$POST_CODE','$PHONE')";
mysqli_query($conn,$sql);
echo "<script> alert('Registration Successful! Please Login to start shopping'); window.location='index.php'</script>";
}
}
?>