so I have this blog that I am creating, but I am having issues with displaying an image from a database to the page itself. It only comes up with a broken image. The data does appear in the database however. It just doesn't display on the page.
Here is the image.php code (used to display the text and images):
<html>
<body>
<?php
//connect to database
//Name the variables
$host= "localhost";
//Localhost is the name of the computer that USBWebser has been loaded on
$username = "user";
$password = "pwd";
$database = "blog";
$dbh=mysql_connect("$host", "$username", "$password") or die('Could not connect:' .mysql_error());
//if cannot connect to database display error message
if(!$dbh)
{
echo mysql_error();
}
mysql_select_db("$database");
//get the id number of the row that the photo is located in and place it in $ano
$ano=$_GET['postID'];
//select the data and type for the photo identified by id
$sql="SELECT photo, phototype FROM blog where postID='$ano'";
//check if sql query can be executed
$r=mysql_query($sql, $dbh);
//if sql query can be executed
if($r)
{
//get the data from the query
$row=mysql_fetch_array($r);
//set the header information so that an image can be displayed
$type="Content-type: image/png" .$row['phototype'];
header($type);
//display the image
echo $row['photo'];
}
else
{
echo mysql_error();
}
?>
Here is the code for the main_menu.php (where I would like the image to appear)
<?PHP
//Name the variables
$host= "localhost";
//Localhost is the name of the computer that USBWebser has been loaded on
$username = "user";
$password = "pwd";
$database = "blog";
$mysqli=new mysqli($host, $username, $password, $database);
//Connect to Header
include "header.php";
?>
<?php
//Select fields from the posts table
$sql="SELECT postID, title, date, contents, rating, photo, phototype FROM posts";
//Place the data into a variable named $result
$result= $mysqli->query($sql);
if ($result->num_rows>0){
while ($row=$result->fetch_assoc()) {
?>
<br><table border="1" bordercolor="25dae3" width="53%"><th><font color="white">Title</th><th><font color="white">Date</th><th><font color="white">Contents</th><th><font color="white">Image</th><th><font color="white">Rating</th>
<tr><td width = "100" align="center"><font color="white">
<?php
echo $row["title"];
?>
</td>
<br><td width="100" align="center"><font color="white">
<?php
echo $row["date"];
?>
</td>
<br><td width="300" align="center"><font color="white">
<?php
echo $row["contents"];
?>
</td>
<br><td width="300" align="center"><font color="white">
<img src="<?php echo $row['photo']; ?>" width=300 height=300/>;
</td>
<br><td width="100" align="center"><font color="white">
<?php
echo $row["rating"];
?>
</td></tr></font>
<?php
}
} else {
//Display message that no data was present
echo "0 results";
}
//Close connection
$mysqli->close();
?>
The add_post.php
<html>
<header>
</header>
<body>
<?php
//Name the variables
$host = "localhost";
//Localhost is the name of the computer that USBWebserver has been loaded on
$username = "user";
$password = "pwd";
$database = "blog";
$mysqli=new mysqli($host, $username, $password, $database);
//Get variables from the form
$new_post_title=$_POST["newtitle"];
$new_post_date=$_POST["newdate"];
$new_post_contents=$_POST["newcontents"];
$new_post_rating=$_POST["newrating"];
$photo=addslashes(file_get_contents($_FILES["photo"]["tmp_name"]));
$imagesize=getimagesize($_FILES["photo"]["tmp_name"]);
//mime returns the image time eg. image/jpeg
$imagetype=$imagesize['mime'];
//Enable sql to read quotation marks within sentences
$new_post_title=addslashes($new_post_title);
$new_post_date=addslashes($new_post_date);
$new_post_contents=addslashes($new_post_contents);
$new_post_rating=addslashes($new_post_rating);
//Enter the new information into the posts table
$sql="INSERT INTO posts(postID, title, date, contents, rating, photo, phototype) VALUES (Null, '$new_post_title', '$new_post_date', '$new_post_contents', '$new_post_rating', '$photo', '$imagetype')";
//Run the query
$result=$mysqli->query($sql) or die (mysqli_error($mysqli));
if ($result) {
header ('location:main_menu.php');
}
else {
echo mysql_error();
}
?>
</body>
</html>
And the form to submit a post to the blog (add_new_post.php)
<HTML>
<style>
form {
border-opacity: 1.0 ;
display: incline-block;
text-align: center;
}
input[type=text]:focus, input[type=date]:focus {
width: 50%;
height: 20%;
border: 3px solid #00ffff;
}
body {
text-align: center;
padding-top: 50px;
}
</style>
<HEAD>
</HEAD>
<BODY><font color="white">
<br><br><br><H1 text-align="center">Add a New Post</H1>
<?php
//Connect To Header Page
include "header1.php";
//Connect To Database
include "dbconnect.php";
?>
<br>
<br>
<!-- <HR> Tag inserts a horizonal line across the page (horizontal rule)-->
<!-- <Form> Tag indicates that a form will be created -->
<!-- action indicates the file used to process the input when the submit button is pressed-->
<form enctype= "multipart/form-data" action="add_post.php" method = "POST">
Title: <br>
<!-- <input type> Tag indicates the type of input expected eg. text. Name = indicates the name given to the input-->
<input type="text" name="newtitle"><br>
Date: <br>
<input type="date" name="newdate"><br>
Contents: <br>
<input type="text" name="newcontents"><br>
Rating: <br>
<input type="text" name="newrating"><br>
Please Browse to where the photo is located:<br>
<input type = file name = "photo"><br>
<br>
<!-- Value indicates the text to be displayed. In this case, displayed on the button -->
<input type ="submit" value="Submit">
</form>
</BODY>
</HTML>
Any assistance on this issue would be appreciated.
Thanks
You are using php tag wrong
<br><td width="300" align="center"><font color="white">
<?php
echo "<img src="<?php echo $row['photo']; ?>" width=300 height=300/>";
?>
</td>
instead of above code use following code
<br><td width="300" align="center"><font color="white">
<img src="<?php echo $row['photo']; ?>" width=300 height=300/>
</td>
Related
This question may look similar but please understand my problem.In my update page I got confused with $_GET method. In my first page I gave a link to edit the table like this
index.php
<?php
include_once("db.php");
$result1 = mysqli_query($connect, "SELECT * FROM mrinsert WHERE userid='{$_SESSION['user_id']}'");
?>
<?php
while($res = mysqli_fetch_array($result1)) {
echo "<tr>";
echo "<td>".$res['bugta']."</td>";
echo "<td>".$res['releaseta']."</td>";
echo "<td>".$res['ccota']."</td>";
echo "<td>Edit | Delete</td>";
}
?>
my mredit.php page displaying with existing values by using mrinsertid. but when try to update the values it giving error in this place:
<?php
//getting id from url
$mrinsertid = $_GET['mrinsertid']; //ERROR Undefined index
//selecting data associated with this particular id
$result = mysqli_query($connect, "SELECT * FROM mrinsert WHERE mrinsertid=$mrinsertid"); //WARNING in this line
while($res = mysqli_fetch_array($result))
{
$releaseta=$res['releaseta'];
$keyta=$res['keyta'];
$programleadsta=$res['programleadsta'];
$ccota=$res['ccota'];
$nextmilestonesta=$res['nextmilestonesta'];
$bugta=$res['bugta'];
$risksta=$res['risksta'];
$summaryta=$res['summaryta'];
?>
My whole mredit.php:
<?php
// including the database connection file
include_once("db.php");
if(isset($_POST['update']))
{
$mrinsertid = mysqli_real_escape_string($connect,$_POST['mrinsertid']);
$releaseta= mysqli_real_escape_string($connect,$_POST['releaseta']);
$keyta= mysqli_real_escape_string($connect,$_POST['keyta']);
$programleadsta= mysqli_real_escape_string($connect,$_POST['programleadsta']);
$ccota= mysqli_real_escape_string($connect,$_POST['ccota']);
$nextmilestonesta= mysqli_real_escape_string($connect,$_POST['nextmilestonesta']);
$bugta= mysqli_real_escape_string($connect,$_POST['bugta']);
$risksta= mysqli_real_escape_string($connect,$_POST['risksta']);
$summaryta= mysqli_real_escape_string($connect,$_POST['summaryta']);
// checking empty fields
if(empty($releaseta) || empty($keyta) || empty($programleadsta)||empty($ccota) || empty($nextmilestonesta) || empty($bugta)|| empty($riskta) || empty($summaryta)) {
if(empty($releaseta)) {
echo "<font color='red'>release field is empty.</font><br/>";
}
if(empty($keyta)) {
echo "<font color='red'>Akey field is empty.</font><br/>";
}
if(empty($programleadsta)) {
echo "<font color='red'>program field is empty.</font><br/>";
}
if(empty($ccota)) {
echo "<font color='red'>cco field is empty.</font><br/>";
}
if(empty($nextmilestonesta)) {
echo "<font color='red'>nextmilestone field is empty.</font><br/>";
}
if(empty($bugta)) {
echo "<font color='red'>bug field is empty.</font><br/>";
}
if(empty($risksta)) {
echo "<font color='red'>risk field is empty.</font><br/>";
}
if(empty($summaryta)) {
echo "<font color='red'>summary field is empty.</font><br/>";
}
} else {
//updating the table
$result = mysqli_query($connect, "UPDATE mrinsert SET releaseta='$releaseta',keyta='$keyta',programleadsta='$programleadsta',ccota='$ccota',nextmilestonesta='$nextmilestonesta',bugta='$bugta',risksta='$risksta',summaryta='$summaryta' WHERE mrinsertid='$mrinsertid'");
//redirectig to the display page. In our case, it is index.php
header("Location: index.php");
}
}
?>
<?php
//getting id from url
$mrinsertid = $_GET['mrinsertid'];
//selecting data associated with this particular id
$result = mysqli_query($connect, "SELECT * FROM mrinsert WHERE mrinsertid=$mrinsertid");
while($res = mysqli_fetch_array($result))
{
$releaseta=$res['releaseta'];
$keyta=$res['keyta'];
$programleadsta=$res['programleadsta'];
$ccota=$res['ccota'];
$nextmilestonesta=$res['nextmilestonesta'];
$bugta=$res['bugta'];
$risksta=$res['risksta'];
$summaryta=$res['summaryta'];
?>
<html>
<head>
<title>Edit Data</title>
</head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.wrap {
position:relative;
width:50px;
}
.wrap button {
border:5px solid;
position:absolute;
top:50px;
border-color:black;
border-radius: 50%;
margin-left:20px;
display:block;
height: 50px;
width: 50px;
background-color:green;
}
</style>
<body>
Home
<br/>
<form name="form1" method="post" action="mredit.php">
<input type="text" name="mrinsertid" value=<?php echo $_GET['mrinsertid'];?> >
<input type="submit" name="update" value="update">
<div id="MRtableDIV">
<table border="2">
<tr style="background-color:#80bfff">
<th style="width:8%"><center>Release</center></th>
<th style="width:5%"><center>Status</center></th>
<th style="width:6%"><center>Key</center></th>
<th style="width:15%"><center>Program Leads</center></th>
<th style="width:6%"><center>CCO Dates</center></th>
<th style="width:6%"><center>Next Milestones</center></th>
<th style="width:10%"><center>Bug Projection</center></th>
<th style="width:14%"><center>Risks</center></th>
<th style="width:20%"><center>Summary</center></th>
<tr>
<tr>
<tr>
<td><textarea name="releaseta" id="ReleaseTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff""><?php echo $res['releaseta'];?></textarea></td>
<td>
<div class="wrap">
<button id="button1" value = "button" style= "color:white" onclick="setColor('button1', '#101010')";></button>
</div>
<textarea name="" id="StatusTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"></textarea>
</td>
<td><textarea name="keyta" id="KeyTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['keyta'];?></textarea></td>
<td><textarea name="programleadsta" id="ProgramLeadsTA" style="width:100%;height:200px;;resize:none;background-color:#e6f2ff"><?php echo $res['programleadsta'];?></textarea></td>
<td><textarea name="ccota" id="CCOTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['ccota'];?></textarea></td>
<td><textarea name="nextmilestonesta" id="NextMilestonesTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['nextmilestonesta'];?></textarea></td>
<td><textarea name="bugta" id="BugTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['bugta'];?></textarea></td>
<td><textarea name="risksta" id="RisksTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['risksta'];?></textarea></td>
<td><textarea name="summaryta" id="SummaryTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['summaryta'];?></textarea></td>
</tr>
</tr>
</table>
</div>
</form>
</body>
</html>
<?php
}
?>
Try this
I just remove the { } and added directly ".$_SESSION['user_id']; and store the query in the variable which is called as $result1.
$result1 = "SELECT * FROM mrinsert WHERE user_id=".$_SESSION['user_id'];
$result = mysqli_query($conn, $result1);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($res = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>".$res['bugta']."</td>";
echo "<td>".$res['releaseta']."</td>";
echo "<td>".$res['ccota']."</td>";
echo "<td><a href='mredit.php?mrinsertid=".$res['mrinsertid']."'>Edit</a></td>";
}
}
else {
echo "0 results";
}
mysqli_close($conn);
mredit.php
echo $mrinsertid = $_GET['mrinsertid'];
Remove the action part from the form and it will work fine. Between, don't forget to type-cast the value to integer before using it. Also, use prepare statements whenever you can.
The problem is that in the first call of "mredit.php" you are using a GET request since you clicked on a <a href> link. In this case your $_GET['mrinsertid'] will be set to the value set in the URL. In your second call of "myedit.php" you are using a POST request as defined in your form with the method="post" attribute. Therefore the value is not in $_GET[] but in $_POST[] instead.
There are several solutions how to fix this:
Use $_REQUEST instead of $_GET. The $_REQUEST array is a merge of the $_GET, $_POST and $_COOKIE array, so it doesn't matter when the value comes from the URL or from a HTML form (send via a POST request).
Change the method= attribute in your <form> tag to GET to send it as a GET request. However you usually don't do that as HTML forms should be send via a POST request for various reasons.
Add the mrinsertid value to the URL in the action= attribute of your <form> tag. This way the value of mrinsertid is in $_GET, but the form data will still be in $_POST.
Im trying to align the image that I fetched from my database with a text that is also fetched from database. The text seems ok but the image just stick to the left
<div align="center">
<p>
<?php
$vid =$_REQUEST[#id];
include 'conn.php';
$sql = mysql_query("SELECT * FROM product_car where Id = '$vid'");
$vid = 'Id';
$vnamaproduk = 'NamaProduk';
$vharga = 'Harga';
$vpenerangan = 'Penerangan';
$vgambar = 'Gambar';
?>
<table width="1000" border="0" align="center">
<?php
while($row= mysql_fetch_assoc($sql)){
?>
<tr>
<td>
<img src="gambar/car/<?php echo $row[$vgambar];?>"width="500" height="400"/>
</td>
<td>
<?php
echo "<br>Product Id : ".$row[$vid];
echo "<br>Product Name : ".$row[$vnamaproduk];
$harganew =sprintf('%0.2f',$row[$vharga]);
echo "<br>Price : RM".$harganew;
echo "<br> <br>".$row[$vpenerangan];
echo "<br>";
}
?>
ADD TO CART
</td>
</tr>
</table>
</div>
is the image displayed as a block?
img {
display:block;
margin:auto;
}
If you want to center the image, you could try this
img {
margin: auto 0;
}
I am taking title as an input from user and posting it an inserting it to the mysql database what i want is that when i am displaying that data again it should be a hyperlink so that i can click on that title an can do commenting after that..
whatever is title in left column should a link link in right column
code i am writing:-
take.php
<?php
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Ask-Free/Your Account</title>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body id="hello">
<div id="heading">
<table border="0" style="width: 100%" cellspacing=".5">
<tr>
<td>
<h1 style="color:#fffaf0">
<i>ASK-FREE</i>
</h1>
</td>
<td>
<form>
<input div class="search" type="text" placeholder="Search Your Question Here">
<input div class="button" type="button" value="Ask Question">
</form>
</td>
<div class="username">
<td><h4 style="color:white">Welcome </h4></td>
<td><a div class="a" style="color: white" href="logout.php" target="_blank">Home</a></td>
<td>
<a div class="a" style="color: white" href="accountsetting.php" target="_blank">Account Settings</a>
</td>
<td><a div class="a" style="color: white" href="logout.php" target="_blank">Log Out</a></td>
<td><a div class="a" style="color: white" href="Help.php" target="_blank">Need Help?</a></td>
</tr>
</table>
</div>
</div>
<div id="second">
<h2 style="color: white">
<center> ASK YOUR QUESTION!</center>
</h2>
</div>
<div class="recent">
<h2 style="color:black" div class="b">ASK YOUR QUESTION HERE</h2>
<br>
<form action="post.php" method="POST">
<p style="color:black">TITLE<br><input div class="c" type="text" id="title" name="title">
<br>
<br>
<br>
DESCRIPTION<br><textarea div class="d" name="description" id="description" >
</textarea>
<br>
<br>
<input div class="button2" type="submit" value="POST">
</form>
</div>
<div class="new">
<h2 style="color:black" div class="e">RECENTLY ASKED QUESTIONS</h2>
<br>
<br>
<?php
echo "<table style='border: solid 1px solid black;'>";
echo "<tr><th>SERIAL NO.</th><th>TITLE</th><th>DESCRIPTION</th><th>DATE</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:250px;border:1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shubhamyadav";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT id,title,description,date FROM questions");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>
</div>
<div id="footer">
<table border="0" style="width: 100%" cellspacing="-0.2">
<td>
<tr>
<td style="color: white">Ask-Free,Inc 2015</td>
<td style="color: white">User Agreement</td>
<td style="color: white">Privacy Policy</td>
<td style="color: white">Community Guidelines</td>
<td style="color: white">Created by Shubham Yadav</td>
<td style="color: white">Terms & conditions</td>
<td style="color: white">Contact Us</td>
<td style="color: white">Ad Choices</td>
<td style="color: white">Cookie Policy</td>
<td style="color: white">Hyperlinking Policy</td>
<td style="color: white">Copyright Policy</td>
</tr>
</td>
</table>
</div>
</body>
</html>
post.php:-
<?php
/*** begin our session ***/
session_start();
/*** first check that both the username, password and form token have been sent ***/
if(!isset( $_POST['title'],$_POST['description']))
{
echo 'Enter A Valid Title And Description To Your Question';
}
/*** check the form token is valid ***/
/*** check the username is the correct length ***/
elseif (strlen( $_POST['title']) > 255 || strlen($_POST['title']) < 1)
{
echo 'You Must Add A valid title';
}
/*** check the password is the correct length ***/
else
{
/*** if we are here the data is valid and we can insert it into database ***/
$title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
$description = filter_var($_POST['description'], FILTER_SANITIZE_STRING);
$date = date('y-m-d');
/*** now we can encrypt the password ***/
/*** connect to database ***/
/*** mysql hostname ***/
$mysql_hostname = 'localhost';
/*** mysql username ***/
$mysql_username = 'root';
/*** mysql password ***/
$mysql_password = '';
/*** database name ***/
$mysql_dbname = 'shubhamyadav';
try
{
$dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
/*** $message = a message saying we have connected ***/
/*** set the error mode to excptions ***/
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** prepare the insert ***/
$stmt = $dbh->prepare("INSERT INTO questions (title,description,date) VALUES (:title,:description,:date)");
/*** bind the parameters ***/
$stmt->bindParam(':title', $title, PDO::PARAM_STR);
$stmt->bindParam(':description', $description, PDO::PARAM_STR);
$stmt->bindParam(':date', $date, PDO::PARAM_STR);
/*** execute the prepared statement ***/
$stmt->execute();
/*** unset the form token session variable ***/
header('location:afterpost.php');
/*** if all is done, say thanks ***/
}
catch(Exception $e)
{
/*** check if the username already exists ***/
if( $e->getCode() == 23000)
{
echo 'Question Already Exist';
}
else
{
/*** if we are here, something has gone wrong with the database ***/
echo 'We are unable to process your request. Please try again later';
}
}
}
?>
I have this php script that parses data from a regular url in the form of "http://example.com/board.php?username=John&score=15&session=976837465", places that in a simple MySQL db, then sorts the score to form a top 10.
Can someone help me with the code to do the same for a SQL Server 2012 db? Please assume that the db has already been created.
Note : I know the method above is insecure and not recommended, but at present it is the only way I am able to pass data over - trust me on this.
Please find the full php code below.
Thanks in advance,
John
<?php
$dbhost = 'localhost'; // Database Host Name - usually 'localhost'
$dbname = 'mydb'; // Database Name
$dbuser = 'myusername'; // Database User Name
$dbpass = 'mypassword'; // Database User Password
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname,$conn);
$game = 'My Game'; // The Name of your game
{
$name = urldecode(mysql_real_escape_string($_GET['username']));
$score = intval(mysql_real_escape_string($_GET['score']));
$gamesession = mysql_real_escape_string($_GET['session']);
global $tlb;
if (!empty($game) && !empty($name) && !empty($score) && !empty($gamesession)) {
$query = "INSERT INTO game_leaderboard (game, name, score, session)
VALUES('$game', '$name', '$score', '$gamesession')";
mysql_query($query) or trigger_error(mysql_error()." in ".$query);
}
}
?>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Sansita+One'
rel='stylesheet' type='text/css'>
<link href="table.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<div role="main">
<header>
<h2 class="toptitle">My Game</h2>
</header>
<?php
$lboard = "SELECT * FROM game_leaderboard WHERE game = '$game' ORDER BY score DESC LIMIT 10";
$leaderboard = mysql_query($lboard) or trigger_error(mysql_error()." in ".$lboard);
?>
<table class="th">
<thead style="background:#f7f7f7;">
<tr>
<td style="font-size: 18px; width:30%;">Name</td>
<td style="font-size: 18px; width:70%;">Score</td>
</tr>
</thead>
<tbody style="background:#ffffff;border:1px solid #bfbfbf;">
<?php
$i=0;
while ($i < mysql_numrows($leaderboard)) { ?>
<tr style="border-bottom:1px solid #cccccc;">
<td><?php echo ucwords(mysql_result($leaderboard,$i,"name")); ?></td>
<td><?php echo mysql_result($leaderboard,$i,"score"); ?></td>
</tr>
<?php $i++; } ?>
</tbody>
</table>
</div>
</body>
</html>
PHP has made it easy to access data from any database, you can follow this guide i found here for ms sql servers http://www.easysoft.com/developer/languages/php/sql_server_unix_tutorial.html
I have created a database using phpmyadmim and to access it, I made a name.php file.
Accessing the registration number, name was easy, but the image retrieval is not so.
I stored the image via phpmyadmin using LongBlob as the type..but I'm not able to display it..
how to retrieve the image?
Please if someone can help,it would be high appreciated.
Thanks,
LJ
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PHYTOCHEMICAL DB</title>
<style type="text/css">
body {
font-family: Georgia, "Times New Roman",
Times, serif;
color: purple;
background-color: #EEEEEE}
</style>
</head>
<body>
<table width="800" border="" align="center">
<tr>
<td colspan="2" style="background-color:#FFA500;height:30px;width:700px">
<div> <img src="leaves.jpg" height="300" width="900"/> </div> <br/>
</td>
</tr>
<tr>
<td style="background-color:#FFD700;width:250px;">
<b>Menu</b><br>
<i> Home<br>
<i> Search by Database ID (DID) <br>
<i><a href="mw.php">Search by Molecular weight<br>
</td>
<td style="background color:#EEEEEE;height:500px;width:800px;">
<form action="" method="POST">
<p> Enter the name </p>
<input type="text" name="pname">
<input type="submit" value="submit" name="submit1">
<br>
</form>
<?php
$mysqli = new mysqli("localhost", "root", "osddosdd", "phychem");
if (mysqli_connect_errno()) {
printf("Connect failed:%s\n", mysqli_connect_error());
exit();
}
if (isset($_POST['submit1'])) {
$pname = $_POST['pname'];
$query = ("select * from pchem where name LIKE '$pname'");
$result = $mysqli->query($query);
echo 'The retrieved query is:';
echo "<table border='1'>
<tr>
<th>DID</th>
<th>Name</th>
<th>Molecular weight</th>
</tr>";
while ($row = $result->fetch_row()) {
echo '<tr>';
printf("<th>%d</th> <th> %s </th> <th> %2f </th>", $row[0], $row[1], $row[2]);
echo '</tr>';
echo '</table>';
}
}
$mysqli->close();
?>
</td>
</table>
</body>
</html>
don't store the images directly into the database as BLOBs. Just store them as files and only store the file names in the database.
I have googled and found some links that would solve you problem. Refer these links :
http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html
http://www.coderslexicon.com/inserting-images-into-mysql-and-retrieving-them-using-php/
http://pujanpiya.com.np/?q=node/25