php mysql edit function error submit button show error - php

I have a bug in my system...when I clicked useraccounts to display the information of the users in the system it says: Notice: Undefined index: Username in C:\xampp\htdocs\GuidanceRecord\useraccounts.php on line 75
I know the problem is quite easy but I can't see what the problem is...
My useraccounts.php is:
<?php
$records = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('records', $records);
$sql = 'SELECT * FROM login';
$result = mysql_query($sql, $records);
echo "<table border='1' width='100%'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td width='20%'><img src='image/loginimage2.jpg'></img>";
echo "</td>";
echo $row['Username'];
echo "<td width='15%'><a href='#'>Guidance<br>Administrator</a>";
echo "</td>";
echo "<td>";
echo "<a href='edituser.php?no={$row['ID']}'><input type='button' name='edit' value='Edit' class='btn btn-success'></a>";
echo "</td>";
}
echo "<td>";
echo "</td>";
echo "</tr>";
echo "</table>";
?>
I also have this edituser page named edituser.php...
<?php
ob_start();
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>UCC Guidance Record System</title>
<link rel="stylesheet" type="text/css" media="all" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="all" href="css/bootstrap-responsive.min.css">
<link rel="stylesheet" type="text/css" media="all" href="css/global.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript"src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/textbox.js"></script>
</head>
<body>
<?php
$records = mysql_connect("localhost","root","");
mysql_select_db("records",$records);
if(!isset($_POST['savechanges']))
{
$sql = "SELECT * FROM login WHERE ID = $_GET[no]";
$result = mysql_query($sql);
$login = mysql_fetch_array($result);
}
?>
<div class="container">
<br>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li>View Records</li>
<li>Add Records</li>
<li class="active">User Accounts</li>
</ul>
<span class="span6">
</span>
<ul class="nav">
<li>Logout</li>
</ul>
</div>
</div>
</div>
<div class="row">
<span class="span12">
<img src="image/UCC Guidance Record System2.png" width="100%" height="210px"></img>
</span>
<span class="span2">
</span>
<span class="span8">
<br><br>
<table border="0" width="100%" height="100%">
<tr>
<td width="33%">
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
</td>
<td width="33%">
</td>
<td width="33%">
</td>
</tr>
<tr>
<td width="33%">
User Accounts
</td>
<td width="33%">
</td>
<td width="33%">
</td>
</tr>
<tr>
<td width="33%">
Username:
</td>
<td width="33%">
Password:
</td>
<td width="33%">
</td>
</tr>
<tr>
<td width="33%">
<input type="hidden" name="ID" value="<?php echo $login['ID']; ?>" />
<input type="text" name="Username" title="Username" style="color:#888;" value="<?php echo $login['Username']; ?>" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
</td>
<td width="33%">
<input type="Password" name="Password" title="Password" style="color:#888;" value="<?php echo $login['Password']; ?>" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
</td>
<td width="33%">
</td>
</tr>
<tr>
<td width="33%">
</td>
<td width="33%">
</td>
<td width="33%">
<input type="submit" name="savechanges" class="btn btn-primary" value="Save Changes">
</form>
</td>
</tr>
</table>
</span>
</div>
<div class="container">
<ul class="pager container-fluid">
<li class="pull-left">Previous</li>
<li class="pull-right">Next</li>
</ul>
</div>
</div>
<center><small class="muted">UCC Guidance Record System<br>
Developed by Christian Baltazar and Jocella Barruga.<br>
Copyright 2014.</small></center>
<?php
if(isset($_POST['savechanges']))
{
$id = $_POST['ID'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$update = "UPDATE students ".
"SET Username = '$Username' ".
", Password = '$Password' ".
"WHERE ID = $id" ;
mysql_query($update) or die(mysql_error());
echo "User has been modified!";
header("Location: http://localhost/GuidanceRecord/Useraccounts.php");
exit() ;
}
?>
</body>
</html>
I also have a database named "records" a table named "login" and columns named "ID", "Username", and "Password"...
I'm a newbie in php...hope you understand...
Thanks in advance for the answer... :))

Try this
$row = mysql_fetch_array($result,MYSQL_ASSOC)
instead of
$row = mysql_fetch_array($result)
and also mysql is deprecated and very vulnerable to sql injection use PDO or Mysqli instead.

