Full Post Page

Latest Full Posts

SIMPLE PHP CRUD MYSQL

Category: Latest Source Code & Written by Admin On March-15-2024 13:53:36

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; }

Comments

Share your thoughts about this post

Why Choose Us:

Experienced Instructors: Our team of experienced instructors are passionate about coding and dedicated to helping you succeed. With years of industry experience and a knack for teaching, they'll guide you every step of the way. Beginner-Friendly Content: Don't worry if you're new to coding. Our tutorials are designed with beginners in mind, starting from the fundamentals and gradually building up to more advanced topics. Updated Content: Coding is a rapidly evolving field, and we're committed to keeping our content up-to-date with the latest trends, technologies, and best practices. Community Support: Learning to code is more fun and effective when you're part of a supportive community. Join our online community forums to connect with fellow learners, share insights, and collaborate on projects. Get Started Today: Ready to kickstart your coding journey? Subscribe to [Rupesh-Tech] on YouTube and start learning today! Don't forget to hit the bell icon to receive notifications whenever we upload new tutorials or go live with Q&A sessions. Remember, coding opens up a world of endless possibilities. Whether you're dreaming of becoming a software developer, launching your own startup, or simply exploring a new hobby, [Rupesh-Tech] is here to help you turn your coding aspirations into reality. Let's code together and unleash your full potential! Feel free to customize the content to better suit Rupesh-tech channel's branding and audience.



Recent Posts

IMAGE CRUD PHP MYSQL

September-04-2024 09:18:37


complete php project mysql

August-11-2024 11:31:12


LARAVEL 11 crud step by step

August-02-2024 23:22:25