quinta-feira, 2 de maio de 2019

Cpanel

<?php
// listar brand
require_once("includes/connection.php");
$table="brand";
$sql="SELECT * FROM $table";
$queryBrand=mysqli_query($connect, $sql) or die("erro 1");
$fetchBrand=mysqli_fetch_assoc($queryBrand);

// listar title
$table="title";
$sql="SELECT * FROM $table";
$queryTitle=mysqli_query($connect, $sql) or die("erro 2");
$fetchTitle=mysqli_fetch_assoc($queryTitle);

// update brand
if(isset($_GET['updateBrand'])){
    $table="brand";
    $href=addslashes($_GET['href']);
    $a=addslashes($_GET['a']);
    $id=$_GET['id']; 
   $sql="UPDATE $table SET  href =  '$href', a =  '$a' WHERE  id = $id";
    mysqli_query($connect,$sql);
    header("Location:?brandChanged");
}

// update title
if(isset($_GET['updateTitle'])){
    $table="title";
    $title=addslashes($_GET['title']);
    $id=$_GET['id']; 
   $sql="UPDATE $table SET  title = '$title' WHERE  id = $id";
    mysqli_query($connect,$sql);
    header("Location:?titleChanged");
}


?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Cpanel</title>
</head>

<body>

 
    <div id="brand">
        <h2>Brand</h2>
        <form>
        ID: <input type="hidden" value="<?php echo $fetchBrand['id'];?>" name="id"><br>
Brand: <input type="text" value="<?php echo $fetchBrand['a'];?>" name="a"><br>
       href: <input type="text" value="<?php echo $fetchBrand['href'];?>" name="href"><br>
        <input type="submit" name="updateBrand" value="Update Brand">

        </form>

    </div>   
 
    <hr>
    <div id="title">
        <h2>Title</h2>
        <form>
            ID: <input type="hidden" name="id" readonly value="<?php echo $fetchTitle['id'];?>"><br>
   title: <input type="text" name="title" value="<?php echo $fetchTitle['title'];?>"><br>
    <input type="submit" name="updateTitle" value="Update Title">
        </form>
    </div>

</body>

</html>


Versão melhorada

<?php
// listar brand
require_once("includes/connection.php");
$table="brand";
$sql="SELECT * FROM $table";
$queryBrand=mysqli_query($connect, $sql) or die("erro 1");
$fetchBrand=mysqli_fetch_assoc($queryBrand);

// listar title
$table="title";
$sql="SELECT * FROM $table";
$queryTitle=mysqli_query($connect, $sql) or die("erro 2");
$fetchTitle=mysqli_fetch_assoc($queryTitle);

// listar menu
$table="menu";
$sql="SELECT * FROM $table";
$queryMenu=mysqli_query($connect, $sql) or die("erro 3");
$fetchMenu=mysqli_fetch_assoc($queryMenu);

// update menu
if(isset($_GET['updateMenu'])){
    $table="menu";
    $href=addslashes($_GET['href']);
    $a=addslashes($_GET['a']);
    $id=$_GET['id'];   
   $sql="UPDATE $table SET  href =  '$href', a =  '$a' WHERE  id = $id";
    mysqli_query($connect,$sql);
    header("Location:?menuChanged");
}


// update brand
if(isset($_GET['updateBrand'])){
    $table="brand";
    $href=addslashes($_GET['href']);
    $a=addslashes($_GET['a']);
    $id=$_GET['id'];   
   $sql="UPDATE $table SET  href =  '$href', a =  '$a' WHERE  id = $id";
    mysqli_query($connect,$sql);
    header("Location:?brandChanged");
}

// update title
if(isset($_GET['updateTitle'])){
    $table="title";
    $title=addslashes($_GET['title']);
    $id=$_GET['id'];   
   $sql="UPDATE $table SET  title = '$title' WHERE  id = $id";
    mysqli_query($connect,$sql);
    header("Location:?titleChanged");
}


?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Cpanel</title>
</head>

<body>

 
    <div id="menu">
        <h2>Menu</h2>
       
        <?php do {?>
        <form>
        ID: <input type="text" value="<?php echo $fetchMenu['id'];?>" name="id"><br>
Brand: <input type="text" value="<?php echo $fetchMenu['a'];?>" name="a"><br>
       href: <input type="text" value="<?php echo $fetchMenu['href'];?>" name="href"><br>
        <input type="submit" name="updateMenu" value="Update Menu">
        </form>
        <?php } while($fetchMenu=mysqli_fetch_assoc($queryMenu));?>
       

    </div>   
 
 
 
 
 
 
    <div id="brand">
        <h2>Brand</h2>
        <form>
        ID: <input type="hidden" value="<?php echo $fetchBrand['id'];?>" name="id"><br>
Brand: <input type="text" value="<?php echo $fetchBrand['a'];?>" name="a"><br>
       href: <input type="text" value="<?php echo $fetchBrand['href'];?>" name="href"><br>
        <input type="submit" name="updateBrand" value="Update Brand">

        </form>

    </div>   
   
    <hr>
    <div id="title">
        <h2>Title</h2>
        <form>
            ID: <input type="hidden" name="id" readonly value="<?php echo $fetchTitle['id'];?>"><br>
   title: <input type="text" name="title" value="<?php echo $fetchTitle['title'];?>"><br>
    <input type="submit" name="updateTitle" value="Update Title">
        </form>
    </div>

</body>

</html>


Sem comentários:

Enviar um comentário