I am working on an admin panel in php.
- My idea is to add a store in the admin panel and it should add the store in database.In the admin panel after submitting it should show the 4 buttons as shown in figure!
for this i have written some html ,but main problem is if i click on show stores it should add a php include and show below like thisBut the problem is without clicking on show stores the php iclude is default enable.Please help me to include the php file only if i press the show stores button.
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Database connection is created with the db AskCoupon.com -->
<?php
//Step1
if ( ! empty( $_POST ) ) {
// Connect to MySQL
$mysqli = new mysqli( 'localhost', 'root', 'sai123', 'askcoupon.com' );
// Check our connection
if ( $mysqli->connect_error ) {
die( 'Connect Error: ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error );
}
/*New Code added here*/
$storeName = $_POST['store_name'];
$check=mysqli_query($mysqli,"select * from featured_stores where store_name='$storeName'");
$checkrows=mysqli_num_rows($check);
if($checkrows>0){echo "customer exists";}
else{
//insert results from the form input
$query = "INSERT INTO featured_stores ( store_id, store_name,no_of_coupons,caption ) VALUES ( '{$mysqli->real_escape_string($_POST['store_id'])}', '{$mysqli->real_escape_string($_POST['store_name'])}', '{$mysqli->real_escape_string($_POST['no_of_coupons'])}', '{$mysqli->real_escape_string($_POST['caption'])}' )";
// $insert = $mysqli->query($sql);
$result = mysqli_query($mysqli, $query) or die('Error querying database.');
mysqli_close($mysqli);
echo "Store Added";
}
};
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Panel</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<a class="btn btn-primary" href="../admin_panel" role="button">Insert Another Store</a>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<a class="btn btn-danger" href="../admin_panel" role="button">Insert Another Coupon</a>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<a class="btn btn-success" href="../Admin_panel/show_stores.php" role="button" onclick="loadThis">Show Stores</a>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<button class="btn btn-success" href="#" role="button" onclick="loadThis">Show Coupons</button>
</div>
</div>
</div>
<script>
function loadThis(){
<?php include'show_stores.php';?>
}
</script>
</body>
</html>
Also I am including showstores.php file here
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<?php
// 1) connect to the database by mysql_connect()
mysql_connect("localhost", "root", "sai123") or die(mysql_error());
// 2) than select the database like mysql_select_db()
mysql_select_db("askcoupon.com") or die(mysql_error());
// 3) you need to use mysql_query()
$data = mysql_query("SELECT * FROM featured_stores where 1") or die(mysql_error());
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Panel</title>
</head>
<body>
<div class="container">
<div class="row well">
<?php
while($row= mysql_fetch_array( $data )){ ?>
<div class="col-xs- col-sm- col-md-2 col-lg-">
<?php echo $row['store_id']; ?>
</div>
<div class="col-xs- col-sm- col-md-4 col-lg-">
<?php echo $row['store_name'] ?>
</div>
<div class="col-xs- col-sm- col-md-3 col-lg-">
<?php echo $row['no_of_coupons'] ?>
</div>
<div class="col-xs- col-sm- col-md-3 col-lg-">
<?php echo $row['caption'] ?>
</div>
<?php } ?>
</div>
</div>
</body>
</html>
Console Log after answer 1