echo is showing output in page source instead of on page - php

I made a table in php and wanted to show the Id's in the dropdown select menu by making a separate file for php. So the code in main file is:
<?php include "functions.php";?>
<form action="login_update.php" method="post">
<div class="form-group">
<label for="username">username</label>
<input type="text" name="username" class="form-control">
</div>
<div class="form-group">
<label for="password">password</label>
<input type="password" name="password" class="form-control">
</div>
<div class="form-group">
<select name="id" id="">
<?php
showAllData();
echo "<br>"."askfkldfjl;adfafladfdf";
?>
</select>
</div>
<input class="btn btn-primary" type="submit" name="submit" value="update">
</form>
The code of functions.php is :
<?php
function showAllData(){
$connection = mysqli_connect('localhost','root','****','loginapp');
if($connection){
echo "We are connected. a=".$a."<br>";
}else{
die("Database connection failed");
}
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if($result){
echo("<br>"." <b><h6>We are successful</h6></b>");
}
else {
die("Query FAILED" . mysqli_error());
}
while($row = mysqli_fetch_assoc($result)) {
$id = $row["id"];
echo"<option value='$id'>$id</option>";
}
}
?>
The expected output was :
But the output is:
So the top two lines in the above screenshot are not printing.
These lines are shown in the INSPECT ELEMENT in chrome.
I forgot to mention the echo command:
echo "<br>"."askfkldfjl;adfafladfdf";
below show all data is also not working.

You made a mistake.
Actually you wrote a code in selectbox and you dont add option so thats why it is not show in html
So write a code like below code so its show in select box as option.
<div class="form-group">
<select name="id" id="">
<option> <?php
showAllData();
echo "<br>"."askfkldfjl;adfafladfdf";
?></option>
</select>
</div>
And If you want to show option from showAllData(); function, the you have return the html.
For this update your showAllData(); function with below code:
function showAllData(){
$options="";
$connection = mysqli_connect('localhost','root','****','loginapp');
if($connection){
echo "We are connected. a=".$a."<br>";
}else{
die("Database connection failed");
}
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if($result){
echo("<br>"." <b><h6>We are successful</h6></b>");
}
else {
die("Query FAILED" . mysqli_error());
}
while($row = mysqli_fetch_assoc($result)) {
$id = $row["id"];
$options.="<option value='$id'>$id</option>";
}
return $options;
}

Move the PHP function showAllData() before the HTML <select> element.
Because the <select> element awaits for an <option> element, but all another text will not be visible on page.
E.g.:
<div class="form-group">
<?php showAllData(); ?>
</div>
<?php
function showAllData(){
$connection = mysqli_connect('localhost','root','****','loginapp');
if($connection){
echo "We are connected. a=".$a."<br>";
}else{
die("Database connection failed");
}
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if($result){
echo("<br>"." <b><h6>We are successful</h6></b>");
}
else {
die("Query FAILED" . mysqli_error());
}
echo '<select name="id" id="">';
while($row = mysqli_fetch_assoc($result)) {
$id = $row["id"];
echo"<option value='$id'>$id</option>";
}
echo "</select>";
}
?>

Your code is mixed up.
You can use below code. Create an array which gives you values which you needs to show in select.
<?php
function showAllData(){
$idArr = array('msg'=>'','data'=>'','status'=>0);
$connection = mysqli_connect('localhost','root','****','loginapp');
if($connection){
$idArr['msg'] = "We are connected";
$idArr['status'] = 1;
}else{
$idArr['msg'] = "Database connection failed";
$idArr['status'] = 0;
}
if($idArr['status'] == 1){
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if($result){
$idArr['msg'] = "We are successful";
$idArr['status'] = 1;
}else {
$idArr['msg'] = "Query FAILED" . mysqli_error();
$idArr['status'] = 0;
}
if($idArr['status'] == 1){
while($row = mysqli_fetch_assoc($result)) {
$idArr['data'][] = $row["section_id"];
}
}
}
return $idArr;
}
$idArr = showAllData();
?>
<?php
if(!empty($idArr['data'])){
echo "We are connected<br>";
echo("<br>"." <b><h6>We are successful</h6></b>");
?>
<form action="login_update.php" method="post">
<div class="form-group">
<label for="username">username</label>
<input type="text" name="username" class="form-control">
</div>
<div class="form-group">
<label for="password">password</label>
<input type="password" name="password" class="form-control">
</div>
<div class="form-group">
<select name="id" id="">
<option value="0">--Select--</option>
<?php
foreach ($idArr['data'] as $key => $value) {
echo"<option value='$value'>$value</option>";
}
?>
</select>
</div>
<input class="btn btn-primary" type="submit" name="submit" value="update">
</form>
<?php }else{
echo $idArr['msg'];
}
?>