Are you sure your column name in database is called 'Username'? It might be 'username', as you know PHP is character sensitive.
Try running print_r to see what are you getting from database:
echo '<pre>'; print_r($row); echo '</pre>';

At the point where you output the id in the ancor link try to replce the 'ID' with 0 it specifies the columns number you wanna display out.

Related

How do I echo more than one product dynamically on the same invoice page

I am trying to echo more than one item on an invoice for the same customer. I am able to echo them from the database, but instead of each item being echoed on the same invoice (on different rows), it echoes the full invoice 2 times (or more depending on how many items are on the invoice) with each item on each invoice. Below is my code (I have not yet cleaned the code up. I am leaving that step once the code works).
<?php include "database_connection.php" ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>DPB quote</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="css/bootstrap.min.css"><!--erase this link once the app is completed-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel='stylesheet' type='text/css' href='css/style2.css' />
<link rel='stylesheet' type='text/css' href='css/print.css' media="print" />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/example.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"><!--search pagination and delete reference link-->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script><!--search pagination and delete reference link-->
</head>
<body>
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order
WHERE order_id = :order_id
LIMIT 1
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<script>
$(document).ready(function(){
$('#order_no').val("<?php echo $row["order_no"]; ?>");
$('#order_date').val("<?php echo $row["order_date"]; ?>");
$('#order_receiver_name').val("<?php echo $row["order_receiver_name"]; ?>");
$('#address_line_1').val("<?php echo $row["address_line_1"]; ?>");
$('#address_line_2').val("<?php echo $row["address_line_2"]; ?>");
$('#city').val("<?php echo $row["city"]; ?>");
$('#state').val("<?php echo $row["state"]; ?>");
$('#zip_code').val("<?php echo $row["zip_code"]; ?>");
$('#phone_number').val("<?php echo $row["phone_number"]; ?>");
$('#email').val("<?php echo $row["email"]; ?>");
$('#notes').val("<?php echo $row["notes"]; ?>");
});
</script>
<form method="post" id="invoice_form">
<div class="container">
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order_item
WHERE order_id = :order_id
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$item_result = $statement->fetchAll();
$m = 0;
foreach($item_result as $sub_row)
{
$m = $m + 1;
?>
<!--QUOTATION APP 2 STARTS HERE-->
<div id="page-wrap">
<textarea id="header">Quotation</textarea>
<div id="identity">
<textarea id="address">Discount Plastic Bags
7750
Suite
Irving
Phone: </textarea>
<div id="logo">
<div id="logohelp">
(max width: 540px, max height: 300px)
</div>
<img id="image" src="images/dpblogo3.png" alt="logo" />
</div>
</div>
<div style="clear:both"></div>
<div id="customer">
<!--<form id="quote_date" class="" action="index.php" method="post">-->
<tr>
<td><textarea placeholder="Enter Customer Information" id="address" name="company_info"></textarea></td>
</tr>
<table id="meta">
<tr>
<td class="meta-head">Invoice #</td>
<td><textarea>000123</textarea></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td><textarea placeholder="enter quotation date" name="quote_date"></textarea></td>
</tr>
<tr>
<td class="meta-head">Amount Due</td>
<td><textarea placeholder="enter amount due" name="amount_due"></textarea></td>
</tr>
</table>
</div>
<table id="items">
<tr>
<th>SKU</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit Cost</th>
<th>Price</th>
</tr>
<tr class="item-row">
<!--<td><span id="sr_no"><?php //echo $m; ?></span></td>-->
<td><input type="text" name="sku[]" id="sku<?php echo $m; ?>" class="item-name" value="<?php echo $sub_row["sku"]; ?>" /></td>
<td><input type="text" name="item_name[]" id="item_name<?php echo $m; ?>" class="description" value="<?php echo $sub_row["item_name"]; ?>" /></td>
<td><input type="text" name="order_item_quantity[]" id="order_item_quantity<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="qty" value = "<?php echo $sub_row["order_item_quantity"]; ?>" /></td>
<td><input type="text" name="order_item_price[]" id="order_item_price<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="cost" value="<?php echo $sub_row["order_item_price"]; ?>" /></td>
<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount<?php echo $m; ?>" data-srno="<?php echo $m; ?>" readonly class="price" value="<?php echo $sub_row["order_item_final_amount"]; ?>" /></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Subtotal</td>
<td class="total-value"><textarea id="subtotal" name="subtotal"></textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Total</td>
<td class="total-value"><textarea name="total" id="total"></textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line">Amount Paid</td>
<td class="total-value"><textarea id="paid">$0.00</textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line balance">Balance Due</td>
<td class="total-value balance"><textarea name="balance_due" class="due"> </textarea></td>
</tr>
</table>
<div id="terms">
<h5>Notes</h5>
<textarea name="notes" placeholder="enter quotation notes" rows="12" style="font-size: 15pt"></textarea>
</div>
</div>
</form>
</body>
</html>
<?php
}
}
?>
I would do something like this. This is not tested and just an example of how I do it. There are a few other ways but this works best for me
// other needed code above
$results = sqlsrv_query($link, $query);
//query returns one value for these
echo "<table>";
echo "<tr> ";
echo "<td>".$name."</td>";
echo "<td>".$store."</td>";
echo "</tr>";
//start your multiple items row
while($row=sqlsrv_fetch_array($results))
{
$items = $row['items'];
echo "<tr> ";
echo "<td>".$items."</td> ";
echo "</tr>";
}
echo "<tr> ";
echo "<td>".$cost."</td>";
echo "<td>".$other."</td>";
echo "</tr>";
echo "</table> ";
//other code for the rest of the page below
Result would be:
Bob Bob's Store
ITEM
ITEM
ITEM
$50.00 other

