Skip to content

Commit 631c8f5

Browse files
authored
Update saveregister.php
1 parent 942e50d commit 631c8f5

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed

newuser/saveregister.php

+47-24
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,58 @@
11
<?php
2-
$email = filter_input(INPUT_POST,'email');
3-
$name = filter_input(INPUT_POST,'name');
4-
$phone = filter_input(INPUT_POST,'phone');
5-
$bg = filter_input(INPUT_POST,'bg');
6-
$city = filter_input(INPUT_POST,'city');
7-
$pincode = filter_input(INPUT_POST,'pin');
2+
// Collecting form data
3+
$email = filter_input(INPUT_POST, 'email');
4+
$name = filter_input(INPUT_POST, 'name');
5+
$phone = filter_input(INPUT_POST, 'phone');
6+
$bg = filter_input(INPUT_POST, 'bg');
7+
$city = filter_input(INPUT_POST, 'city');
8+
$pincode = filter_input(INPUT_POST, 'pin');
89
$lat = $_POST["lat"];
910
$lon = $_POST["lon"];
10-
$address = filter_input(INPUT_POST,'address');
11+
$address = filter_input(INPUT_POST, 'address');
1112

12-
$conn = new mysqli("sql308.epizy.com","epiz_30952003","4TeSyJ2b5LHde","epiz_30952003_majorproject");
13-
if (mysqli_connect_error()){
14-
die('Connect Error('.mysqli_connect_error().')');
15-
}
16-
else{
17-
$sql = "INSERT INTO donordetails (address,bg,city,email,name,phn,pin,lat,lon)
18-
values('$address','$bg','$city','$email','$name','$phone','$pincode','$lat','$lon')";
19-
if ($conn->query($sql)){
20-
header("location:RS.php");
21-
exit();
22-
}
23-
else{
13+
// Include the database connection file
14+
require_once '../app/db.conn.php'; // Make sure $conn is defined in this file
15+
16+
try {
17+
// Prepare an SQL statement for execution
18+
$sql = "INSERT INTO donordetails (address, bg, city, email, name, phn, pin, lat, lon)
19+
VALUES (:address, :bg, :city, :email, :name, :phone, :pincode, :lat, :lon)";
20+
21+
$stmt = $conn->prepare($sql);
22+
23+
// Bind parameters
24+
$stmt->bindParam(':address', $address);
25+
$stmt->bindParam(':bg', $bg);
26+
$stmt->bindParam(':city', $city);
27+
$stmt->bindParam(':email', $email);
28+
$stmt->bindParam(':name', $name);
29+
$stmt->bindParam(':phone', $phone);
30+
$stmt->bindParam(':pincode', $pincode);
31+
$stmt->bindParam(':lat', $lat);
32+
$stmt->bindParam(':lon', $lon);
33+
34+
// Execute the prepared statement
35+
if ($stmt->execute()) {
36+
header("location: RS.php");
37+
exit();
38+
} else {
2439
include 'header.php';
2540
?>
26-
<div class="u-clearfix u-sheet u-sheet-1" style="border:1px solid red; width:fit-content; border-radius:20px; padding-left:10px;padding-right:20px;background-color:red; color:white;">
27-
<p><?php echo "Error: ".$conn->error;?></p>
28-
</div>
41+
<div class="u-clearfix u-sheet u-sheet-1" style="border:1px solid red; width:fit-content; border-radius:20px; padding-left:10px;padding-right:20px;background-color:red; color:white;">
42+
<p><?php echo "Error: Could not execute the query."; ?></p>
43+
</div>
2944
<?php
3045
include '../php/register.php';
3146
}
32-
$conn->close();
47+
} catch (PDOException $e) {
48+
include 'header.php';
49+
?>
50+
<div class="u-clearfix u-sheet u-sheet-1" style="border:1px solid red; width:fit-content; border-radius:20px; padding-left:10px;padding-right:20px;background-color:red; color:white;">
51+
<p><?php echo "Error: " . $e->getMessage(); ?></p>
52+
</div>
53+
<?php
54+
include '../php/register.php';
3355
}
3456

35-
?>
57+
// Closing the connection is optional; PDO does this automatically when the script ends.
58+
?>

0 commit comments

Comments
 (0)