1
1
<?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 ' );
8
9
$ lat = $ _POST ["lat " ];
9
10
$ lon = $ _POST ["lon " ];
10
- $ address = filter_input (INPUT_POST ,'address ' );
11
+ $ address = filter_input (INPUT_POST , 'address ' );
11
12
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 {
24
39
include 'header.php ' ;
25
40
?>
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>
29
44
<?php
30
45
include '../php/register.php ' ;
31
46
}
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 ' ;
33
55
}
34
56
35
- ?>
57
+ // Closing the connection is optional; PDO does this automatically when the script ends.
58
+ ?>
0 commit comments