downloading Mp3 file form mysql DB and Increasing number of downloads per click

I want to desing an e-music php web base application and i want to achive the forllowing:
1. on cliking on the download button the file should be downloaded
2. The number of downloads of that file should be incremented by 1
The following code show list of music i.e new releases and top downloads
<?php
$hostname_conn = "localhost";
$database_conn = "e-music";
$username_conn = "root";
$password_conn = "";
$conn = mysqli_connect($hostname_conn, $username_conn, $password_conn, $database_conn) or trigger_error(mysqli_error());
$sql="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by upload_date Desc limit 0,3";
$Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error());
$sql1="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by downloads Desc limit 0,3";
$Result1= mysqli_query($conn,$sql1) or die('Cannot Retrive Record' . mysqli_error());
?>
<table align="center" class="table table-striped table-hover ">
<thead>
<tr>
<th colspan="3" align="center"> <h3>New Releases </h3></th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($Result)) { ?>
<tr>
<td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" >
</div>
<label> Artist: <?php echo $row['artist_name'] ?></label> <br/>
<label> Title: <?php echo $row['m_title'] ?></label> <br/>
<label>Category: Wakoin <?php echo $row['cat_name'] ?></label>
</td>
<td>
<a class="btn btn-xs btn-primary" href="download.php?did=<?php echo $row['mid'];?>"> Downloader</a>
</td>
<td class="col-md-2">
Format:<?php echo $row['m_format']; ?>
</td>
<td class="col-md-2">
File Size: <?php echo round($row['size']/1048576,2); ?> MB
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<table align="center" class="table table-striped table-hover">
<thead>
<tr>
<th colspan="3" align="center"> <h3>Top Downloads </h3></th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($Result1)) { ?>
<tr>
<td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" >
</div>
<label> Artist: <?php echo $row['artist_name'] ?></label> <br/>
<label> Title: <?php echo $row['m_title'] ?></label> <br/>
<label>Category: Wakoin <?php echo $row['cat_name'] ?></label>
</td>
<td class="col-md-2">
<a class="btn btn-xs btn-primary" href="download.php?did=<?php echo $row['mid'];?>"> Downloader</a>
</td>
<td class="col-md-2">
Format: <?php echo $row['m_format']; ?>
</td>
<td>
File Size :<?php echo round($row['size']/1048576,2); ?> MB
</td>
</tr>
<?php
}
?>
</tbody>
</table>
The code i tried for the downloads on cliking the "downloader" Button which redirects to download.php file is below:
$hostname_conn = "localhost";
$database_conn = "e-music";
$username_conn = "root";
$password_conn = "";
$conn = mysqli_connect($hostname_conn, $username_conn, $password_conn, $database_conn) or trigger_error(mysqli_error());
$did=$_GET['did'];
$sql="SELECT target from music where mid='$did'";
$Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error());
$row = mysqli_fetch_assoc($Result);
// the target filed contains the directory and file name of the file to be downloaded e.g uploads/Akon_Sorry Blame.mp3
echo "<a href=". $row['target'] ." > download</a>";
$sql1="update music set download=download+1 where mid='$did";
$Result= mysqli_query($conn,$sql1) or die('Cannot Increment number of downloads' . mysqli_error());
After research on my project i am able to solve my problem using ajax. Here is the code i used to achieve my objectives
//index page
<!DOCTYPE html>
<html>
<head>
<title>E-music</title>
<link href="includes/Style.css" rel="stylesheet" type="text/css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script src="jQuery/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript"></script>
<script src="bootstrap-3.3.7-dist/js/site.js" type="text/javascript"></script>
<?php
require_once("includes/connection.php");
$sql="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by upload_date Desc limit 0,3";
$Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error());
$sql1="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by downloads Desc limit 0,3";
$Result1= mysqli_query($conn,$sql1) or die('Cannot Retrive Record' . mysqli_error());
?>
<div id="nav">
Search For Music Audio
<p>Wakokin Hausa Na Gargajiya
</p>
</div>
<div id="section">
<table align="center" class="table table-striped table-hover ">
<thead>
<tr>
<th colspan="3" align="center"> <h3>New Releases </h3></th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($Result)) { ?>
<tr>
<td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" >
</div>
<label> Artist: <?php echo $row['artist_name'] ?></label> <br/>
<label> Title: <?php echo $row['m_title'] ?></label> <br/>
<label>Category: Wakoin <?php echo $row['cat_name'] ?></label>
</td>
<td>
<a href="<?php echo $row['target'] ?>" d="<?php echo $row['mid'] ?>" class="dload btn btn-xs btn-primary" download>Download</a>
</td>
<td class="col-md-2">
Format:<?php echo $row['m_format']; ?> <br>
Total Download: <?php echo $row['downloads']; ?>
</td>
<td class="col-md-2">
File Size: <?php echo round($row['size']/1048576,2); ?> MB
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<table align="center" class="table table-striped table-hover">
<thead>
<tr>
<th colspan="3" align="center"> <h3>Top Downloads </h3></th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($Result1)) { ?>
<tr>
<td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" >
</div>
<label> Artist: <?php echo $row['artist_name'] ?></label> <br/>
<label> Title: <?php echo $row['m_title'] ?></label> <br/>
<label>Category: Wakoin <?php echo $row['cat_name'] ?></label>
</td>
<td class="col-md-2">
<a href="<?php echo $row['target'] ?>" d="<?php echo $row['mid'] ?>" class="dload btn btn-xs btn-primary" download>Download</a>
</td>
<td class="col-md-2">
Format: <?php echo $row['m_format']; ?>
Total Download: <?php echo $row['downloads']; ?>
</td>
<td>
File Size :<?php echo round($row['size']/1048576,2); ?> MB
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
//Site.js an ajax file to handle download incrementation
$(function() {
$(".dload").click(function(){
var id = $(this).attr("d");
$.ajax({
type: "POST",
url: "count.php",
data: {id:id},
success: function(info)
{
},
error: function(){
}
});
});
});
//conut.php to handle the databae update
<?php
require_once("includes/connection.php");
$id = $_POST["id"];
$Result= mysqli_query($conn,"SELECT downloads as total FROM music WHERE mid='$id'");
$Res = mysqli_fetch_assoc($Result);
$re = $Res['total'] + 1;
$updateCount = mysqli_query($conn, "UPDATE music SET downloads= '$re' WHERE mid=$id ");
?>

Show only relevant search results

I have created a page for search, and I'm having some problems.
The data is displayed on the page but I also use some fields on the form for a specific field, so when I enter the data in those fields and hit search, it shows the search field on the top of the display page with the rest of the data, but I want only the data which belongs to my search.
CODE:
<?php
include('connect.php');
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include('include/head.php')?>
</head>
<body>
<div id="header-wrapper">
<div id="header">
<div id="menu">
<ul>
<?php include('include/menu.php') ?>
Logout
</ul>
</div>
</div>
</div>
<div id="logo">
<?php include('include/logo.php'); ?>
</div>
<div id="wrapper">
<div id="page">
<div id="page-bgtop">
<div id="content">
<div class="post">
<div class="entry-image">
<?php
$q=mysql_query("SELECT count( php ) AS ph, count( dotnet ) AS dot, count( design ) AS des FROM candidate");
while($row=mysql_fetch_array($q))
{
?>
<form name="" method="post">
<table border="1" cellpadding="10" cellspacing="1" width="280" height="200">
<th colspan="5" bgcolor="orange" >Total Number of Resume by skills</th>
<tr>
<th><B>PHP</B></th>
<th><B>DOTNET</B></th>
<th><B>DESIGN</B></th>
</tr>
<td><?php echo "$row[ph]"; ?></td>
<td><?php echo "$row[dot]"; ?></td>
<td><?php echo "$row[des]"; ?></td>
</table>
</form>
<?php
}
?>
</div>
<h2 class="title">Welcome to Resume </h2>
<div class="entry">
<p>
<form name="search" method="post" action="searchview.php">
<table>
<tr>
Id: <input type="text" name="id" /></br></br>
Name:<input type="text" name="name" /><br/></br>
Expected Salary:<input type="text" name="es" /><br/></br>
Skill Rate: <input type="text" name="sr" /><br/> </br>
Salary:<input type="text" name="cs" /></br></br>
<input type="submit" name="submit" value="seach" /><input type="reset" name="reset" value="reset" />
</tr>
</table>
</form>
</p>
</div>
</div>
<div class="post" >
<?php
$query=mysql_query("select * from candidate");
while($row=mysql_fetch_array($query))
{
$sno=$row['id'];
$image=$row['image'];
$name=$row['fname'];
$es=$row['es'];
$sr=$row['sr'];
$cs=$row['cs'];
?>
<form name="view" method="post" action="searchview.php" >
<table border="1" cellpadding="30" class="centered" width="20" >
<tr>
<th width="150">S.NO</th>
<th width="150">IMAGE</th>
<th width="150">NAME</th>
<th width="150">EXPECTED SALARY</th>
<th width="150">SKILL RATE</th>
<th width="150">SALARY</th>
<th width="150">ACTION</th>
</tr>
<td><?php echo "$row[id]"; ?></td>
<td><div class="rightdiv1a"><img src="<?php echo 'img/'.$row['image']; ?>" style="height:120px; width:145px; "></div></td>
<td><?php echo "$row[fname]"; ?></td>
<td><?php echo "$row[es]"; ?></td>
<td><?php echo "$row[sr]"; ?></td>
<td><?php echo "$row[cs]"; ?></td>
<td><img alt='view' title='view' src='images/view.png' width='15px' height='15px' hspace='20' /></td>
<td><img alt='Edit' title='Edit' src='images/edit.png' width='15px' height='15px' hspace='20' /></td>
<td><a onclick="return confirm('Would you like to delete?');" href="delete.php?id=<?php echo "$row[id]"; ?>"><img alt='delete' title='delete' src='images/delete.png' width='15px' height='15px' hspace='20' /></a></td>
</table>
</form>
<?php
}?>
</div>
</div>
</div>
</div>
</div>
<div id="footer-bgcontent">
<div id="footer">
<?php// include('include/footer.php');?>
</div>
</div>
</body>
</html>
<?php// } ?>
This code displays the data now but I want to filter the data and only show the results which belongs to my search, and have the rest disappear.
Here are some screenshots of my form:
pls help,
thanks in advance..
If I understand the question correctly, you want to display the search results, but no longer show the search form. If this is the case, then move your second "post" div to the top and wrap it in an if:
if (!empty($_POST)) {
// Process POST results here:
...
die(); // end processing so the form doesn't display again
}

How to display BLOB Images from database in a while loop

I've been working on these codes for 2 hours now and i can't seem to make it appear. It has the right ID, but the picture doesnt show. i have no idea why.
anyway, here are my codes.
this is for showing the pic along with other stuff.
<div align="left">
<center><img src="img/compressportbanner.jpg" height="180"></center>
<table border="0" cellpadding="2px" width="600px">
<?php
$result=mysql_query("select * from inventory WHERE prod_brand = 'Compressport' AND prod_category='compression' ");
while($row=mysql_fetch_array($result)){
?>
<tr>
<td>
<?php
echo '<'.'img src="image.php?prod_id='.$row['prod_id'].'" alt="'.$row['prod_name'].'" width="250">';
?>
</td>
<td> <b><?php echo $row['prod_name']?></b><br />
<?php echo $row['prod_category']?>
<!--<?php echo $row['prod_desc']?>-->
<br>
Price:<big style="color:green">
₱ <?php echo $row['prod_price']?></big><br /><br />
<input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['prod_id']?>)" />
</td>
</tr>
<tr><td colspan="2"><hr size="1" /></td>
<?php } ?>
</table>
</div>
and here is the image.php
<?php
$prodID=($_GET['prod_id']);
$sql = "SELECT * FROM `inventory` where `prod_id` = ".$prodID;
$qry = mysql_query($sql);
$result=mysql_fetch_array($qry);
echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['prod_pic'] ).'"/>'
?>
How do i make it appear, im new to php and im just starting to understand it.
Here's what I did with your codes, i added this line of code.
<?php echo '<img src="data:image/jpeg;base64,'.base64_encode($row['prod_pic']).'" width="250">';?>
Here are the full codes.
<div align="left">
<center><img src="img/compressportbanner.jpg" height="180"></center>
<table border="0" cellpadding="2px" width="600px">
<?php
$result=mysql_query("select * from inventory WHERE prod_brand = 'Compressport' AND prod_category='compression' ");
while($row=mysql_fetch_array($result)){
?>
<tr>
<td>
<?php
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['prod_pic']).'" width="250">';
?>
</td>
<td> <b><?php echo $row['prod_name']?></b><br />
<?php echo $row['prod_category']?>
<!--<?php echo $row['prod_desc']?>-->
<br>
Price:<big style="color:green">
₱ <?php echo $row['prod_price']?></big><br /><br />
<input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['prod_id']?>)" />
</td>
</tr>
<tr><td colspan="2"><hr size="1" /></td>
<?php } ?>
</table>
</div>