Why you are putting <br> inside the select tag? select tag only accept the options tag under it, so please remove br tag and all extra strings inside the select tag. and you should echo the message above the select tag if you want to show your users.
Thanks

Related

"adding variable into mysqli"

I wrote the code below. When I pass $cat_title in myslqi and i print $query it runs the query but in mysql table cat_title field is empty.
<?php
if(isset($_POST['submit'])){
$cat_title = $_POST['cat_title'];
echo "this is cat_title: ".$cat_title."<br>";
if($cat_title ="" ){
echo "title shouldn't be empty";
}
else{
echo $cat_title."this is cat_tiltel";
$query = "INSERT INTO categories(cat_title) ";
$query .= "VALUE('{$cat_title}') ";
echo $query;
$create_category_query = mysqli_query($connection , $query);
if(!$create_category_query){
die("QUERY FAILD".mysqli_error($connection));
}
header("location:categories.php");
}
}
?>
<form action="" method="post">
<div class="form-group">
<label for="cat-title">category title</label>
<input class="form-control" type="text" name ="cat_title">
</div>
<div class="form-group">
<input class = type="submit" name ="submit" value ="Add category">
</div>
</form>
There is a typo error. Please write "VALUES". You have written just VALUE.
Plese try to use below sintex.
INSERT INTO `table_name`(column_1,column_2,...) VALUES (value_1,value_2,...);

How to populate dropdown field pre-selected with the existing data from another MySQL table?

In my database I have 2 tables:
To insert data, I have a form that populates dropdown options from the table formulation. This is what the insert form for formulation dropdown looks like:
<?php
$formulation = '';
$query = "SELECT * FROM formulation";
$result = mysqli_query($connect, $query);
while ($row = mysqli_fetch_array($result)) {
$formulation .= '<option value="' . $row["formulationID"] . '">' . $row["formulation_name"] . '</option>';
}
?>
<select>
<option value="">Select formulation</option>
<?php echo $formulation; ?>
</select>
Now I am working on the ‘Update’ form. But my question is how can I populate the ‘Formulation’ field dropdown with the data from the formulation table (like as the insert form) but pre-selected with the existing formulation value for the name from the items table? Like this image below:
I am having problem with how I should build the form. How should I proceed with this form?
<?php
$output = array('data' => array());
$sql = "SELECT * FROM items";
$query = $connect->query($sql);
while ($row = $query->fetch_assoc()) {
$output['data'][] = array(
$row['name'],
);
}
echo json_encode($output);
?>
<form action=" " method="POST">
<div>
<label>Name</label>
<input type="text"><br>
<label>Formulation</label>
<select >
<!--What should be the codes here? -->
</select>
</div>
<button type = "submit">Save changes</button>
</form>
Thanks in advance for your suggestion.
Note: I'm not a user of mysqli so maybe there will be some error, but you will get the idea. This will not tackle the update part, just the populate part
Since you are editing a certain item, I will assume that you have something to get the item's itemID.
<?php
$sql = "SELECT * FROM items WHERE itemID = ?";
$query = $connect->prepare($sql);
$query->bind_param("s", $yourItemID);
$query->execute();
$result = $query->fetch_assoc();
$itemName = $result['name'];
$itemFormulation = $result['formulation_fk'];
//now you have the name and the formulation of that certain item
?>
<form action=" " method="POST">
<div>
<label>Name</label>
<input type="text" value="<?php echo $itemName; ?>"><br>
<label>Formulation</label>
<select >
<?php
$query = "SELECT * FROM formulation";
$result = mysqli_query($connect, $query);
while ($row = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $row['formulationID']; ?>" <?php echo ($row['formulationID'] == $itemFormulation) ? 'selected' : ''; ?>>
<?php echo $row['formulation_name']; ?>
</option>
<?php
}
?>
</select>
</div>
<button type = "submit">Save changes</button>
</form>
I changed the code to better suit the problem, there may be typos, just comment for clarification
If I have understand Your question... You have to put Your result into a string. For example:
<?php
$output = array('data' => array());
$sql = "SELECT * FROM items";
$query = $connect->query($sql);
$option = '';
while ($row = $query->fetch_assoc()) {
$name=$row['name'],
$option.='<option value="$name">$name</option>'
}
echo json_encode($output);
?>
<form action=" " method="POST">
<div>
<label>Name</label>
<input type="text"><br>
<label>Formulation</label>
<select >
<?=$option?>
</select>
</div>
<button type = "submit">Save changes</button>
</form>
I hope to be of help
This should do the trick:
<?php
$itemsSql = "SELECT * FROM items WHERE itemId = 5";
$itemQuery = $connect->query($sql);
$item = $itemQuery->fetch_assoc();
$formulationsSql = "SELECT * FROM formulation";
$formulationsQuery = $connect->query($sql);
$formulations = $itemQuery->fetch_assoc();
?>
<form action="updateItem" method="POST">
<div>
<label>Item Name</label>
<input type="text" value="<?= $item[0]['name']; ?>"><br>
<label>Formulation</label>
<select>
<?php foreach($formulations as $formulation){
echo '<option value="'. $formulation['formulationId'].'">' .
$formulation['formulation_name'] . '</option>';
} ?>
</select>
</div>
<button type = "submit">Save changes</button>
</form>

