i am trying to display the isbn number from my database when they click an image from another page and for some reason i keep getting this error
Notice: Undefined index: isbn on line 8
<html><title>Employee List</title> <head></head>
<body>
<h1> List of Employees </h1>
<?php
require_once("include/db_connect.php");
$db_link = db_connect("project");
$isbn = $_REQUEST['isbn'];
$query = "SELECT * FROM bookstore WHERE isbn = '$isbn'";
$result = mysql_query($query);
if ($row = mysql_fetch_assoc($result)) {
$isbn = $row['isbn'];
echo "<tr><td><strong>Isbn:</strong>". $isbn. "</td>";
}
?>
</body>
</html>
main program for my php program
<?php require_once("include/db_connect.php"); ?>
<html>
<head><title>Displaying Image files using PHP</title></head>
<body>
<h1>Bookworms Booksite</h1>
<style> #import "css/style.css";</style>
<div id = "nav">
<ul>
<li><a class = "navbutton" href="index.html">Home</a></li>
<li><a class = "navbutton" href="membership.html">Books</a></li>
<li><a class = "navbutton" href="classes.html">Shopping Cart</a></li>
<li><a class = "navbutton" href="">Checkout</a></li>
<li><a class = "navbutton" href="shop.html" id ="current" >About</a></li>
</ul>
</div>
<p></p>
<p></p>
<div id = "sideNav">
<ul>
<li>Enter Bookstore</li><br>
<li>Bookstore Administartion</li><br>
<li>Search</li>
</ul>
</div>
<?php
$db_link = db_connect("project");
// Retrieve table properties
$fields = mysql_list_fields("project", "bookstore");
$num_columns = mysql_num_fields($fields);
// Make a simple database query to select all columns and rows
$query = "SELECT * FROM bookstore";
$result = mysql_query($query) or die("SQL query failed");
// Display results as an HTML table. Note how mysql_field name
// uses the $fields object to extract the column names
echo '<table border="1" cellpadding = "5" >';
// Display the column names
echo "<tr>";
echo "</tr>";
// Loop over the rows of the table.
// $row contains the information for each row
// Refer to the names of the fields in the table
// Must ahow the path where the image files are held
while ($row = mysql_fetch_assoc($result))
{
echo "<tr>";
$isbn = $row['isbn'];
$title = $row['title'];
echo "<td><a href='bookDetail.php'><img src = 'images/". $row['image']. "'></a></td>";
echo "<a href='bookDetail.php? id= ". $isbn . "'>". $title . "</a><br/>";
echo "<td>". $row['isbn']."</td>";
echo "<td>". $row['title']."</td>";
echo "<td>". $row['author']."</td>";
echo "<td>". $row['pub']."</td>";
echo "<td>". $row['year']."</td>";
echo "<td>". $row['price']."</td>";
echo "</tr>";
}
echo "</table>";
// Free the resources and close the connection
mysql_free_result($result);
mysql_close($db_link);
?>
</body>
</html>
Line 8 is this :
$isbn = $_REQUEST['isbn'];
Therefore, your $_REQUEST['isbn'] variable is undefined. Do a print_r ($_REQUEST); to check your request parameters.
To use $_REQUEST['isbn'], you need the page to be called by a form and have a field with name='isbn', otherwise it won't exist.
More information about forms : http://www.php.net/manual/en/tutorial.forms.php
Actually the line 8 is "$_REQUEST['isbn'];" which has nothing to do with database. Are you sure you're passing the parameter to the page?
Related
<?php
$servername = "*****";
$username = "****";
$password = "";
$dbname = "****";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$product_id = intval($_GET['product_id']);
// make sure its only an id (SQL Incjection problems)
$sql = "SELECT * FROM product_gallery WHERE pid=$product_id";
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) {
while ($row = mysqli_fetch_array($result)) {
echo"<div class='tg-productbox'>";
echo" <div id='tg-thumblider' class='tg-thumblider tg-productgalleryslider owl-carousel'>";
echo" <figure class='item'><img src='$row[product_image]' alt='image description'></figure>";
echo" </div>";
echo" </div>";
echo" </div>";
};
} else {
echo "0 results";
}
$conn->close();
?>
This is my php code to view multiple images from database.but I can only see one image in front end.please help me..there is a main image and a slider to view to multiple images. It is similar to how we see product images in a shopping site
this is my php code to view multiple images from database.but i can only see one image in front end.please help me..there is a main image and a slider to view to multiple images.its is similar to how we see product images in a shopping site
There are some other mistakes like one extra closing div in loop and semicolon }; which not necessary.
Try something like below if you are getting multiple records it will definitely work.
while ($row = mysqli_fetch_array($result)) {
extract($row);
?>
<div class='tg-productbox'>
<div id='tg-thumblider' class='tg-thumblider tg-productgalleryslider owl-carousel'>
<figure class='item'>
<img src="<?php echo $product_image; ?>" alt="image description">
</figure>
</div>
</div>
<?php
}
Changes
Remove id='tg-thumblider' from echo "<div id='tg-thumblider' class='tg-thumblider. ID must need to be unique. According to the code provided, In while loop, every <div> will have same ID, which is wrong. So, either remove that ID or give some unique ID to each div.
Remove extra echo "</div>";
Remove ; from closing of while loop.
Code:
<?php
if ($result->num_rows > 0) {
while ($row = mysqli_fetch_array($result)) {
echo "<div class='tg-productbox'>";
echo "<div class='tg-thumblider tg-productgalleryslider owl-carousel'>";
echo "<figure class='item'><img src='".$row['product_image']."' alt='image description'></figure>";
echo "</div>";
echo "</div>";
}
}?>
So far this loop pulls all the item images from the items table using a method I created and positions them wonderfully.
Now I am trying to use the $linv['item_id'] to find the item id's of the items in the items table, and pull the data from that table to use between the <span> tags (creating a tooltip).
I'm so confused with all the sql calls now.
<?php
$idata = mysql_query("SELECT * FROM `items` where `item_id`='".$linv['item_id']."'");
while($linv = mysql_fetch_array($inv)){
$idata = mysql_fetch_array($itemdata);
echo "<a class='tooltips' href='#'><img id='bagicons' src='".getiimage($linv['item_id'])."' />
<span>
".$itemdata['item_name']."
</span></a>" ;
}
?>
</div>
<div id="spacer"> </div>
<?php
echo "<div id='char'>".createavatar($_SESSION['uid'])."</div>";
include("footer.php");
?>
change
<?php
$idata = mysql_query("SELECT * FROM `items` where `item_id`='".$linv['item_id']."'");
while($linv = mysql_fetch_array($inv)){
$idata = mysql_fetch_array($itemdata);
echo "<a class='tooltips' href='#'><img id='bagicons' src='".getiimage($linv['item_id'])."' />
<span>
".$itemdata['item_name']."
</span></a>" ;
}
?>
to
<?php
while($linv = mysql_fetch_array($inv))
{
$idata_result_set = mysql_query("SELECT * FROM `items` where `item_id`='".$linv['item_id']."'");
if(mysql_num_rows($idata_result_set) == 0)
continue;
$idata = mysql_fetch_array($idata_result_set);
echo "<a class='tooltips' href='#'><img id='bagicons' src='".getiimage($linv['item_id'])."' />
<span>
".$idata['item_name']."
</span></a>" ;
}
?>
I want to create an automatic cms in my website using php and mysql
i.e. I would just feed data to mysql table and it will generate result.
so my code is:
<!DOCTYPE html>
<html>
<head>
<?php
include 'head.php';
include 'conct.php';
?>
<title>GIZMOMANIACS|DOWNLOADS</title>
</head>
<body>
<div id="container" style="width:100%;height:100%;clear:both">
<div id="header" style="background-color:#FFFFFF;">
<div class="head" style="clear:both">
<a href= "http://gizmomaniacs.site88.net">
<img src="/GM%203D.gif" width= "200" height="100" alt='gizmomaniacs logo'></a></div>
<h1 style="margin-bottom:0; float:right"><font id="gmfont">GIZMOMANIACS</font></h1>
</div>
<div id="menu" style="clear:both;background-color:#0762AE">
<?php include 'head.html'; ?></div> <div class="content" >
<?php include 'search.php'; ?>
<ul>
<?php
$sql = "SELECT * from downloads";
$result = mysql_query($sql);
if($result==false){
$view = "error";
$error = "Could not retrieve values";
}
else {
$dload = $GET_['downloadname'];
$imagelink = $GET_['imagelink'];
$title = $GET_['title'];
while ($row = mysql_fetch_array($result))
{
echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
}
}
?>
</ul>
</div>
<div class="social">
<?php
include 'social.php';
?></div>
</div>
</body>
</html>
everything is gong well but three thing are not happening they are:
a href atrribute not retreiving from db
a title atrribute not retreiving from db
img src atrribute not retreiving from db
in the actual source it is showing
<a class ="alldld" href="" title=""><img class="downloads" src =""/></a><br></li>
<li><a class ="alldld" href="" title=""><img class="downloads" src =""/></a>
the src href title attribute are blank
so what to do?
change this part of code
$dload = $GET_['downloadname'];
$imagelink = $GET_['imagelink'];
$title = $GET_['title'];
while ($row = mysql_fetch_array($result))
{
echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
}
to
while ($row = mysql_fetch_array($result))
{
$dload = $row['downloadname'];
$imagelink = $row['imagelink'];
$title = $row['title'];
echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
}
While retrieving from DB you need to use the array in which the values are fetched and not the $_GET array. also there is no such thing as $GET_.
Important Note: Stop using mysql_ function and start using mysqli_* functions or PDO.For more info see here
You're outputting the rows like this:
$dload = $GET_['downloadname'];
$imagelink = $GET_['imagelink'];
$title = $GET_['title'];
while ($row = mysql_fetch_array($result))
{
echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
}
}
There's a couple of issues with that. First of all, if you wanted to retrieve it from the query string, you'd want to use $_GET, not $GET_. Second, you don't want to retrieve it from the query string with $_GET; you want to retrieve it from $row. Thirdly, you need to put it inside the while loop. Once you've fixed that, it should work.
$_GET is the array containing values passed in the URL.
<?php
// Let's take the following URL
// http://localhost/index.php?name=John&age=20
echo $_GET["name"]; // Will display 'John'
echo $_GET["age"]; // Will display '20'
?>
When you select something from the database, the variable $row contains each line of the results that you get using the function mysql_fetch_array. Try this to display your data :
<?php
// ...
while ($row = mysql_fetch_array($result)) {
$dload = $row["downloadname"];
$imagelink = $row["imagelink"];
$title = $row["title"];
echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
}
?>
I'm trying to pass the id of a blogpost in an url. It works in the adminpanel (read blogpost) now I want to do the same on my frontpage, so that it says read more under every blogpost, but when I use the same code it doesn'nt pass the id.
My code that isn't working:
$db_connection = mysql_connect('localhost', 'root', '')or die("cannot connect");
mysql_select_db('database',$conn);
// mysql query
$sql_query="SELECT * FROM blog_posts ORDER BY id DESC";
// Create the ps_pagination object here
$pager = new ps_pagination($db_connection,$sql_query,5,5);
echo $pager->renderFullNav();
//The paginate() function returns a mysql result set
$rs = $pager->paginate();
while($rows = mysql_fetch_assoc($rs)) {
// table to display results here // modify here
echo '<h1>'.$rows["title"].'</p></h1>';
echo '<p> '.$rows["post"].'</p>';
echo '<p class="klein"><span>Door</span>: '.$rows["first_name"].' ';
echo '<p class="klein">Geplaatst op</span>: '.$rows["date_posted"].'</p>';
echo "<td><a class='link' href=\"/admin/bekijk.php?id=$row->id\">Lees meer</a></td>";
echo "<BR>";
}
// close mysql connection here
mysql_close();
My code that is working:
while($row = mysql_fetch_object($sql))
{
echo "<tr>";
echo "<h1><td><a class='link' href=\"bekijk.php?id=$row->id\">$row->title</a></td></h1>";
if($row->id == 0)
{ //home page verberg delete link
}
else
{
// delete functie waarbij een alert word weergegeven of je dit zeker wil
echo "<td><a class='link' href=\"javascript:delpage('$row->id','$row->title');\">Verwijder</a></td>";
echo '<br>';
echo "<td><a class='link' href=\"edit.php?id=$row->id\">Pas aan</a></td>";
echo '<br>';
echo "<td><a class='link' href=\"bekijk.php?id=$row->id\">Bekijk</a></td>";
}
echo "</tr>";
}
They both link to this page:
<?php
session_start();
include '../includes/includes.php';
require('../includes/functions.php');
//make sure user is logged in, function will redirect use if not logged in
login_required();
//if logout has been clicked run the logout function which will destroy any active sessions and redirect to the login page
if(isset($_GET['logout'])){
logout();
}
?>
<html>
<title>Admin</title>
<script src="../ckeditor/ckeditor.js"></script>
<header><link rel="stylesheet" type="text/css" href="../css/style.css"></header>
<body>
<nav>
<ul>
<li>Admin</li>
<li>Bekijk site</li>
<li>Toevoegen</li>
<li>Posts</li>
<li>Uitloggen</li>
</ul>
</nav>
</body>
</html>
<?php
//pak het ID van de pagina die aangepast moet worden
$id = $_GET['id'];
$id = mysql_real_escape_string($id);
$q = mysql_query("SELECT * FROM blog_posts WHERE id='$id'");
$row = mysql_fetch_object($q);
?>
<div id="bekijkwrap">
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $row->id;?>" />
<h1><?php echo $row->title;?></h1>
<p><?php echo $row->post;?></p>
</form>
</div>
Your broken code loops through mysql_fetch_assoc(), setting your $rows variable as an (associative) array for each iteration.
Your working code calls mysql_fetch_object(), pulling back an object (of class StdClass) for each iteration.
Your broken code attempts to reference the id by treating the $row variable as if it was an object. Not only does this variable not exist (it should be $rows), but the $rows variable is an associative array, not an object.
Therefore, instead of accessing the value using the syntax $foo->id, it must be accessed like $foo['id'] instead.
To fix the problem, change:
echo "<td><a class='link' href=\"/admin/bekijk.php?id=$row->id\">Lees meer</a>
To
echo "<td><a class='link' href=\"/admin/bekijk.php?id=" . $rows['id'] . "\">Lees meer</a>
You can see in the lines above that in your original code that you're referencing $rows and treating it like an array. This is what you must do to the problem line too.
My Code -
<?php
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM employees ORDER BY id DESC") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
Echo "<img src=http://www.mywebsite.com/upload/".$info['video'] ."> <br>"; //This is the name of my Video URL in MySQL
Echo "<b>Video</b> ".$info['Video'] . "<br> "; //This is the name of my Video Name in MySQL
Echo "<b>Author</b> ".$info['Author'] . "<br> "; //This is the name of my USER in MySQL
Echo "<b>Category</b> ".$info['category'] . "<br> "; //This is the name of Video Category in MySQL
Echo "<b>Description</b> ".$info['Description'] . "<hr>"; //This is the name of Description in MySQL
}
?>
As raw output the details are coming in List like this -
Image1
Video name1
Author name1
Category1
Description1
<hr>
Image2
Video name2
Author name2
Category2
Description2
Now want to Make put <div> Tags and Tags in between the Image, Author, Video Name
How can i put ? Cuz when i edit "<br>" and insert "<div class="thumb"></div><br>"
It shows error ! - Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/servin/public_html/upload/view.php on line 14
How can i edit mysql php code so that i can add the html codes + the All details must also shows like this
you cant use double quotes by this <div class="thumb"> you should use it like that <div class='thumb'> with single quote .because you already using it with echo , try this :
<?php
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM employees ORDER BY id DESC") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
echo "<div class='thumb'><img src='http://www.mywebsite.com/upload/".$info['video'] ." ' /> </div><br>"; //This is the name of my Video URL in MySQL
echo "<div class='thumb'><b>Video</b> ".$info['Video'] . "<br /> "; //This is the name of my Video Name in MySQL
echo "<div class='thumb'><b>Author</b> ".$info['Author'] . "<br /> "; //This is the name of my USER in MySQL
echo "<div class='thumb'><b>Category</b> ".$info['category'] . "<br /> "; //This is the name of Video Category in MySQL
echo "<div class='thumb'><b>Description</b> ".$info['Description'] . "<hr>"; //This is the name of Description in MySQL
}
?>
EDIT: if you want use html here better way
<?php
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM employees ORDER BY id DESC") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
?>
<div class='thumb'><img src='http://www.mywebsite.com/upload/<?php echo $info['video']; ?> ' /> </div><br />
<div class='thumb'><b>Video</b><?php echo $info['Video'] ;?><br />
<div class='thumb'><b>Author</b><?php echo $info['Author'] ;?><br />
<div class='thumb'><b>Category</b><?php echo $info['category'] ; ?><br />
<div class='thumb'><b>Description</b><?php echo $info['Description'] ; ?><hr />
<?php } ?>