hide jQuery table row

I've got a search done with jQuery..
<script type="text/javascript" src="ajax.js"></script>
<div style="width:400px; margin:auto;">
<form action="clientes.php" method="post">
<legend>Procurar cliente</legend>
<input type="text" id="nome" name="nome" value="<?php echo $nome; ?>" style="width: 280px; height: 23px;" /><input type="button" name="btnPesquisar" value="Pesquisar" onclick="getDados();"/></form>
</div>
<div id="resultado"></div>
and getDados returns the results from another page, which is:
<?php
header('Content-Type: text/html; charset=utf-8');
include "conexao.php";
if ($_GET['nome']) {
$nome = $_GET['nome'];
$result = mysql_query("SELECT * FROM cliente WHERE nome LIKE '%".$nome."%' OR cpf LIKE '%".$nome."%' ORDER BY nome ASC") or die('Invalid query: ' . mysql_error());
$num_rows = mysql_num_rows($result);
}
if ($num_rows != 0) {
?>
<head><script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"> </script></head>
<script type="text/javascript">
$(document).ready(function() {
$('.hideme td').hide();
});
</script>
<table border=4 width="800px" align="center">
<tr><th>Cliente</th> <th>CPF</th> <th>Telefone</th> <th> Aniversário </th><th> Endereço </th></tr>
<?php
$i = "1";
while ($row = mysql_fetch_assoc($result)) {
?>
<TR>
<td width="220px" align="center"> <?php echo $row['nome']; ?> </td>
<td width="80px" align="center"> <?php echo $row['cpf']; ?> </td>
<td width="120px" align="center"><?php echo $row['telefone'] ?> </td>
<td width="120px" align="center"><?php echo $row['dataNascimento']; ?></a></td>
<td width="270px" align="center"><?php echo $row['endereco']; ?></td>
</TR>
<tr class="hideme"><td><form id="nomepost<?php echo $i; ?>" action="agrupaclienteteste.php" method="post">
<input type="hidden" name="nome" value="<?php echo $row['nome']; ?>"></form></td</tr>
<?php
$i++;
}
}
else{
if ($nome) { echo "Não há dados cadastrados em nosso sistema."; }
}
?>
Now.. the thing is, if I run the page of the results by itself.. lets say
result.php?nome=I
it hides the tr class=hideme...
if I access the search page and search for nome = I, it shows the results but it doesn't hide the tr class=hideme ...
Can anyone help me?
Why don't just use style="display:none;" as attribute value, since you are trying to hide onload itself

Categories