<?php $servername ="localhost";$username ="root";$password ="";$dbname ="test"; $con= new mysqli($servername,$username,$password,$dbname); if($con->connect_error){ die("connection failed:" .$con->connect_error); } // echo '<pre>'; print_r($_POST);echo '</pre>'; //insert if(isset($_POST['save'])){ if($_POST['contacts_id']==''){ // if(isset($_FILES['upload_file'])){ $filename = @$_FILES['upload_file']['name']; $temname = @$_FILES['upload_file']['tmp_name']; $folder = "upload/" .$filename; move_uploaded_file($temname,$folder); // echo '<pre>'; print_r($_POST); echo '</pre>'; $insQuery = "INSERT INTO contacts (contacts_name,contacts_gender,contacts_subject,contacts_img,contacts_message) values('".@$_POST['name']."' ,'".@$_POST['gender']."','".@$_POST['subject']."','".$folder."','".@$_POST['message']."')"; $runQuery= $con->query($insQuery); if($runQuery){ echo "<h2>Data Inserted Successfully.</h2>"; }else{ echo "<h2>Data is Not Inserted Successfully.</h2>"; }}} //update if(@$_GET['uid']!=''){ $fetchSQL= "SELECT *FROM contacts where contacts_id='".$_GET['uid']."'"; $Runfet= $con->query($fetchSQL); $editdata= $Runfet->fetch_assoc(); } // if(isset($_POST['save'])){ if(@$_POST['contacts_id']!=''){ $folder= @$_POST['upload_old_file']; if($_FILES['upload_file']['name']!=''){ $filename= $_FILES['upload_file']['name']; $temname= $_FILES['upload_file']['tmp_name']; $folder= "upload/".$filename; move_uploaded_file($folder,@$tmp_name) ; } $updateSQL= "UPDATE contacts SET contacts_name='".$_POST['name']."' ,contacts_gender='".$_POST['gender']."' , contacts_subject='".$_POST['subject']."' , contacts_img='".$folder."' , contacts_message='".$_POST['message']."' WHERE contacts_id='".@$_POST['contacts_id']."'"; $RunUpdate= $con->query($updateSQL);} //delete if(@$_GET['del']!=''){ $delSQL="DELETE FROM contacts where contacts_id='".@$_GET['del']."'"; // $runDEl= mysqli_query($con,$delSQL); $runDEl= $con->query($delSQL); }?> <!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> </head> <body> <h2>Contact Form</h2> <form action="" method="POST" enctype="multipart/form-data"> <label for="name">Name:</label><br> <input type="hidden" id="name" name="contacts_id" value="<?php echo @$_GET['uid'] ?>"> <input type="text" id="name" name="name"value="<?php echo @$editdata['contacts_name']?>" required> <br><br> <label for="gender">Gender:</label><br> <input type="radio" id="male" name="gender" value="male" <?php if("male"==@$editdata['contacts_gender'] ) echo 'checked ="checked"'; ?> accept="" required> <label for="male">Male</label> <input type="radio" id="female" name="gender" value="female" <?php if("female"==@$editdata['contacts_gender']) echo 'checked="checked"'; ?>> <label for="female">Female</label><br><br> <label for="subject">Subject:</label><br> <select id="subject" name="subject" required> <option value="Select" <?php if("Select"==@$editdata['contacts_subject']) echo 'selected="selected"'; ?>>Select a subject</option> <option value="java" <?php if("java"==@$editdata['contacts_subject'])echo 'selected="selected"';?> > Java</option> <option value="html" <?php if("html"==@$editdata['contacts_subject'])echo 'selected="selected"';?>> HTML</option> <option value="css" <?php if("css"==@$editdata['contacts_subject']) echo 'selected="selected"';?>> CSS</option> <option value="php" <?php if("php"==@$editdata['contacts_subject'])echo 'selected="selected"';?>> PHP</option> </select><br><br> <label for="image">Image:</label><br> <input type="file" id="image" name="upload_file"><br><br> <input type="hidden" id="image" name="upload_old_file" value="<?php echo @$editdata['contacts_img'] ?>"> <?php if(@$editdata['contacts_img']!='')echo '<img src= "'.$editdata['contacts_img'].'"width="50px" <a href="'.$editdata['contacts_img'].'" target="_blank"> </a> ' ?> <label for="message">Message:</label><br> <textarea id="message" name="message" rows="4" required> <?php echo @$editdata['contacts_message'] ?> </textarea><br><br> <input type="submit" name="save" value="Submit"> </form> <table width="100%" cellpadding="12px" cellspacing="2px"> <thead> <tr> <th>#</th> <th>NAME</th> <th>PHOTO</th> <th>GENDER</th> <th>SUBJECT</th> <th>MESSGSGE</th> <th>OPERAATION</th> </tr> </thead> <tbody> <?php $Displaysql= "SELECT *FROM contacts"; $rundsql= $con->query($Displaysql); // print_r($rundsql); exit(); if($rundsql->num_rows >0){ $abc= 1; // while($row= $result->fetch_assoc()){ // while($row=mysqli_fetch_assoc($rundsql)){ foreach($rundsql as $key=>$value){ echo '<tr align="center"> <td> '.$abc++.';</td> <td> '.$value["contacts_name"].';</td> <td>'.$value["contacts_gender"].'</td> <td>'.$value["contacts_subject"].'</td> <td> <img src='.$value["contacts_img"].' width="50px" height="50px"</td> <td> '.$value["contacts_message"].'</td> <td> <a href="index1.php?uid='.$value["contacts_id"].'">Edit</a> <a href="index1.php?del='.$value["contacts_id"].'" >DELETE</a> </td> </tr>'; } }else{echo '<tr><td colspan="12"> NO ROW FOUND</td></tr>';} ?> </tbody></table> </body> </html>
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