variable can't return value using in mysql query
This is my code:
Code:
<?php
if(isset($_POST['submit']) & !empty($_POST['appid'])) {
$app = mysql_real_escape_string($_POST['appid']);
//establish a connection
include('/var/config.php');
//database parameters
$conp = mysqli_connect($hostname, $user, $password, $database) or die('error in connection' . mysqli_error());
//actual data for appid's
$appsi = mysqli_query($conp, "SELECT distinct name FROM `app` where `app_id` = '$app'");
$all = array();
while($row = mysqli_fetch_assoc($appsi)) {
$all[] = '<br />' . $row["name"];
}
foreach ($all as $value) { ----> echo $value = shows
$install = mysqli_query($conp, "SELECT COUNT(*) from `stall` where name = '$value'");
$row = mysqli_fetch_array($install, MYSQL_BOTH);
$data = '<br>' . $row[0];
var_dump($data);
}
//total pn
$total = mysqli_query($conp, "SELECT COUNT(distinct name) FROM `user_app` where `app_id` = '$app'");
$row = mysqli_fetch_assoc($total);
$name = '<br />'. 'Total Packages in ' . '<b>' ."$app".' id '. '</b>'. ' : '. $row["COUNT(distinct name)"];
}
mysqli_close($conp);
?>
<html>
<head>
<title>Code</title>
</head>
<body>
<span style="text-align: center"><h1>@dnetwork (Beta)</h1></span>
<form name="query" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>Enter Application-Specific Id:</p>
<select name='appid'>
<?php
include('/var/config.php');
$conp = mysqli_connect($hostname, $user, $password, $database) or die('error in connection' . mysqli_error());
$getid = mysqli_query($conp, "SELECT distinct `app_id` from `user`;") or die('get data failed' . mysqli_error());
while(($row = mysqli_fetch_assoc($getid)) != null) {
echo "<option value = '{$row['app_id']}'";
if ($selected == $row['app_id']) {
echo "selected = 'selected'";
}
echo ">{$row['app_id']}</option>";
}
mysqli_close($conp);
?>
</select>
<p><input type="submit" name="submit" value="Go" /></p>
</form>
<div>
<p><?php echo '<br />' .'<b>'. 'Application Id : '. $app . '</b>'; ?> </p>
<p><?php echo implode("<br>", $all) . ' : ' .$data; ?></p>
<p><?php echo "$name"; ?></p>
</div>
</body>
</html>
on echo $value in foreach loop it shows the value but when i am using in mysql query, it shows 0. It is not syntax problem because it shows values when echo query, but can't using when fetch value from database using this variable.