DELETE query ears the last upload? [UPDATE]

I can not understand why the application delete the las upload.I am new in php and I hope to help me. Thank you.
Code: HTML
<div class="row">
<div class="col-md-6 col-centered">
<div class="newboxes" id="newboxes3">
<form class="form" method="POST">
<input type="text" id="nmPic" name="nmPic" placeholder="име на снимката" onfocus="this.placeholder = ''" onblur="this.placeholder = 'име на снимката'"></br>
<input type="text" id="price" class="priceFrom" name="priceFrom" placeholder="цена от" onfocus="this.placeholder = ''" onblur="this.placeholder = 'цена от'"></br>
<input type="text" id="price" class="priceTo" name="priceTo" placeholder="цена до" onfocus="this.placeholder = ''" onblur="this.placeholder = 'цена до'"></br>
<select name="picCat" id="picCat">
<option value="" selected disabled>Изберете категория</option>
<option value="Детски">Детски</option>
<option value="Сватби">Сватби</option>
<option value="Рожден ден">Рожден ден</option>
<option value="18+">18+</option>
<option value="Други">Други</option>
</select></br>
<input type="text" id="numPic" name="numPic" placeholder="номер на снимката" onfocus="this.placeholder = ''" onblur="this.placeholder = 'номер на снимката'"></br>
<input type="submit" name="showFilter" value="покажи" />
</form>
</div>
</div>
</div>
Code: php
<div class="row">
<div class="col-md-12 col-centered pic">
<form class='form' method='POST'>
<?php
if (isset($_POST["showFilter"]))
{
$picName = $_POST['nmPic'];
$priceFrom = $_POST['priceFrom'];
$priceTo = $_POST['priceTo'];
$picCat = isset($_POST['picCat']) ? $_POST['picCat'] : '';
$numPic = $_POST['numPic'];
$filter = " SELECT * FROM images WHERE status = '1'";
if ($numPic && !empty($numPic)) {
$filter .= " AND id='$numPic'";
}
if ($picName && !empty($picName)) {
$filter .= " AND img_content='$picName'";
}
if ($picCat && !empty($picCat)) {
$filter .= " AND category='$picCat'";
}
if ($priceTo && !empty($priceTo)) {
$filter .= " AND price < '$priceTo'+1";
}
if ($priceFrom && !empty($priceFrom)) {
$filter .= " AND price > '$priceFrom'";
}
$resFilter = $connect->query($filter);
if ($resFilter->num_rows > 0) {
while($row = mysqli_fetch_array($resFilter))
{
echo "<div class='col-md-3 picture'>
<img class='child-img' src='".$row["picture"]." '/></br>
<div class='number'>
<span class='id'>№ ".$row['id']."</br>
име: ".$row['img_content']."</br> категория: ".$row['category']."</br>
цена: ".$row['price']."лв.</br>
дата: ".$row['time']."ч.</br>
</span>
<input type='hidden' name='del' value=" .$row['id'].">
<input class='btn btn-danger' name='delete' type='submit' value='истрии'/>
</div>
</div>";
}
}
}
?>
</form>
</div>
</div>
<form method="POST">
<?php
if (isset($_POST['delete']))
{
$sql = "SELECT * FROM images WHERE status = '1'";
$res = $connect->query($sql);
while($row = mysqli_fetch_array($res))
{
$id = $_POST['del'];
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'paspartu';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'DELETE FROM images
WHERE id='.$id;
mysql_select_db('login');
mysql_query($sql);
mysql_close($conn);
}
}
?>
</form>
If pressed the delete button <input class="btn btn-danger" name="delete" type="submit" value="истрии"> , this delete the last upload image???
And can you tell me how to delete the image from upload folder "uploads/"? Thank you verry much.
It's because you don't have an input in your form that's named "showFilter". You need to either rewrite or remove:
if (isset($_POST["showFilter"]))
Try modified query delete
$sql = "DELETE FROM `your_database`.`images` WHERE `your_database`.`id` = $del_id";
As I can see your submit button is in separate form tag. That is why the button is responsible only for the first parent form and if it is pressed the page is only reloaded. It should be placed in the general form you use, so that it will be related with the general form action.
You need to take your submit button inside the form. You have used two different forms. It is the problem.
Try to write your code as below:-
<?php
// Take div and form tag outside the loop
echo "<div class='col-md-3 picture'>
<form class='form' method='POST'>";
// Loop start
while($row = mysqli_fetch_array($resFilter))
{
echo "<img class='child-img' src='".$row["picture"]." '/></br>
<div class='number'>
<span class='id'>№ ".$row['id']."
<input class='check' name='checkbox[]' type='checkbox' value='". $row['id']."'></br>
име: ".$row['img_content']."</br> категория: ".$row['category']."</br>
цена: ".$row['price']."лв.</br>
дата: ".$row['time']."ч.
</br></span>
<br></div>";
}
// Loop End
?>
<!-- submit button -->
<input class="btn btn-danger" name="delete" type="submit" value="истрии маркираните">
<?php
// end div and form tag outside the loop
echo "</form>
</div>";
if (isset($_POST['delete']) && isset($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $del_id){
$del_id = (int)$del_id;
$sql = "DELETE FROM images WHERE id = $del_id";
mysql_query($sql);
}
header('Location: admin.php');
}
Hope it will help you :)

