Had this all working with html. Then I tried making it into html5 and I'm coding some of my first css code. The only thing I'm tackling right now is why isn't my image showing?? I'm using google chrome btw. The code passed in the url is this: "?fname=raichu&yesorno=true%2F" And there is no image tag in my generated html :/ I'm assuming that the if statement is equating to false??
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
td{
text-align: center;
padding:15px;
background-color:black;
color:#00FF00;}
th{
background-color:black;
color:yellow}
</style>
<title>Search Results</title>
</head>
<body style="color:#FFFFFF">
<?php
$dbhost = 'server';
$dbname = 'database1';
$dbuser = 'me';
$dbpass = 'password';
$link = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
mysqli_select_db($link,$dbname);
$naame = $_GET["fname"];
if( $_GET["yesorno"] == 'true' OR !$_GET["yesorno"])
{$query = sprintf("SELECT image_url, Type
FROM Pokemon c
WHERE c.name='%s'", mysqli_real_escape_string($link,$naame));
$result = mysqli_fetch_assoc(mysqli_query($link,$query));
echo '<img height="450" width="330" src="'.$result['image_url'].'" alt="blue"/>';}
$res = mysqli_query($link,"SELECT Name,HP,Type,Pokedex_Number AS 'Pokedex Number',Weakness,Resistance,Retreat AS 'Retreat Cost'
FROM Pokemon
WHERE Pokedex_Number!=0 AND name='$naame'");
if (!$res) {
die("Query to show fields from table failed");}
$fields_num = mysqli_num_fields($res);
echo "<h1>Stats</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{$field = mysqli_fetch_field($res);
echo "<th>{$field->name}</th>";}
echo "</tr>\n";
// printing table rows
while($row = mysqli_fetch_row($res))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
echo "</table>";
mysqli_close($link);
?>
<br />
<form method="link"
action = "http://engr.oregonstate.edu/~bainro/welcome.php" ><input
type="submit" value="(>O.O)>RETURN<(O.O<)"></form>
<p></p>
</body>
</html>
You have
&yesorno=true%2F
therefore $_GET['yesorno'] will equate to 'true/' as %2f is a forward slash.
This doesn't match
if( $_GET["yesorno"] == 'true' OR !$_GET["yesorno"])
So you're correct - that line is failed so you won't get the image.
Solution: remove the %2F from the query.
The variable you are retrieving from the url, is never evaluating to true because '%2F' is a forward slash. Check your code.
Related
I have made a database and connected it properly. I am trying to display the database contents to be side by side. I have tried to create a div but everything is jumbled up. The items are floating left but are not showing up side by side.
<html>
<head>
<style>
.menu{
float:left;
}
p{
text-align:left;
float:left;
inline-size:300px;
overflow:hidden;
}
</style>
</head>
<body>
<main>
<section>
<h3>Inventory</h3>
<?php include 'db.php';
$ID = $_GET['ID'];
$query = "SELECT * FROM inventory ORDER BY ID";
/* Try to query the database */
if ($result = $mysqli->query($query)) {
// Don't do anything if successful
}
else
{
echo "Sorry, an item with the ID of $ID cannot be found " . mysql_error()."<br>";
}
while ($result_ar = mysqli_fetch_assoc($result)) {
//Display food image and image source
$image = $result_ar['Image'];
echo "<div class = 'menu'>" . $result_ar['Image_Source'] . "<br>".
"<IMG src= 'images/$image' style = height:200px; width:300px;>". "</div>";
//Display name and description
echo "<p>".$result_ar['Name'] . "<br>"
. $result_ar['Description'] ."</p>";
}
$mysqli->close();
?>
</section>
</main>
</body>
</html>
How to send data from a dynamic php table inside an anchor tag to another page(description_of_gpu.php) and also how to retrieve that data on the new page.
I am trying to send the variable generated inside the table-data tag to another page,
which is in itself retrieved from "MySQL" database.
Once I get that data, I will search through my database with the same "NameOfVcard" and
display it's discription.
Code inside "gpu_table_page.php"
<?php
$conn = mysqli_Connect('localhost', 'root', '', 'gpu_db');
//$result = mysqli_query($conn,"select * from gpu_table");
?>
<!DOCTYPE html>
<html>
<head>
<title>gpu page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="css/style_of_gpu.css" type="text/css">
<script type="text/javascript" src="javascript/javascript_of_gpu.js"></script>
</head>
<body>
<br />
<br/>
<div style="margin-left: 150px; margin-right: 20px; vertical-align: right">
<table style="margin-top: 40px" border="3px">
<thead>
<tr>
<th>SrNo</th>
<th>Video card Name</th>
<th>Architecture</th>
<th>Boost_clock</th>
<th>Core_speed</th>
<th>Memory</th>
<th>Manufacturer</th>
</tr>
</thead>
<tbody>
<?php
$data = 1000;
$sql = "SELECT * FROM gpu_table WHERE Core_Speed<? ORDER BY Core_Speed DESC;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
echo "SQL statement failed";
}
else{
mysqli_stmt_bind_param($stmt,"i",$data);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$k = 1;
while ($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$k."</td>";
echo "<td>".$row['Name']."</td>";;
echo "<td>".$row['Architecture']."</td>";
echo "<td>".$row['Boost_Clock']."</td>";
echo "<td>".$row['Core_Speed']."</td>";
echo "<td>".$row['Memory']."</td>";
echo "<td>".$row['Manufacturer']."</td>";
echo "</tr>";
$k = $k + 1;
}//while end
}//else end
?>
</tbody>
</table>
</div>
<br />
</body>
</html>
Code inside "description_of_gpu.php"
<?php
$conn = mysqli_Connect('localhost', 'root', '', 'gpu_db');
//$result = mysqli_query($conn,"select * from gpu_table");
?>
<!DOCTYPE html>
<html>
<head>
<title>gpu page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="css/style_of_gpu.css" type="text/css">
<script type="text/javascript" src="javascript/javascript_of_gpu.js"></script>
</head>
<body>
<br />
<br/>
<?php
//the below "$data" variable will contain the "NameOfVcard" data.
$data = "GeForce GTX 1080 Ti Zotac Founders Edition 11GB";//currently "$data" is a static variable
$sql = "SELECT * FROM gpu_table WHERE Name=?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
echo "SQL statement failed";
}
else{
mysqli_stmt_bind_param($stmt,"s",$data);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$k = 1;
while ($row = mysqli_fetch_array($result))
{
echo "<p>";
echo "<em>".$row['Name']."</em>"." is from the architecture "."<b>".$row['Architecture']."</b>"."where Boost_Clock is "."<b>".$row['Boost_Clock']."</b>"."Mhz and Core_Speed is ".$row['Core_Speed']."Mhz having ".$row['Memory']."mb of DRAM which is of the type ".$row['Memory_Type']." and have ".$row['DVI_Connection']." DVI connections";
echo "<br>";
echo "also having ".$row['HDMI_Connection']." HDMI ports which is Manufactured by ".$row['Manufacturer']." consuming ".$row['Max_Power']." power and it has ".$row['Power_Connector']." power connectors ";
echo "</p>";
$k = $k + 1;
}//while end
}//else end
?>
</div>
<br />
</body>
</html>
As the PHP is using double-quotes around the strings you can embed the variable within this string without needing to escape it so you can modify
echo "<tr>";
echo "<td>".$k."</td>";
echo "<td>".$row['Name']."</td>";;
echo "<td>".$row['Architecture']."</td>";
echo "<td>".$row['Boost_Clock']."</td>";
echo "<td>".$row['Core_Speed']."</td>";
echo "<td>".$row['Memory']."</td>";
echo "<td>".$row['Manufacturer']."</td>";
echo "</tr>";
to be more like this
echo "
<tr>
<td>{$k}</td>
<td><a href='description_of_gpu.php?NameOfVcard={$row['Name']}'>{$row['Name']}</a></td>
<td>{$row['Architecture']}</td>
<td>{$row['Boost_Clock']}</td>
<td>{$row['Core_Speed']}</td>
<td>{$row['Memory']}</td>
<td>{$row['Manufacturer']}</td>
</tr>";
Then, within description_of_gpu.php you should be able to access the GET variable NameOfVcard, like so:
$NameOfVcard=isset( $_GET['NameOfVcard'] ) ? $_GET['NameOfVcard'] : false;
leading on to
$sql = "SELECT * FROM gpu_table WHERE Name=?;";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt,$sql);
mysqli_stmt_bind_param($stmt,"s",$NameOfVcard);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
I have the following php code, which gathers data from a database, and displays it in a table. It works fine when used in chrome, But is not working properly, i.e, the border, rows etc.. are not being displayed, like the table tag itself is being disregarded. Here is the code, I have.
<html>
<head>
<title> Reviews List. </title>
</head>
<body>
<?php
include 'settings.php';
if (!isset($dbc)){
$dbc = new mysqli(DB_HOST , DB_USER , DB_PASSWORD , DB_NAME) or die("Cannot connect to the database.");
}
$query = "SELECT * FROM reviews";
$result = $dbc->query($query) or die ("Cannot query");
?>
<table id="review_table" border="1" width="1">
<?php
while ($row = mysqli_fetch_assoc($result)){
echo '<tr>';
echo '<td>';
echo $row['id'];
echo '</td>';
echo '<td>';
echo $row['pid'];
echo '</td>';
echo '<td>';
echo $row['publish'];
echo '</td>';
echo '</tr>';
}
?>
</table>
</body>
Here are the screen shots of the page viewed in safari and in chrome.
Safari:
I did try to click on the toggle formatting button, which did nothing.
Chrome:
Remove border and width from table tag and add this css instead.
#review_table {
border: 1px solid #000;
border-collapse: collapse;
}
#review_table td {
border: 1px solid #000;
}
You are missing the <tbody> tag
I don't understand why this isn't working, I have been stuck on this for ages and tried lots of different alternatives, but it just doesn't print the data from the database.
At the moment I am just trying to get the id to print, but eventually I want to print most of the data in the database (not including the hash).
Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>Staroids Leaderboard</title>
</head>
<body>
<table border=1px>
<thead>
<tr>
<td>name</td>
<td>score</td>
</tr>
</thead>
<tbody>
<?php
$connect = mysql_connect("localhost","root", "password");
if (!$connect) {
die(mysql_error());
}
mysql_select_db("staroids");
$results = mysql_query("SELECT id FROM scores");
while($row = mysql_fetch_array($results)) {
$name = $row['id']
?>
<tr>
<td><?php echo '$name'?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>
The image below shows what it looks like in html:
This image shows the database in local host and as you can see there is lots of data, but none of the names seem to print?!
Correct your syntax where it could be
$name = $row['id']; //Put ; here
<?php echo $name;?> //Remove quotes and put ;
Select name from DB and you can get name then.It should be
$results = mysql_query("SELECT id,name FROM scores");
while($row = mysql_fetch_array($results)) {
$name = $row['name'];
?>
<td><?php echo $name;?></td>
And dont use mysql_* functions due to they are deprecated.Instead use mysqli_* functions or PDO statements.
And as #Nedstark said use try die(mysql_error()); for the errors regarding the mysql errors.
<td><?php echo $name;?></td>
or use
<td><?php echo "$name";?></td> <!--(Bad idea but works)->
Variables work in double quotes("") not in single quotes('')
<?php
session_start();
if (!(isset($_SESSION['UserName'])))
{
echo "<script type=\"text/javascript\">alert('Unauthorize user are redirected to Login page');".
header('Location:http://localhost/campus');
}
include_once "connect.php";
$find = mysql_query("YOUR SELECT STATEMENT ") or die('error');
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ST. MICHAEL's COLLEGE ILIGAN CITY</title>
<style>
AlignJst {
text-align:justify;
text-justify:inter-word;
}
pTable {
margin:2cm 4cm 3cm 4cm;
}
body {color: black; font-size: 10px; font-family: Helvetica, Arial, non-serif;}
a:link {color: #FF8C00;}
a:visited {color: #FF8C00;}
a:hover {color: #FF8C00; background: #ADD8E6; text-decoration:none;}
a:active {color: #FF0000;}
p {line-height: 2em;
font-size:85%;
color:black;
letter-spacing: 0.3em
}
h1 {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12pt;
color: navy;
padding-top: 12px;
padding-bottom: 3px;
}
</style>
</head>
<body>
<?php
echo "<CENTER>"."<H1>TABLE TITLE</H>" . "<BR />";
echo "<H1>SUBTITLE</H>"."</CENTER>"."<BR/>";
echo "<CENTER>"."<p>"."<b>" . "PAST MORNING PRAYER SCHEDULE" ."</b>"."</p>"."</CENTER>"."<BR/>";
echo "<table border='1' width='100%' align ='center'>";
echo "<tr>";
echo "<th>SPONSOR NAME</th>";
echo "<th>VENUE </th>";
echo "<th>DATE EVENT</th>";
echo "<th>TIME </th>";
while($row = mysql_fetch_array($find)){
echo "<tr>";
echo "<td>".$row['sponsor_name']."</td>";
echo "<td>".$row['Venue']."</td>";
echo "<td>".$row['Date_Event']."</td>";
echo "<td>".$row['Time_Event']."</td>";
echo "</tr>";
}
echo "</table>";
echo "<br />". "<br />" ."<br />";
echo "<p align = 'right'>"."Prepared By:" . $_SESSION['UserName'] ."</p>";
?>
</body>
Other than changing mysql ==> msqli, I'd recommend a couple of debug strategies, in this case I would:
fix the echo, you need to pick one of those two options:
<?php echo $variable; ?>
<?php echo "this is my variable {$variable}"; ?>
If you put a single quote PHP don't parse the content of what is about to print, it just print it as text, so what you have should print $name in the HTML...but, since I don't see any $name text in the black screenshot I think you might even not get into that loop...
a good debug strategy would be to query for something broader, i.e. "SELECT * FROM `scores`", then you can do a
<?php print_r($row); ?>
right after while ($row = mysql_fetch_array($results)) {
Current Grid View structure with View Anchor - I want to view a specific row after clicking on View anchor, data should be displayed in popup - javascript
Below is my code. I have already implemented functionality for PHP Grid View, Delete option is implemented at the top with querystring
Now what i want is, After clicking view, it should display javascript popup with all the details of that specific row, and close option
The part which am not getting is
how to transfer data from php/mysql to javaScript and display it in popup
`
if(isset($_GET['id'])){
$id = $_GET['id'];
//$x = 'confirm("Are you sure you want to delete this product")';
//echo $x;
mysql_query("DELETE FROM users WHERE id = '$id'");
//echo "alert('Row Deletion Successful')";
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Table Display</title>
<style>
table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<?php $result = mysql_query("SELECT id, CONCAT(title, ' ', name) as FullName, email, mobile FROM users") or die(mysql_error());
$row_count = 1;
$row = mysql_fetch_assoc($result);
echo '<td><input type="checkbox" /></td>';
echo "<th> Sr. No </th>";
foreach($row as $col=>$value)
{
echo "<th>";
echo $col;
echo "</th>";
}
?>
<th>EDIT</th>
</tr>
</thead>
<tbody>
<?php
mysql_data_seek($result, 0);
while($row = mysql_fetch_assoc($result)){
echo "<tr>";
echo '<td><input type="checkbox" /></td>';
echo "<td>" . $row_count ."</td>";
foreach($row as $key=>$value)
{
echo "<td>";
echo $row[$key];
echo "</td>";
}
$row_count++;
?>
<td>
VIEW |
DELETE |
EDIT
</td>
<?php
echo "</tr>";
}
echo "</table>";
?>
</tbody>
</table>
</body>
</html>`
you can use this code to display in your records in popup window
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>your code to display in table format</p>");
myWindow.focus();
}
<a onclick="openWin();">Edit/Delete/View(any one)</a>
try this out in document.write() method enter your code inside a table tag
render specific view in a page (e.g. viewpageaddress.php?id=7)
and then get it's content in js by:
$.get('viewpageaddress.php?id=7', function(cnt){/* show cnt in your popup */})