<?php error_reporting(0); $servername="localhost"; $username="root"; $password=""; $database="test"; $con= mysqli_connect($servername,$username,$password,$database) or die('connection failed'); if($con){ // echo 'Connection is set'; } //delete if($_GET['del']){ $delSql= "DELETE FROM webiste WHERE website_id= '".$_GET['del']."' "; // echo $delSql; $RunDel= mysqli_query($con,$delSql); if($RunDel){ echo '<h3 style="text-align:center;color:red;">data deteted !!!</h3>'; ?> <meta HTTP-EQUIV="Refresh" content="4; URL=index.php"><?php } } // if(isset($_POST['save'])){ if(isset($_POST['website_id'])){ // print_r($_POST);{} // if($_POST['website_id']==''){ $insql= "INSERT INTO webiste (website_url) VALUES('".$_POST['url']."')"; // echo $insql; $Runquery= mysqli_query($con,$insql); if($Runquery){ echo '<h3 style="text-align:center;color:green;">data inserted !!!</h3>'; ?> <meta HTTP-EQUIV="Refresh" content="4; URL=index.php"><?php } } // } //fetch and update if($_GET['uid']!=''){ $fet="SELECT *FROM webiste WHERE website_id= '".$_GET['uid']."'"; $runfet=mysqli_query($con,$fet); // echo print_r($runfet); $editdata=mysqli_fetch_assoc($runfet); } if($_POST['website_id']!=''){ $upSQL= "UPDATE webiste SET website_url='".$_POST['url']."' WHERE website_id='".$_POST['website_id']."' "; // echo $upSQL; $runupsql= mysqli_query($con,$upSQL); if($runupsql){ echo '<h3 style="text-align:center;color:green;">data updated !!!</h3>'; } } ?> <!DOCTYPE html> <html> <body> <h1>WEBSITE URL CRUD</h1> <form action="<?php $_SERVER["PHP_SELF"] ?>" method="POST"> <label for="homepage">Add your homepage:</label> <input type="hidden" id="homepage" name="website_id" value="<?php echo $_GET['uid']; ?>"> <input type="url" id="homepage" name="url" value="<?php echo $editdata['website_url'] ?>"><br><br> <input type="submit" name="save"> </form> <table width="100%" cellpadding="10px" cellspacing="10px" border="2px"> <thead> <tr style="text-align:center; background-color:black;color:#fff;"> <th>Sr No</th> <th>Webiste Url</th> <th>Operation</th> </tr> </thead> <tbody> <?php $disSql ="SELECT *FROM webiste"; $rundisql= mysqli_query($con,$disSql); if(mysqli_fetch_row($rundisql)>0){ // echo 'ROW Found'; $abc=1; foreach($rundisql as $key=>$value){ echo '<tr style="text-align:center;"> <td> '.$abc++.'</td> <td> <a href=" '.$value['website_url'].'"> '.$value['website_url'].'</a></td> <td> <a href="index.php?del='.$value["website_id"].'">DELETE</a> <a href="index.php?uid='.$value["website_id"].'">UPDATE</a> </td> </tr>'; } } ?> </tbody> </table> </body> </html>
May-21-2024 22:46:29
thanks for code
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