How to pass a variable from one php block of code to another in one single page?

I am getting error to this probably, $result = mysql_query("Select setyear, YearName from tblset, tblyear where tblyear.ID=tblset.setyear group by setyear having tblset.setcours=".$res, $connection);
I want to pass the value of select name="studcourse" class="form-control"** which is in variable $res and put it on the $result variable under **select name="studyear" class="form-control".
Can anybody help me?
<form method="post" action="<?php echo $_SERVER['$PHP_SELF'];?>">
<div class="form-group">
<label>Student Course</label>
<select name="studcourse" class="form-control">
<?php
$result = mysql_query("Select setcours, course_desc from tblset, tbl_coursetype where tbl_coursetype.course_no=tblset.setcours group by setcours", $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
// 4. Use returned data
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"{$row[0]}\">{$row[1]}</option>";
}
?>
<?php
$res="";
$res=$_POST["studcourse"];
?>
</select>
</div>
<div class="form-group">
<label>Student Year</label>
<select name="studyear" class="form-control">
<?php
$result = mysql_query("Select setyear, YearName from tblset, tblyear where tblyear.ID=tblset.setyear group by setyear having tblset.setcours=".$res, $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
// 4. Use returned data
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"{$row[0]}\">{$row[1]}</option>";
}
?>
</select>
</div>
You need to define <?php $res ?> before starting html code as
<?php
$res = '';
if($_POST['studcource']){
$res = $POST['studcource'];
}
<form method="post" action="<?php echo $_SERVER['$PHP_SELF'];?>">
<div class="form-group">
<label>Student Course</label>
<select name="studcourse" class="form-control" onchange="document.form.submit();">
<?php
$result = mysql_query("Select setcours, course_desc from tblset, tbl_coursetype where tbl_coursetype.course_no=tblset.setcours group by setcours", $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
// 4. Use returned data
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"{$row[0]}\">{$row[1]}</option>";
} ?>
</select>
</div>
<div class="form-group">
<label>Student Year</label>
<select name="studyear" class="form-control">
<?php
$result = mysql_query("Select setyear, YearName from tblset, tblyear where tblyear.ID=tblset.setyear group by setyear having tblset.setcours=".$res, $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
// 4. Use returned data
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"{$row[0]}\">{$row[1]}</option>";
}
?>
</select>
</div>
You can pass one variable to another php using session variables :
<? Php
session_start();
$z=3;
$_SESSION['var_name'] =$z;? >
Second php :
<? Php
session_start() ;
$x=$_SESSION['var_name'] ;? >
Apologies in advance if this is not what you meant but I interpreted the question to mean that you wish to populate the second dropdown menu based upon the selection made in the first dropdown menu. To that end ( not tested ) the approach below implements ajax to send a POST request to the same page that is then used in the sql query. The results of the sql query are then used to generate the options for the second dropdown menu...
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' && isset( $_POST['studcourse'] ) ){
/* Generate the html and send to javascript callback to insert into select menu */
#ob_clean();
$studcourse=mysql_real_escape_string( $_POST['studcourse'] );
/*
Possible alternative SQL
------------------------
select s.`setyear`, yr.`YearName`
from `tblset` s
left outer join `tblyear` yr on yr.`id`=s.`setyear`
where s.`setcours`='".$studcourse."'
order by s.`setyear`;
*/
$sql="select `setyear`, `YearName`
from `tblset`, `tblyear`
where `tblyear`.`ID`=`tblset`.`setyear`
group by `setyear`
having `tblset`.`setcours`='".$studcourse."';";
$result=mysql_query( $sql, $connection );
if( $result ){
while( $row = mysql_fetch_array( $result ) ) {
echo "<option value='{$row[0]}'>{$row[1]}";
}
} else {
echo '<option>No results';
}
exit();
}
?>
<html>
<head>
<title>Example - set select menu based upon value from previous select menu</title>
<script type='text/javascript'>
function cbstudyear(r){
document.getElementById('studyear').innerHTML=r;
}
function setstudyear( event ){
var el=typeof( event.target )!='undefined' ? event.target : event.srcElement;
var value=el.options[ el.options.selectedIndex ].value;
var req=new XMLHttpRequest();
var headers={
'Accept': "text/html, application/xml, application/json, text/javascript, "+"*"+"/"+"*"+"; charset=utf-8",
'Content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
};
req.onreadystatechange=function(){
if( req.readyState==4 ) {
if( req.status==200 ) cbstudyear.call( this, req.response );
else console.warn( 'Error: '+req.status+' status code returned' );
}
}
req.open( 'POST', document.location.href, true );
for( header in headers ) req.setRequestHeader( header, headers[ header ] );
req.send( 'studcourse=' + value );
}
</script>
</html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<label>Student Course</label>
<select name="studcourse" id='studcourse' class="form-control" onchange='setstudyear(event)'>
<?php
$result = mysql_query("select `setcours`,`course_desc`
from `tblset`, `tbl_coursetype`
where `tbl_coursetype`.`course_no`=`tblset`.`setcours`
group by `setcours`;", $connection );
if( $result ){
while( $row = mysql_fetch_array( $result ) ) {
echo "<option value=\"{$row[0]}\">{$row[1]}";
}
} else {
echo "<option>Database query failed";
}
?>
</select>
</div>
<div class="form-group">
<label>Student Year</label>
<select name="studyear" id='studyear' class="form-control">
</select>
</div>
<!--
Other form elements here presumably ~ including submit button etc
-->
</form>
</body>
</html>

View customer info on select change

I'm creating a page which will allow an admin to select a user from a drop down list, which populates from a database. When the person is selected, the info associated with that person will then be viewed on the page. I already have a select statement which selects all the info and the drop down menu is populating correctly. However, I'm unsure on how to get that selected user's info to display on the page once selected. Would I need to do an entirely different select statement and query which checks which customer was selected? Or is there another way?
customer.php
<div id="view_form" class="view">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<fieldset>
<label for="viewCustomer">Select Customer</label>
<?php
echo "<select name='selectCust' id='selectCust'>";
echo "<option></option>";
while($row = mysqli_fetch_assoc($custResult)){
$name = "{$row['fName']} {$row['lName']}";
echo "<option>$name</option>";
}
echo "</select>";
?>
</fieldset>
</form>
</div>
viewUser.php
if(isset($search)){
$select = "SELECT * FROM $cust WHERE acctNum='{$search}'";
$result = mysqli_query($db, $select);
if(mysqli_num_rows($result) > 0){
if($row = mysqli_fetch_assoc($result)){
$acct = "{$row['acctNum']}";
echo $acct;
}
}
}
script.js
$(document).ready(function(){
function searchAjax(){
var search = $('#selectCust').val();
$.post('includes/viewUser.php', {searchUsers: search}, function(data){
$('#view_form').append(data);
})
}
$('#selectCust').on('change', function(ev){
ev.preventDefault();
searchAjax();
})
})
Search.php
<script type="text/javascript "src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$(".dropdown-users").on("change",function(event){
event.preventDefault();
search_ajax_way();
});
});
function search_ajax_way(){
var search_this=$("dropdown-users").val();
$.post("Ajaxsearch.php", {searchusers : search_this}, function(data){
$(".results").html(data);
})
}
</script>
<div id="view_form" class="view">
<form method="post">
<fieldset>
<label for="viewCustomer">Select Customer</label>
<?php
echo "<select class="dropdown-users">";
echo "<option></option>";
while($row = mysqli_fetch_assoc($custResult)){
$name = "{$row['fName']} {$row['lName']}";
$acct = $row['acctNum'];
echo "<option value="$acct">$name ($acct)</option>";
}
echo "</select>";
?>
</fieldset>
</form>
</div>
<label>Enter</label>
<input type="text" name="search_query" id="search_query" placeholder="What You Are Looking For?" size="50"/>
<input type="<span id="IL_AD1" class="IL_AD">submit</span>" <span id="IL_AD6" class="IL_AD">value</span>="Search" id="button_find" />
<div class="results"></div>
//********************************************************************************************
********************************************************************************************//
Ajaxsearch.php
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db"); // Enter your information here
$term = $_POST['searchusers']
$term = mysqli_real_escape_string($con, $term);
if($term == "")
echo "Enter Something to search";
else {
$query = mysqli_query($con, "select * from USERDATEBASEHERE where ID = '{$term}' ");
$string = '';
if (mysqli_num_rows($query) > 0) {
if (($row = mysqli_fetch_assoc($query)) !== false) {
$string = "{$row['ID']}";
}
} else {
$string = "This Person does not exist";
}
echo $string;
}
?>
<div id="view_form" class="view">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<fieldset>
<label for="viewCustomer">Select Customer</label>
<?php
echo "<select name=\"somename\" onchange=\"this.form.submit();\">";
echo "<option value=\"\">Select User</option>";
while($row = mysqli_fetch_assoc($custResult)){
$name = "{$row['fName']} {$row['lName']}";
$acct = $row['acctNum'];
echo '<option value="'.$acct.'">$name ($acct)</option>';
}
echo "</select>";
?>
</fieldset>
</form>
</div>
The options must have some refering value, through which you can retrieve the details of selected user, whenever the value of option is not initiated then the default value of the option will be option's label.

Categories