Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I am not getting any errors but when I run my code it doesn't pull anything from the server. It is just blank. I feel like there must be something really obvious I'm missing. 


What I have tried:

<?php
if(isset($_GET['id'])) {
	require_once  'login1.php';

	$id = null; 
	
	$conn = new mysqli($hn, $un, $pw, $db); 
	if($conn->connect_error) die($conn->connect_error); 
	$ID = mysqli_real_escape_string($conn, $_GET['id']);
	
	$sql = "SELECT * FROM freshwater WHERE id='$id' ";
	$result = mysqli_query($conn, $sql) or die("Bad Query: $sql");
	$row = mysqli_fetch_array($result);
	
}
	else {
		header('Location: freshwaterlist.php');
	}
?>
<html>
<head>
<title>Fish R Us - Saltwater Fish</title>
</head>
<body>
<div class="toptext"><center>
<img src="banner.png" height="300"></img></center>
</div>
<center>
<h2><?php echo $row["name"] ?></h2>

<img src="<?php echo $row["picture"] ?>"></img>
<table>
  <tr>
    <th>Name</th>
    <th>Type</th>
    <th>Quantity</th>
	<th>Price</th>
  </tr>
  <tr>
    <td><?php echo $row["name"] ?></td>
    <td><?php echo $row["type"] ?></td>
    <td><?php echo $row["qty"] ?></td>
	<td><?php echo $row["price"] ?></td>
  </tr>
</table><br>
<table class="fish-text">
<th><?php echo $row["description"] ?></th>
</center></table><br>
<button padding: 10px 24px;><a href="products.php">Return to Products List</a></button></body>
<button padding: 10px 24px;><a href="menu.php">Return to Menu</a></button>
</html>
Posted
Updated 19-Apr-19 10:05am

I think the variable name in PHP is case sensitive, in the posted code, there are two id variables with different case

PHP
$id = null; 
$ID = mysqli_real_escape_string($conn, $_GET['id']);


The first one ($id) was being assigned a null value and being used in the query, which I think it should be $ID
PHP
$sql = "SELECT * FROM freshwater WHERE id='$id' ";


And the code might be vulnerable to SQL injection and XSS attacks.
PHP MySQLi Prepared Statements Tutorial to Prevent SQL Injection[^]

Example of SQL Injection and Cross site Scripting (XSS) attacks:
SQL Injection and Cross-Site Scripting[^]
 
Share this answer
 
v2
Quote:
I am not getting any errors but when I run my code it doesn't pull anything from the server.

Advice: use the debugger to see exactly what your code is doing.
PHP
$sql = "SELECT * FROM freshwater WHERE id='$id' ";

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900