I'm trying to create an Edit option in the table showing the database on my website.
The problem is even when I click Save, the database is not updated.
There are no errors showing.
There's an EditComplaint.php, which fetches data from DB and shows it in input boxes so it can be edited and Ecomp.php, which is called on clicking Save.
<?php
$id = $_GET['id'];
$db_host = 'localhost'; // Server Name
$db_user = 'Username'; // Username
$db_pass = 'Username'; // Password
$db_name = 'Database'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = "SELECT `id`, `ref_no`, `type`, `comp_name`, `comp_no`, `station`, `pertains`, `user_remarks`, `to_whom`, `concern`, `brief_fct`, `sec_remarks`, `depart`, `cisf_remarks`, `generalcomment`, `status` FROM `Complaintstable` WHERE `Complaintstable`.`id` = '$id'";
$query = mysqli_query($conn, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Titillium+Web|Roboto+Condensed:400,300|Pathway+Gothic+One|ABeeZee:400,400italic" rel="stylesheet" type="text/css">
<link href="master-stylesheet.css" rel="stylesheet">
<link href="custom-stylesheet.css" rel="stylesheet">
<link href="complaintstable.css" rel="stylesheet">
<link href="dmrc-favicon.png" rel="shortcut icon" type="image/x-icon">
<title>DMRC/Login</title>
</head>
<body>
<form action="Ecomp.php" id="form1" method="post" name="form1">
<!-- header section -->
<div class="header">
<div class="header-inner">
<div class="header-top">
<div class="welcome-guest">
<span class="align-right float-right" id="lblusername" style="color:Black;">Guest</span><em><span class="welcome-cont float-right fontfamily_2" id="lblwelcome" style="padding-left:5px;padding-right:5px;color:black;">Welcome</span></em>
</div>
<div class="header-top-links">
<ul>
<li>
Home
</li>
</ul>
</div>
</div>
<div class="header-bottom">
</div>
</div>
</div>
<div class="container clearfix">
<br><br>
<table class="data-table">
<thead>
<tr>
<th>ID</th>
<th>Referral/No.</th>
<th>Type</th>
<th>Complainant Name</th>
<th>Station</th>
<th>Pertains To</th>
<th>User Remarks</th>
<th>To Whom</th>
<th>Concern</th>
<th>Brief Fact</th>
<th>Security Comments</th>
<th>Deptt</th>
<th>CISF Comments</th>
<th>General Comment</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
while($row = $query->fetch_assoc())
{
$id = $row['id'];
$ref_no = $row['ref_no'];
$type = $row['type'];
$comp_name = $row['comp_name'];
$station = $row['station'];
$pertains = $row['pertains'];
$user_remarks = $row['user_remarks'];
$to_whom = $row['to_whom'];
$concern = $row['concern'];
$brief_fct = $row['brief_fct'];
$sec_remarks = $row['sec_remarks'];
$depart = $row['depart'];
$cisf_remarks = $row['cisf_remarks'];
$generalcomment = $row['generalcomment'];
$status = $row['status'];
if ($i == 0)
{
$i++;
echo "<tr>";
echo "<td><input type='text' name='id' value='$id'/></td>";
echo "<td><input type='text' name='ref_no' value='$ref_no'/></td>";
echo "<td><input type='text' name='type' value='$type'/></td>";
echo "<td><input type='text' name='comp_name' value='$comp_name'/></td>";
echo "<td><input type='text' name='station' value='$station'/></td>";
echo "<td><input type='text' name='pertains' value='$pertains'/></td>";
echo "<td><input type='text' name='user_remarks' value='$user_remarks'/></td>";
echo "<td><input type='text' name='to_whom' value='$to_whom'/></td>";
echo "<td><input type='text' name='concern' value='$concern'/></td>";
echo "<td><input type='text' name='brief_fct' value='$brief_fct'/></td>";
echo "<td><input type='text' name='sec_remarks' value='$sec_remarks'/></td>";
echo "<td><input type='text' name='depart' value='$depart'/></td>";
echo "<td><input type='text' name='cisf_remarks' value='$cisf_remarks'/></td>";
echo "<td><input type='text' name='generalcomment' value='$generalcomment'/></td>";
echo "<td><input type='text' name='status' value='$status'/></td>";
echo "<td><a href='delete.php?id=$id' class='button-new'>Delete</a></td>";
echo "</tr>";
}
echo '<br><br>';
}
?>
</tbody>
</table>
<br><br>
<input type="submit" class="button-new" value="Save"/>
</div>
<div class="footer">
<div class="footer-top">
<div class="footer-top-inner">
<ul>
<li>
FAQs
</li>
<li>
Contact Us
</li>
<li>
Disclaimer
</li>
<li>
Terms & Conditions
</li>
</ul>
</div>
</div>
<div class="footer-bottom fontfamily_2">
<div class="footer-bottom-inner">
<div class="float-left footer-text">
</div>
</div>
</div>
</div>
</form>
</body>
</html>
And Here's the Ecomp.php that Save calls
<?php
$db_host = 'localhost'; // Server Name
$db_user = 'Username'; // Username
$db_pass = 'Username'; // Password
$db_name = 'Database'; // Database Name
// Create connection
$con = mysqli_connect($servername, $username, $password) or die("Unable to Connect to '$dname'");
// Check connection
if (!$con)
{
echo "Please try later.";
}
else
{
mysqli_select_db($con, $dname);
}
$id = $_POST['id'];
$ref_no = $_POST['ref_no'];
$type = $_POST['type'];
$comp_name = $_POST['comp_name'];
$station = $_POST['station'];
$pertains = $_POST['pertains'];
$user_remarks = $_POST['user_remarks'];
$to_whom = $_POST['to_whom'];
$concern = $_POST['concern'];
$brief_fct = $_POST['brief_fct'];
$sec_remarks = $_POST['sec_remarks'];
$depart = $_POST['depart'];
$cisf_remarks = $_POST['cisf_remarks'];
$generalcomment = $_POST['generalcomment'];
$status = $_POST['status'];
mysqli_query($con," UPDATE `Complaintstable` SET `ref_no`= '$ref_no',`type`='$type',`comp_name`=`$comp_name`,`station`='$station',`pertains`='$pertains',`user_remarks`='$user_remarks',`to_whom`='$to_whom',`concern`='$concern',`brief_fct`='$brief_fct',`sec_remarks`='$sec_remarks',`depart`='$depart',`cisf_remarks`='$cisf_remarks',`generalcomment`='$generalcomment',`status`='$status' WHERE `Complaintstable`.`id` = '$id'");
header("Location: complaintstable.php");
?>
Kindly guide me please.
Its my first time here.
Thanks in Advance.
Edit: The Update SQL query works when ran in phpmyadmin console.
What i can see is that you are wrapping one of your db values $comp_name in backticks ` but it is probably a string..
In this line look at the $comp_name:
mysqli_query($con," UPDATE `Complaintstable` SET `ref_no`= '$ref_no',`type`='$type',`comp_name`='$comp_name',`station`='$station',`pertains`='$pertains',`user_remarks`='$user_remarks',`to_whom`='$to_whom',`concern`='$concern',`brief_fct`='$brief_fct',`sec_remarks`='$sec_remarks',`depart`='$depart',`cisf_remarks`='$cisf_remarks',`generalcomment`='$generalcomment',`status`='$status' WHERE `Complaintstable`.`id` = '$id'");
I agree with Magnus. Here is how you could do the same with PDO. Although prepared statements are possible in mysql too, i would always go for PDO. See this reference if you want to spend time with it.
$db = new PDO('mysql:host=localhost;dbname=someDatabase', 'someUser', 'somePass');
$stmt = $db->prepare("UPDATE `Complaintstable` SET `ref_no`= ?,`type`= ?,`comp_name`=?,`station`= ?,`pertains`= ?,`user_remarks`=?,`to_whom`= ?,`concern`= ?,`brief_fct`= ?,`sec_remarks`= ?,`depart`= ?,`cisf_remarks`= ?,`generalcomment`= ?,`status`= ? WHERE `Complaintstable`.`id` = ?");
$stmt->execute(array($ref_no,$type,$comp_name,$station,$pertains,$user_remarks,$to_whom,$concern,$brief_fct,$sec_remarks,$depart,$cisf_remarks,$generalcomment,$status,$id));
Related
I'm trying to make an OPAC website. Everything works fine since it's mostly just selecting from the database and displaying it. I noticed that when the book title i'm trying to search has an apostrophe, it displays nothing. If the book title doesn't contain any apostrophe it all works. I'm using mysql for my database.
<!-- {this is how i connect my datatbase} -->
<?php
include 'includes/dbh.inc.php';
?>
<!DOCTYPE <!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div id= "wrapper">
<img class="cpclogo" src="cpc.png">
<header>
<h1 class="CPC"> Colegio de la Purisima Concepcion </h1>
<h3 class="Saying"> The School of the Archdiocese of Capiz </h3>
</header>
</div>
header.php file
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "library";
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
?>
search.php file
<?php
include 'header.php'
?>
<h1 class="searchresults">Search Results:</h1>
<div class="search-container">
<?php
if (isset($_POST['submit']))
{
$search = mysqli_real_escape_string($conn, $_POST['search']);
$sql = "SELECT * FROM book WHERE Book_Title LIKE '%$search%' OR Author LIKE '%$search%' OR Call_Number LIKE '%$search%' OR Book_ID LIKE '%$search%'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
$search = mysqli_real_escape_string($conn, $_POST['search']);
echo "<h3 class='resultcount'>There are ".$queryResult." results!</h3>";
if ($queryResult > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
echo "<a href='article.php?Book_Title=".$row['Book_Title']."&id=".$row['Book_ID']."&call=".$row['Call_Number']."' class= 'search-ref'><div class=search-box>
<tr><td>".$row['Book_Title']." </td>
<td>/ ".$row['Author']."</td>
<p>".$row['Call_Number']."</p>
</div></tr><br>";
}
}
}
?>
<input class="backbtn" type="button" value="Back" onclick="history.back(-1)" />
</div>
article.php file
<?php
include 'header.php';
?>
<div class="article-container">
<?php
//Declairing Variables
$Author = "Authors: ";
$Edition = "Edition: ";
$Subject ="Subject: ";
$Summary = "Summary: ";
$Notes = "Notes: ";
$Publisher ="Publisher: ";
$Phys_Desc ="Physical Description: ";
$Call_Number ="Call Number: ";
$Book_ID = "Book ID: ";
$Title= mysqli_real_escape_string($conn, $_GET['Book_Title']);
$sql ="SELECT * FROM book WHERE Book_Title='$Title'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
if ($queryResult > 0)
while ($row = mysqli_fetch_assoc($result))
{
echo "<div class= 'article-box'>
<h3 class='booktitle'><b>".$row['Book_Title']."</h3></b>
<p><b>$Author</b>".$row['Author']."</p>
<p><b>$Edition</b>".$row['Edition']."</p>
<p><b>$Subject</b>".$row['Subject']."</p>
<p><b>$Summary</b>".$row['Summary']."</p>
<p><b>$Notes</b>".$row['Notes']."</p>
<p><b>$Publisher</b>".$row['Publisher']."</p>
<p><b>$Phys_Desc</b>".$row['Phys_Desc']."</p>
<p><b>$Call_Number</b>".$row['Call_Number']."</p>
</div>";
}
?>
<div class="btns">
<input class="backbtn" type="button" value="Back" onclick="history.back(-1)" />
<button type="submit" id="copybtn" class= "copybtn">Copies</button>
</div>
<!-- POP-UP WINDOW -->
<div class="bg-modal">
<div class="modal-content">
<div class="close"></div>
<table class = "table">
<tr>
<th>Copy</th>
<th>Status</th>
<th>Accession Number</th>
<th>Call Number</th>
<th>Location</th>
<th>Format</th>
<th>Cost</th>
<th>Vendor</th>
<th>Fund</th>
<th>Date Acquired</th>
</tr>
<?php
$id = mysqli_real_escape_string($conn, $_GET['id']);
$call = mysqli_real_escape_string($conn, $_GET['call']);
$sql = "SELECT Copy, Status, Accession_Number, l.Location, f.Format, Cost, Vendor, u.Fund, Date_Acq
FROM copy c
INNER JOIN location l ON l.Location_Acronym = c.Location
INNER JOIN format f ON f.Format_ID = c.Format
INNER JOIN fund u ON u.Fund_ID = c.Fund
WHERE Book_ID='$id'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
if ($queryResult > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
echo "
<tr><td>".$row['Copy']."</td>
<td>".$row['Status']."</td>
<td>".$row['Accession_Number']."</td>
<td>".$call."</td>
<td>".$row['Location']."</td>
<td>".$row['Format']."</td>
<td>₱".$row['Cost']."</td>
<td>".$row['Vendor']."</td>
<td>".$row['Fund']."</td>
<td>".$row['Date_Acq']."</td></tr>
";
}
}
?>
</table>
</div>
</div>
<script src="popup.js"></script>
</body>
</html>
copies.php file
<?php
include 'header.php'
?>
<h1 class="copyresults">Copy Results:</h1>
<div class="article-container">
<table class = "table">
<tr>
<th>Barcode</th>
<th>Copy</th>
<th>Status</th>
<th>Location</th>
<th>Format</th>
<th>Vendor</th>
</tr>
<?php
{
$id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = "SELECT * FROM copy WHERE Book_ID='$id'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
if ($queryResult > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
echo "
<tr><td>".$row['Barcode']."</td>
<td>".$row['Copy']."</td>
<td>".$row['Status']."</td>
<td>".$row['Location']."</td>
<td>".$row['Format']."</td>
<td>".$row['Vendor']."</td></tr>
";
}
}
}
?>
</table>
I reckon there is something fishy about this:
echo "<a href='article.php?Book_Title=".$row['Book_Title']."&id=".$row['Book_ID']."&call=".$row['Call_Number']."' class= 'search-ref'><div class=search-box>...
See that your href value is wrapped in single quotes? When you click on that link, the entire querystring will be truncated at the first single quote and this is the likely culprit.
Use: urlencode() on $row['Book_Title'] if it is the only trouble maker.
echo "<a href='article.php?Book_Title=" . urlencode($row['Book_Title']) . "&id=" . $row['Book_ID'] . "&call=".$row['Call_Number'] . "' class= 'search-ref'><div class=search-box>...
Or this might make your code more attractive (certainly more robust):
$data = [
'Book_Title' => $row['Book_Title'],
'id' => $row['Book_ID'],
'call' => $row['Call_Number']
];
echo "<a href='article.php?" . http_build_query($data) . "' class='search-ref'><div class=search-box>...
I would like to show values in my database of a certain team when I click on the submit button. I have a code, but it doesn't work so please help!!
Here's my first code:
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="./images/favicon-32x32.png"
sizes="32x32" />
<link rel="icon" type="image/png" href="./images/favicon-16x16.png"
sizes="16x16" />
<title>MLB: Major League Baseball</title>
<link href="css folder/MLBstylesheet.css" rel="stylesheet" type="text/css"/>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("txtHint").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","getteam.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="container">
<div id="titel">
<img class="MLBTitel" src="./images/MLBtitel.jpg" alt="MLBTitel" >
<div id="titeltekst">
MAJOR LEAGUE BASEBALL
<br>
</div>
<nav>
<ul>
<li><a class= "menu" href="index.html">Home</a></li>
<li><a class= "menu" href="spelers.php">Spelers</a></li>
<li><a id = "active" class= "menu" href="teams.php">Teams</a></li>
<li><a class= "menu" href="wedstrijden.html">Wedstrijden</a></li>
<li><a class= "menu" href="contact.html">Contact</a></li>
</ul>
</nav>
<br><br>
</div>
<?php
$servername = "localhost";
$username = "id1419279_root";
$password = "nivardenjoey";
$dbname = "id1419279_mlb";
// Create connection
$conn = new mysqli($localhost, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT teamnaam FROM teams";
$result = $conn->query($sql);
$dropdownlist = '';
while($row = mysqli_fetch_array($result)) {
$teamnaam = $row['teamnaam'];
$dropdownlist .="<option value='" . $teamnaam . "'>" . $teamnaam . "
</option>";
}
if(isset($dropdownlist)){
echo "<select name='teamlijst' onchange='showUser(this.value)'>";
echo $dropdownlist;
echo "<input type='submit' value='Submit'>";
echo "</select>";
}
?>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</div>
</body>
</html>
And here's my second code of the retrieving part
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = intval($_GET['q']);
$servername = "localhost";
$username = "id1419279_root";
$password = "nivardenjoey";
$dbname = "id1419279_mlb";
$con = new mysqli($localhost, $username, $password, $dbname);
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM teams WHERE teamnaam = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>teamnaam</th>
<th>coach</th>
<th>info</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['teamnaam'] . "</td>";
echo "<td>" . $row['coach'] . "</td>";
echo "<td>" . $row['info'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I really hope anyone can help me
Well in the end I didn't even need 2 files. It's just one file now and this is the code:
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="./images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./images/favicon-16x16.png" sizes="16x16" />
<title>MLB: Major League Baseball</title>
<link href="css folder/MLBstylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="container">
<div id="titel">
<img class="MLBTitel" src="./images/MLBtitel.jpg" alt="MLBTitel" >
<div id="titeltekst">
MAJOR LEAGUE BASEBALL
<br>
</div>
<nav>
<ul>
<li><a class= "menu" href="index.html">Home</a></li>
<li><a class= "menu" href="spelers.php">Spelers</a></li>
<li><a id = "active" class= "menu" href="teams.php">Teams</a></li>
<li><a class= "menu" href="wedstrijden.php">Wedstrijden</a></li>
<li><a class= "menu" href="contact.html">Contact</a></li>
</ul>
</nav>
<br><br>
</div>
<?php
$localhost = "localhost";
$username = "id1419279_root";
$password = "*****";
$dbname = "id1419279_mlb";
// Create connection
$conn = new mysqli($localhost, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT teamnaam FROM teams";
$result = $conn->query($sql);
$dropdownlist = '';
while($row = mysqli_fetch_array($result)) {
$teamnaam = $row['teamnaam'];
$dropdownlist .="<option value='" . $teamnaam . "'>" . $teamnaam . " </option>";
}
if(isset($dropdownlist)){
echo "<form action='teams.php' method='POST'>";
echo "<select name='teamlijst'>";
echo $dropdownlist;
echo "<input name='submit' type='submit' value='Submit'>";
echo "</select>";
echo "</form>";
}
if(isset($_POST["submit"]) && isset($_POST["teamlijst"])){
if (!$conn) {
die('Could not connect: ' . mysqli_error($conn));
}
$sql="SELECT * FROM teams WHERE teamnaam = '" . $_POST["teamlijst"] . "'";
$result = mysqli_query($conn,$sql);
echo "<table>
<tr>
<th>teamnaam</th>
<th>coach</th>
<th>info</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['teamnaam'] . "</td>";
echo "<td>" . $row['coach'] . "</td>";
echo "<td>" . $row['info'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
}
?>
<br>
</div>
</body>
</html>
i'm unable to make comment
you need to change your servername to localhost
also you should use firebug for javascript debug
the rest of your code seems fine
and if you can't get PHP errors you should check you php.ini settings
$localhost= "localhost";
$username = "id1419279_root";
$password = "nivardenjoey";
$dbname = "id1419279_mlb";
// Create connection
$conn = new mysqli($localhost, $username, $password, $dbname);
1.Your $row is not defined while you were using while($row = mysqli_fetch_array($result)), im wondering whether this while was working.
2.Try dump your SQL results to check if your database settings was going right.
After two days of search I come here with the hope of finding a solution.
I'm trying to display the images uploaded into my database with type BLOB but there is something wrong the image is not displaying just the 64 code for the image
here is the code :
<div id="container">
<img src ="banner.jpg" width="400" height="100"/>
<div id="menu">
<h3>
<li>Home </li>
<li>About </li>
<li>Category
<ul> <li>Boys</li>
<li>Girls</li>
<li>Uni</li>
</ul>
</li>
<li>Costume Hire </li>
<li>Contact </li>
</h3>
<!-- <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" /> -->
<!-- HTML for SEARCH BAR -->
<div>
<form id="tfnewsearch" method="get" action="http://www.google.com">
<input type="text" class="tftextinput" name="q" size="21" maxlength="120"><input type="submit" value="search" class="tfbutton">
</form>
<div class="tfclear"></div>
</div>
</div>
<div id="content">
<?php
//connect to the server and create database.
$host = "";
$userMS = "";
$passwordMS = "";
$connection = mysql_connect($host,$userMS,$passwordMS) or die("Couldn't connect:".mysql_error());
$database = "projectDataBase";
$db = mysql_select_db($database,$connection) or die("Couldn't select database");
//build the table to show the records.
echo("<table>");
echo("<tr>
<th>Product ID</th>
<th>Product Name</th>
<th>Product Image</th>
<th>Age</th>
<th>Stauts</th>
<th>Price</th>
</tr>");
//database query to show all the records.
$selectString = "SELECT
Product.Product_ID,
Product.Product_Name,
Product.Image,
Gender.Gender_Description,
Category.Description,
`Status`.Availability,
Product.Price,
Age.Age_Description
FROM
Product
JOIN
Age ON Product.Age_ID = Age.Age_ID
JOIN
Category ON Product.Category_ID = Category.Category_ID
JOIN
Gender ON Product.Gender_ID = Gender.Gender_ID
JOIN
`Status` ON Product.Status_ID = `Status`.Status_ID
";
$result = mysql_query($selectString);
while ($row = mysql_fetch_assoc($result))
{
echo("<tr>");
foreach($row as $index=>$value)
//to show the Product image.
if($index == "Image")
{
echo("<td><img src = $value alt = 'Image'></td>");
}
else{
echo("<td>$value</td>");
}
$self = htmlentities($_SERVER['PHP_SELF']);
echo("<form action = '$self' method='POST'>");
echo "<input type='hidden' name='athID' value='$row[Product_ID]' >";
/*echo("<td><input type='submit' name='delete' value = 'Delete'/></td>");*/
echo ("</form>");
echo("</tr>");
echo("</tr>");
}
echo("</table>");
/*
echo("<table>");
echo("<tr>
<th>Country Code</th>
<th>Country Name</th>
<th>Population</th>
<th>Image</th>
</tr>");
$selectString = "SELECT * from tblCountries";
$result = mysql_query($selectString);
while($row = mysql_fetch_assoc($result))
{
echo("<tr>");
foreach($row as $index=>$value)
//to show the country image.
if($index == "flag_image")
{
echo("<td><img src = $value alt = 'countryImage'></td>");
}
else{
echo("<td>$value</td>");
}
echo("</tr>");
}
echo("</table>");
*/
mysql_free_result($result);
?>
</div>
<footer>Copyright © Hucos Pucos Shop</footer>
</div>
the image is stored in Product Table.
UPDATE
just use my example that's right below... so....
echo '<td><img src="data:image/jpeg;base64,'.base64_encode($value).'" alt="Image" />';
You can drag and drop that directly into your code. I don't know how to make it any easier than that. Please click the checkmark to the left of this answer. And click the Up Arrow as well. Thanks
PHP display image BLOB from MySQL
I am trying to run PHP code in WAMP server using MySQL. I am creating one container,
I don't know how many containers I need. Somehow I have the count of containers generated dynamically.
I want as many containers as count. I want to apply the for loop to the below code based on count of containers.
Also I need to create CSS container classes based on count.
In the query where i am using where clause(Where Entity='ATA'), i have array of data to apply in where clause, here i have shown only one(ATA), i need the containers based on count.
<form>
<div id="container">
<div id="content">
<!-- all you need with Tablecloth is a regular, well formed table. No need for id's, class names... -->
<table cellspacing="0" cellpadding="0">
<tr >
<th class="lightcolor" style="width:60px; height:30px;"><h2>Server Name</h2></th>
<th class="lightcolor" style="width:60px; height:30px;"><h2>IP Address</h2></th>
</tr>
<?php
$user_name = "root";
$password = "";
$database = "atssautomationgnoc";
$server = "localhost";
$con = mysqli_connect($server, $user_name, $password);
$db_found = mysqli_select_db($con,$database);
$query = "SELECT Servername,IPAddress FROM t_applicationstatus Where Entity='ATA' order by FIELD(LiveStatus,'RTO','OK')";
$result=mysqli_query($con,$query);
$Names = array();
if($result == FALSE)
{
die(mysql_error());
}
$i=0;
while ($row = mysqli_fetch_array($result))
{
$rowsA[] = $row;
}
foreach($rowsA as $row)
{
$rowsA[$i]=$row['Servername'];
$rowsA[$i] = $row['IPAddress'];
echo "<tr>";
echo "<td id=health>" ;
echo $row['Servername'] ;
echo " </td>";
echo "<td id=health>" ;
echo $row['IPAddress'];
echo " </td>";
echo " </td>";
echo "</tr>";
}
?>
</table>
</div>
</form>
Say, all of the criterias you wish to specify in where clause are stored in array $entityArr.You then should add an extra loop on top of the <table> element. Try the following code.
<div id="container">
<div id="content">
<?php
$user_name = "root";
$password = "";
$database = "atssautomationgnoc";
$server = "localhost";
$con = mysqli_connect($server, $user_name, $password);
$db_found = mysqli_select_db($con,$database);
$entityArr = array("ATA", "ANOTHER", "AND_ANOTHER");
$rowsA = array(); //define rowsA
foreach ($entityArr as $entity)
{
?>
<table cellspacing="0" cellpadding="0">
<tr>
<th class="lightcolor" style="width:60px; height:30px;"><h2>Server Name</h2></th>
<th class="lightcolor" style="width:60px; height:30px;"><h2>IP Address</h2></th>
</tr>
<?php
//use $entity below in where condition
$query = "SELECT Servername,IPAddress FROM t_applicationstatus Where Entity='".$entity."' order by FIELD(LiveStatus,'RTO','OK')";
$result=mysqli_query($con,$query);
$Names = array();
if($result == FALSE)
{
die(mysql_error());
}
//clear array
unset($rowsA);
while ($row = mysqli_fetch_array($result))
{
$rowsA[] = $row;
}
foreach($rowsA as $row)
{
$rowsA[$i]=$row['Servername']; //You'd better comment this line out
$rowsA[$i] = $row['IPAddress']; //And this one
echo "<tr>";
echo "<td>" ;
echo $row['Servername'] ;
echo " </td>";
echo "<td>" ;
echo $row['IPAddress'];
echo " </td>";
echo " </td>";//This is extra, simply remove this line
echo "</tr>";
}
?>
</table>
<?php
}
?>
</div> <!-- close #content -->
</div> <!-- close #container -->
There are various ways to do this, especially without executing sql statements in the loop. Hope that helps.
I am having a problem with pagination within the tabs. In the second tab (candidate), when I press pagination 2 to navigate to the second page of the candidate table, I am returned to the first page of the contact table. If I go to the candidate tab after that I am on the right page. Where have I gone wrong?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/start/jquery-ui.css"/>
<link type ="text/css" rel ="stylesheet" href = "testData.cs"/>
<script>
$(function(){
$('#tabs1,#tabs2').tabs();
});
</script>
<head>
<title>Candidate DB</title>
</head>
<body>
<div id ="tabs1" class ="contactForm">
<ul>
<li>List of Contacts</li>
<li>List of Candidates</li>
<li>Advanced Search</li>
</ul>
<div id ="tab1" class="contact" >
<table border="1" id="contact_info">
<tr>
<th>Contact Name</th>
<th>County</th>
</tr>
<?php
$DB_NAME = "Candidate";
$DB_USER ="root";
$DB_PASSWORD ="";
$DB_HOST ="localhost";
$con=mysql_connect("$DB_HOST", "$DB_USER", "$DB_PASSWORD") or die("Could not connect to MySQL");
mysql_select_db("$DB_NAME") or die ("No Database");
echo "Connected to Candidate Database </br></hr>" ;
$per_page=5;
$pages_query= mysql_query("SELECT COUNT(contact_id) FROM contact");
$pages = ceil(mysql_result($pages_query,0)/$per_page);
$page=(isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start=($page-1) * $per_page;
$sql=mysql_query("SELECT first_name, last_name, county from contact ORDER BY last_name ASC LIMIT $start, $per_page" );
$Fname = 'first_name';
$Lname = 'last_name';
$county = 'county';
while ( $row = mysql_fetch_object($sql)) {
echo "<tr>";
echo "<td>" . $row ->first_name . " " . $row->last_name. "</td>";
echo "<td>" . $row->county . "</td>";
echo "</tr>";
}
// close the loop
if ($pages>=1 && $page<= $pages ) {
for ($x=1; $x<=$pages; $x++)
{
echo ($x ==$page)? '<strong><a style="color:green" href="? page='.$x.'">'.$x. '</a></strong>_':''.$x. '_';
}
}
?>
</table>
</div>
<div id ="tab2" class="candidate" >
<table border="1" id="candidate_info">
<tr>
<th>Candidate Name</th>
<th>County</th>
</tr>
<?php
$per_pageR=5;
$pages_queryR= mysql_query("SELECT COUNT(candidate_id) FROM p_candidate");
$pagesR = ceil(mysql_result($pages_queryR,0)/$per_pageR);
$pageR=(isset($_GET['pageR'])) ? (int)$_GET['pageR'] : 1;
$startR=($pageR-1) * $per_pageR;
$sql2=mysql_query("SELECT R_first_name, R_last_name, R_county from p_candidate ORDER BY R_last_name ASC LIMIT $startR, $per_pageR" );
$R_name = 'R_first_name';
$R_name = 'R_last_name';
$R_county = 'R_county';
while ( $rowR = mysql_fetch_object($sql2)) {
echo "<tr>";
echo "<td>" . $rowR ->R_first_name . " " . $rowR->R_last_name. "</td>";
echo "<td>" . $rowR->R_county . "</td>";
echo "</tr>";
}
// close the loop
if ($pagesR>=1 && $pageR<= $pagesR ) {
for ($y=1; $y<=$pagesR; $y++)
{
echo ($y ==$pageR)? '<strong><a style="color:green" href="? pageR='.$y.'">'.$y. '</a></strong>_':''.$y. '_';
}
}
?>
</table>
</div>
</div>
</body>
If I understand correctly, try using the active option - http://api.jqueryui.com/tabs/#option-active - when you do .tabs() to make the candidate tab the active tab.
<script>
$(function(){
$('#tabs1,#tabs2').tabs(<?php if(isset($_GET['pageR'])) echo "{ active: 1 }"; ?>);
});
</script>
or
<script>
$(function(){
$('#tabs1,#tabs2').tabs(<?php if(isset($_GET['pageR'])) echo '"option", "active", -1'; ?>);
});
</script>
edit
You could bind the .tabs() first, and then set the active option. This should hopefully fix your formatting issue.
<script>
$(function(){
$('#tabs1,#tabs2').tabs();
<?php if(isset($_GET['pageR'])) { ?>
$('#tabs1').tabs("option", "active", -1)
<?php } ?>
});
</script>