create file index.php <?php $servername="localhost"; $username="root"; $password=""; $dbname="test"; $con=mysqli_connect($servername,$username,$password,$dbname) or die('connection failed'); if(@$_GET['del']!=''){ $DelSql= "DELETE FROM contacts WHERE contacts_id= '".@$_GET['del']."' "; $ExDel= mysqli_query($con,$DelSql) or die('Query failed'); if($ExDel){ echo '<script> alert("deleted success")</script>'; }} if(isset($_POST['contacts_id'])){ $name=@$_POST['name']; $email=@$_POST['email']; $message=@$_POST['message']; if(@$_POST['contacts_id']==''){ $InSql="INSERT INTO contacts (contacts_name,contacts_email,contacts_message) VALUES('$name','$email','$message')"; $ExInQ = mysqli_query($con,$InSql); if($ExInQ){ echo '<script> alert("data inserted!!!!!")</script>'; } }} if(isset($_POST['contacts_id'])){ // if(isset($_POST['submit'])){ $UpSql ="UPDATE contacts SET contacts_name='".@$_POST['name']."' ,contacts_email='".@$_POST['email']."', contacts_message = '".@$_POST['message']."' WHERE contacts_id ='".@$_GET['uid']."'"; // echo $UpSql; exit(); $ExUPQ= mysqli_query($con,$UpSql) or die('update query failed'); if($ExUPQ) {echo '<script> alert("updated success!!!!!!!")</script>';} header("Location: index.php");} if(@$_GET['uid']!=''){ $FetSqlID="SELECT *FROM contacts WHERE contacts_id='".@$_GET['uid']."'"; $ExFetq= mysqli_query($con,$FetSqlID) or die('fetquery failed'); $editData= mysqli_fetch_assoc($ExFetq);} ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Contact Form</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h2>Contact Us</h2> <form action="" method="POST"> <div class="form-group"> <label for="name">Your Name:</label> <input type="hidden" id="name" name="contacts_id" value="<?php @$_GET['uid']; ?>"> <input type="text" id="name" name="name" value="<?php echo @$editData['contacts_name']?>" placeholder="Enter your name" required> </div> <div class="form-group"> <label for="email">Your Email:</label> <input type="email" id="email" name="email" value="<?php echo @$editData['contacts_email'] ?>" placeholder="Enter your email" required> </div> <div class="form-group"> <label for="message">Message:</label><textarea id="message" name="message" rows="5" placeholder="Enter your message" required><?php echo @$editData['contacts_message'] ?></textarea> </div> <button type="submit" name="submit">Send Message</button> </form></div> <?php $DisSql="SELECT *FROM contacts "; $ExDq= mysqli_query($con,$DisSql) ; if(mysqli_num_rows($ExDq)>0){ //echo 'Row found'; ?> <h2>CRUD DATA</h2> <table> <thead> <tr> <th>SR</th> <th>Name</th> <th>Email</th> <th>Message</th> <th>Operation</th> </tr> </thead> <tbody> <?php $abc=1; foreach($ExDq as $key=>$value) { ?> <tr> <td><?php echo $abc++;?></td> <td><?php echo $value['contacts_name']?></td> <td><?php echo $value['contacts_email'];?></td> <td><?php echo $value['contacts_message'];?></td> <td><a href="index.php?uid=<?php echo $value['contacts_id'] ?>">Update</a> <a href="index.php?del=<?php echo $value['contacts_id']?>">Delete</a> </td> </tr> </tr><?php }} else{ echo '<tr><td colspan="10";align="center";> ROW NO FOUND</td></tr>'; }?> </tbody> </table> </body> </html> create style.css /* styles.css */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f4f4f4; } .container { width: 50%; margin: 50px auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h2 { text-align: center; } .form-group { margin-bottom: 20px; } label { display: block; font-weight: bold; } input[type="text"], input[type="email"], textarea { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; } textarea { resize: vertical; } button { display: block; width: 100%; padding: 10px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } /* table */ table { width: 100%; border-collapse: collapse; align-items: center; } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; } th { background-color: #f2f2f2; color: #333; font-weight: bold; } tr:hover { background-color: #f5f5f5; }
September-04-2024 09:18:37
August-11-2024 11:31:12
August-02-2024 23:22:25
May-12-2024 02:44:34
May-10-2024 20:14:30