Update multiple rows in mysql with php - php

Here is my code below. The problem is when I try to update info it instead clears all records and does not update. How can I get this script to update and not clear. Also, I have used this before and it worked fine but all the sudden it doesn't.. I might have removed something important.
<strong>Update multiple rows in mysql</strong><br>
<?php
$mysql_host = "mysql.com";
$mysql_user = "username";
$mysql_pass = "password";
$mysql_database = "dbname";
$tbl_name="test_mysql"; // Table name
// Connect to server and select databse.
mysql_connect("$mysql_host", "$mysql_user", "$mysql_pass")or die("cannot connect");
mysql_select_db("$mysql_database")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
$id = array();
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>"></td>
<td align="center"><input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>"></td>
<td align="center"><input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if(isset($_POST['Submit'])){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
echo "Good";
////header("location:update_multiple.php");
}
mysql_close();
?>

You have using wrong set of variables,
try
$name[$i] <-- access local variable, an array called $name
$_POST["name"][$i] <-- access $_POST, the form name instead
I would suggest you make use $row["id"] as index key (name[$row["id"]]),
instead of using sequential indexed (key (0, 1, 2...)

None of your variables are defined in your SQL ($name, $lastname, $email, $id).
In your for loop, use $_POST['name'][$i] and so forth.
Also, it seems like you have forgotten to put your id in some form (hidden) field?

try this:
<?php require_once('Connections/tlsc_conn.php');
mysql_select_db($database_tlsc_conn, $tlsc_conn);
$query_Recordset1 = "SELECT * FROM tbl_name";
$Recordset1 = mysql_query($query_Recordset1, $tlsc_conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
if(isset($_POST['submit'])) {
// $count = count($_POST['id']);
// $count=mysql_num_rows($Recordset1);
$submit = $_GET['submit'];
$i = ($_POST['count']);
$name = ($_POST['name']);
$lastname = ($_POST['lastname']);
$email = ($_POST['email']);
$id = ($_POST['id']);
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET name='{$_POST['name'][$i]}',
lastname='{$_POST['lastname'][$i]}',
email='{$_POST['email'][$i]}'
WHERE id='{$_POST['id'][$i]}'";
$row_Recordset1=mysql_query($sql1);
}
if($row_Recordset1){
header("location:lulu.php");
exit;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form name="form2" method="post" action="">
<table width="634" border="1">
<tr>
<td>id</td>
<td>name</td>
<td>lastname</td>
<td>email</td>
</tr>
<?php do { ?>
<tr>
<td><?php $id[]=$row_Recordset1['id']; ?><?php echo $row_Recordset1['id']; ?>
<input name="id[]" type="hidden" value="<?php echo $row_Recordset1['id']; ?>" /></td>
<td><input name="name[]" type="text" value="<?php echo $row_Recordset1['name']; ?>"></td>
<td><input name="lastname[]" type="text" value="<?php echo $row_Recordset1['lastname']; ?>"></td>
<td><input name="email[]" type="text" value="<?php echo $row_Recordset1['email']; ?>"> </td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<p>
<input type="submit" name="submit" value="Submit" />
</p>
</form>
<p>
</p>
</body>
</html>

Used this command to change multiple entries in the database:
$sql = "UPDATE users SET name = ?, lastname = ?, email = ? WHERE id = '{$_SESSION['id']}'";

Related

i want to try fetch data on other page and than update but always show me an error

here is my index page.inserted all the data to the database and also show on the same page but the main problem is that on update.php page I can not retrieve the data
//that main problem is here and I can't be retrieved the data on this page and always sow that: Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\wamp\www\phonebook\update.php on line 12
index.php
<?php require_once('dbconnect.php'); ?>
<html>
<head>
<title> </title>
</head>
<body>
<h1> phone book </h1>
<form method="post">
<table>
<tr>
<td>fname </td><td> <input type="text" name="firstname" required /> </td>
</tr>
<tr>
<td>lname </td><td> <input type="text" name="lastname" required /> </td>
</tr>
<tr>
<td>mobile </td><td> <input type="text" name="mobile" required /> </td>
</tr>
</table>
<input type="submit" name="submit" value="submit" >
</form>
<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ show $$$$$$$$$$$$$$$$$$$$$$$$$$ -->
<br> data </br>
<table border="1">
<tr>
<th>id</th> <th>firstname</th> <th>lastname</th> <th>mobile</th><th>update</th><th>delete</th>
</tr>
<?php
$conn = mysqli_connect('localhost','root','','phonebook');
$show = mysqli_query($conn,"SELECT * FROM contacts");
while($row = mysqli_fetch_array($show))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['mobile']; ?></td>
<td>update</td>
<td><a href="delete.php?id=<?php echo $row['id']; ?>" onclick="return confirm('sure want to delete')" >delete</a></td>
</tr>
<?php } ?>
</table>
</body>
</html>
<?php
//require_once("function.php");
//$obj = new data();
if(isset($_POST{"submit"}))
{
//echo "<pre>";print_r($_POST);die;
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$mobile = $_POST['mobile'];
//$obj->insert($fname,$lname,$mobile);
$connect = mysqli_connect('localhost','root','','phonebook');
$insert = mysqli_query($connect,"insert into contacts(firstname,lastname,mobile) values('".$fname."','".$lname."','".$mobile."')");
if ($insert)
{ ?>
<script> alert('record inserted'); </script>
<?php
}
else
{ ?>
<script> alert('record not inserted'); </script>
<?php
}
header('Location:index.php');
}
?>
update.php
//check the code here
<?php require_once('dbconnect.php');
if(isset($_GET['id']) && is_numeric($_GET['id']) )
{
$id=$_GET['id'];
}
?>
<?php
$conn = mysqli_connect('localhost','root','','phonebook');
$result=mysqli_query($conn,"SELECT * FROM contacts WHERE id='$id'");
$fetch=mysql_fetch_array($result);
//$conn = mysqli_connect('localhost','root','','phonebook');
//$show = mysqli_query($conn,"SELECT * FROM contacts");
//while($row = mysqli_fetch_array($show))
?>
<html>
<head>
<title>update page</title>
</head>
<body>
<form method="post" name="update" action="update.php">
<table>
<tr>
<td>fname </td><td> <input type="text" name="firstname" value= "<?php echo $fetch['firstname']; ?>" required /> </td>
</tr>
<tr>
<td>lname </td><td> <input type="text" name="lastname" value="<?php echo $fetch['lastname']; ?>" required /> </td>
</tr>
<tr>
<td>mobile </td><td> <input type="text" name="mobile" value= "<?php echo $fetch['mobile']; ?>" required /> </td>
</tr>
</table>
<input type="submit" name="submit" value="submit" >
</form>
</body>
</html>
Switch to using mysqli_fetch_array() (note the i) instead of mysql_fetch_array
try this:
$conn = mysqli_connect('localhost','root','','phonebook');
$result=mysqli_query($conn,"SELECT * FROM contacts WHERE id='$id'");
$fetch=mysqli_fetch_array($result);
You must not use mysql_*, it's deprecated. Use PDO or MySQLi instead
You shouldn't mix mysql_* and mysqli_*
Just create ONE mysqli instance instead of creating it for every file you have.
Maximize the use of variables too. This way you only have to change something once.
Please sanitize/escape user input before passing it into your SQL query. Otherwise your application is vulnerable to SQL injection attacks.

Can't update/change data in MySQL from PHP

I was almost there, but the update is not functioning well especially on the bottom part.
<?php
require('dbconnect.php');//Connects to the database
session_start();
$user_check=$_SESSION['login_user'];
$ses_sql=mysqli_query($link,"SELECT username FROM members WHERE username='$user_check'");
$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$loggedin_session=$row['username'];
if(!isset($loggedin_session))
{
header("Location: login.php");
}//To ensure that you must be logged in to access this page
?>
<html>
<head>
<title>Healing Food Form</title>
<meta charset="iso-8859-1"> <!--charset specifies characters available-->
<meta name="author" content="Klarenz Kristoffer M. Qui;ntildeones">
<meta name="description" content="form to update healing food">
<meta name="keywords" content="healing food,form">
</head>
<body>
<?php
$id=$_GET['hf_id'];
$query = "SELECT * FROM healingfood WHERE hf_id='$id'";
if(!mysqli_query($link,$query))
{
die("Sorry. There's a problem with the query.");
}
//stores the result of the query
$result = mysqli_query($link,$query);
while($record = mysqli_fetch_assoc($result))
{
$hf_id=$record['hf_id'];
$hf_title=$record['hf_title'];
$a_id=$record['a_id'];
$hf_image=$record['hf_image'];
$hf_description=$record['hf_description'];
$hf_benefits=$record['hf_benefits'];
$hf_source=$record['hf_source'];
?>
<form action="updatehealingfood.php?hf_id=<?php echo $record['hf_id']; ?>" method="POST">
<table id="container" align="center">
<caption>Update healing food</caption>
<tr>
<td>Title:</td>
<td><input name="hf_title" type="text" value="<?php echo $hf_title; ?>"><br></td>
</tr>
<tr>
<td>Author ID:</td>
<td><input name="a_id" type="text" value="<?php echo $a_id; ?>"><br></td>
</tr>
<tr>
<td>Image URL:</td>
<td><input name="hf_image" type="url" value="<?php echo $hf_image; ?>"><br></td>
</tr>
<tr>
<td>Description:</td>
<td><textarea name ="hf_description" rows="18" cols="60"><?php echo $hf_description; ?></textarea><br></td>
</tr>
<tr>
<td>Benefits:</td>
<td><input name="hf_benefits" type="text" value="<?php echo $hf_benefits; ?>"><br></td>
</tr>
<tr>
<td>Source:</td>
<td><input name="hf_source" type="text" value="<?php echo $hf_source; ?>"><br></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="update" value="Update Healing Food"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
$id=$_GET['hf_id'];
if(isset($_POST['update']))
{
$hf_title=$_POST['hf_title'];
$a_id=$_POST['a_id'];
$hf_image=$_POST['hf_image'];
$hf_description=$_POST['hf_description'];
$hf_benefits=$_POST['hf_benefits'];
$hf_source=$_POST['hf_source'];
$query2="UPDATE healingfood SET hf_title='$hf_title', a_id='$a_id', hf_image='$hf_image', hf_description='$hf_description', hf_benefits='$hf_benefits', hf_source='$hf_source' WHERE hf_id='$id'";
$result2=mysql_query($query2) or die();
echo "Updated";
}
?>
When I was supposed to update the data, the data remains the same. No one changed. I don't get the $id=$_GET['hf_id']; .
What are my errors?
You are mixing mysqli_* and mysql_*.
At the first part you use mysqli_query(), later you use mysql_query() which has no connection to the database yet.
Stick to mysqli_*.
Change:
$result2=mysql_query($query2) or die();
to:
$result2=mysqli_query($link, $query2) or die( "MySQL error: " . mysqli_error($link) );

trouble in updating multiple rows in mysql db

can someone tell me were I wrote wrong ? this code shows data from database but when I press submit it just reload the page and none of those field's update in database ...
shall I change variables in update query to for example : $_POST['name']
<?php
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="db"; // Database name
$tbl_name="test"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="POST" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>mid</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
$id[]=$rows['id'];
?>
<tr>
<td align="center">
<input name="id[]" type="text" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>">
</td>
<td align="center">
<input name="midmark[]" type="text" id="midmark" value="<? echo $rows['midmark']; ?>">
</td>
</tr>
<?
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
if(isset($_POST['submit'])){
for($i=0;$i<$count;$i++){
$sql1=mysql_query("UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', midmark='$midmark[$i]' WHERE id='$id[$i]' ");
$result1=mysql_query($sql1);
}
}
if(isset($result1)){
header("location:multiple.php");
}
mysql_close();
?>
Try this, hope it'll help you.
if(isset($_POST['Submit']))
{
for($i=0;$i<$count;$i++)
{
$sql1=mysql_query("UPDATE `".$tbl_name."` SET name='".magic($_REQUEST['name'][$i])."', lastname='".magic($_REQUEST['lastname'][$i])."', midmark='".magic($_REQUEST['midmark'][$i])."' WHERE id='".magic($_REQUEST['id'][$i])."' ");
$result1=mysql_query($sql1);
}
}
function magic($value)
{
if( get_magic_quotes_gpc() )
$value = stripslashes( $value );
if( function_exists( "mysql_real_escape_string" ) )
$value = mysql_real_escape_string( $value );
else
$value = addslashes( $value );
return $value;
}
Try putting a '.' between the variables in your SQL string and the text and using single quotes - it may be trying to evaluate both parts of $name[$i]
, e.g.
'UPDATE '.$tbl_name.' SET name=\''.$name[$i].' ...etc
Also, always echo the SQL string before the query when testing to see what it will do
display and input using:-
<tr>
<td align="center">
<input name="data[<? echo $rows['id']; ?>][name]" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="data[<? echo $rows['id']; ?>][lastname]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>">
</td>
<td align="center">
<input name="data[<? echo $rows['id']; ?>][midmark]" type="text" id="midmark" value="<? echo $rows['midmark']; ?>">
</td>
</tr>
then process using:-
<?php
if(isset($_POST['submit']))
{
while(list($index,$record)=each($_POST['data']))
{
$sql=mysql_query("UPDATE $tbl_name SET name='".mysql_real_escape_string($record['name'])."', lastname='".mysql_real_escape_string($record['lastname'])."', midmark='".mysql_real_escape_string($record['nmidmarkame'])." WHERE id=".intval($index));
$result1=mysql_query($sql1);
}
}
?>
Your post variables are set wrong.
first of all your if statements, post['submit'] is lowercase, it needs to be the same as in the form:
isset($_POST['Submit'])
Then you need to read the rest of the post values and store them in variables or at least reference them properly:
$sql1=mysql_query("UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', midmark='$midmark[$i]' WHERE id='$id[$i]' ");
Should become:
$name = $_POST['name[$i]'];
$lastname = $_POST['lastname[$i]'];
$sql1=mysql_query("UPDATE $tbl_name SET name='$name', lastname='$lastname', ...

php error Undefined variable: result1 help!

I'm trying to troubleshoot this code and I'm getting this error and I do not know how to fix it: Undefined variable: result1 in plainview.php on line 44
here is the code:
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE depot = 'plainview'";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
//error reporting
error_reporting(E_ALL); ini_set('display_errors', '1');
//update
if(isset($_POST['Submit'])){
for($i=0;$i<$count;$i++){
$sql1 = "UPDATE $tbl_name SET
available='".mysql_real_escape_string($_POST['available'][$i])."',
rent='".mysql_real_escape_string($_POST['rent'][$i])."',
corp_ready='".mysql_real_escape_string($_POST['corp_ready'][$i])."',
down='".mysql_real_escape_string($_POST['down'][$i])."',
gfs='".mysql_real_escape_string($_POST['gfs'][$i])."',
dateTime = NOW()
WHERE id='".$id[$i]."'";
$result1 = mysql_query($sql1) or die(mysql_error());
}
}
//redirect
if($result1){
header("location: plainview.php");
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script language="JavaScript1.1" type="text/javascript">
<!--
function mm_jumpmenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<title>Untitled Document</title>
</head>
<body>
<div>
<p>Plainview, North East Region</p>
<p>Select a different region: <select onchange="mm_jumpmenu('parent',this,0)" name="lostlist">
<option value="" selected="selected">Choose Your Depot</option>
<option value="plainview.php">Plainview</option>
<option value="worcrester.php">Worcrester</option>
</select></p>
</div><Br />
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="700" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>ID</td>
<td align="center"><strong>Product Name</strong></td>
<td align="center"><strong>Available</strong></td>
<td align="center"><strong>Rent</strong></td>
<td align="center"><strong>Corp Ready</strong></td>
<td align="center"><strong>Down</strong></td>
<td align="center"><strong>GFS</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="left"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
<td align="left"><?php echo $rows['product']; ?></td>
<td align="center"><input name="available[]" type="text" id="available" value="<?php echo $rows['available']; ?>" size="5"></td>
<td align="center"><input name="rent[]" type="text" id="rent" value="<?php echo $rows['rent']; ?>" size="5"></td>
<td align="center"><input name="corp_ready[]" type="text" id="corp_ready" value="<?php echo $rows['corp_ready']; ?>" size="5"></td>
<td align="center"><input name="down[]" type="text" id="down" value="<?php echo $rows['down']; ?>" size="5" /></td>
<td align="center"><input name="gfs[]" type="text" id="gfs" value="<?php echo $rows['gfs']; ?>" size="5"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
</body>
</html>
Please help! I'm an amateur at PHP and any help would be appreciated....
$result1 is only getting set inside a for loop, inside an if statement. If the if fails, it's never defined, so the if($result1) gives that error. Set $result1 = false before your if statement. Better yet, move the if statement to surround the entire code block, including the database connection and disconnection stuff.
In line 44 $result is undefined, if
if ( isset( $_POST['Submit'] )) {
...
$result1 = mysql_query($sql1) or die(mysql_error());
}
deflects its block, since you didn't posted the request or $_POST['Submit'] isn't defined.
Preset $result1 with a default value of FALSE.
You only define $result1 if the script was invoked via a POST operation. As such,
if($result1){
header("location: plainview.php");
}
will issue that warning anytime you're NOT in a POST situation.
As well, on another note, you're closing the mysql connection BEFORE you fetch rows to generate your HTML. This will kill your page output, as the results have not been "fetched" yet at the time you close the connection.

how to get value from the database

i want to get value from database..for exmaple,in the name field, it show the name that stored in the database. i want to show the value in the respective field.but it cannot retrieve the value..plz guys..help me
<?php
session_start();
$username = $_SESSION["username"];
$department = $_SESSION["department"];
?>
<html>
<head>
<title>Change Password</title>
</head>
<form method="post" action="changepassprocess.php">
<?php
$db = mysql_connect('localhost','root')
or die ("unable to connect");
mysql_select_db('fyp',$db) or die ("able to select");
$sql_select = "SELECT * FROM access WHERE username ='".$username."' ";
?>
<font face= "arial" size="2" font color="black">
<center>
<h3 align=center> Change Password </h3>
<table width="500" height="100" border="0" cellspacing="0" cellpadding="2">
<tr>
<tr>
<td align="left">User ID</td>
<td>: <input name="username" type="text" id="username" value="<? {echo "$username"; } ?>" size="20" maxlength="10" readonly='username'></td>
</tr>
<tr>
<td align="left">Name </td>
<td>: <input name="name" type="text" id="name" value="<? {echo "$name"; } ?>" size="50" readonly="name"></td>
</tr>
<tr>
<td align="left">Department </td>
<td>: <?php echo $row['department']; ?> </td>
</tr>
<tr>
<td align="left">New Password </td>
<td>:<input name="newpassword" type="password" id="newpassword" size="20" ></td>
</tr>
</table><br>
<align = center><input type="submit" name="send" value="Change Password">
</form>
</body>
</html>
Well, you forgot to run your query to the database. The $sql_select variable holds the query text, but you need to pass it to the database and retrieve the answer from it. Read http://php.net/manual/en/function.mysql-query.php and examples there.
You are missing:
$result = mysql_query($sql_select);
$row = mysql_fetch_array($result);
These will execute the query you've prepared and get the results as an array $row.
You might want to see how get fetch a value from Mysql DB using php from:
W3school: Select Data From a Database Table.
<?php
session_start();
include("../connect.php");
$user=$_SESSION['user'];
if(empty($user))
{
header("location:index.php");
}
else{
$query_display="SELECT * FROM user_login WHERE user_id_no='$user_id_no'";
$result=mysqli_query($bd,$query_display);
while($arr=mysqli_fetch_array($result))
{
$first_name=$arr['first_name'];
$last_name=$arr['last_name'];
$address=$arr['address'];
}
echo $first_name;
echo $last_name;
echo $address;
}
?>
connect.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "";
$bd=mysqli_connect($mysql_hostname,$mysql_user,$mysql_password,$mysql_database);
?>

Categories