I have a very simple webpage setup for delivering media content from a mysql database, but after my hosts upgraded my server, the site went down.
It was created many years ago so this was to be expected.
I have attempted to update my code to current standards, but I am still not getting any results from my query.
The page opens but does not return anything past the header.
I have run the code through a couple of php syntax checkers and no faults are detected.
could somebody possible suggest where I am going wrong.
I have not done any coding for 7yrs or so, so finding the fault is taking way longer than it should.
Here is the full code from my index.php
<?php
include 'header.php';
include 'welcome.php';
include 'musicDb.php';
include 'analyticstracking.php';
/* MAIN QUERY */
$query_recordset1 = "SELECT * FROM setinfo ORDER BY setid DESC";
$recordset1 = mysqli_query($query_recordset1, $musicDb) or die(mysqli_error());
$row_recordset1 = mysqli_fetch_assoc($recordset1);
$totalRows_recordset1 = mysqli_num_rows($recordset1);
?>
<tr>
<td>
<table align="center">
<!-- LOOP THROUGH RESULTS AND DISPLAY ALL RESULTS -->
<?php do { ?>
<tr CLASS="data_left" >
<td><a href="<?php echo $row_recordset1['id'];?>.php"><img width="200" HEIGHT="200" src="<?php echo $row_recordset1['artwork']; ?>" /></td>
<td>
<table>
<tr><td><a href="player.php?TargetSet=<?php echo $row_recordset1['setid'];?>"><?php echo $row_recordset1['setname'];?></td></tr>
<tr><td><?php echo $row_recordset1['dj'] ; ?> </td></tr>
<tr><td><?php echo $row_recordset1['bpm'] ; ?>bpm <?php echo $row_recordset1['genre'] ; ?> (<?php echo $row_recordset1['era'] ;?>) </td></tr>
<tr><td><?php echo $row_recordset1['length'] ; ?> </td></tr>
<tr><td><?php echo $row_recordset1['date'] ; ?> </td></tr>
</table>
</td>
</tr>
<tr height="50" ><td colspan="4"><img src="images/lineindex.png" /></td></tr>
<tr height="50" ></tr>
<!-- END LOOP -->
<?php } while ($row_recordset1 = mysqli_fetch_assoc($recordset1)); ?>
</table>
<!-- LINK TO FOOTER -->
<?php include 'footer.php'; ?>
I also created a test file to check my raw query is still working, and it does retrun the data.
<?php
// Create connection
$conn = new mysqli("*****", "*****", "*****", "*****");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM setinfo ORDER BY setid DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo
" " . $row["artwork"].
" " . $row["setid"].
" " . $row["dj"].
" " . $row["setname"].
": " . $row["bpm"].
": " . $row["length"].
": " . $row["date"].
": " . $row["file"].
": " . $row["filesize"].
"<br><br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
I'm trying to put two table record into one PHP, but it only views one of the records when including both PHP file?
another file when echo will become an undefined index.
Main.php
<?php
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($row = $result->fetch_assoc()){
echo "
<tr>
<td>{$row['Fullname']}</td>}}
<td>{$row['LocationFrom']}</td>
<td>{$row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
Location.php
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
Fullname.php
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
$result = mysqli_query($conn,$sql);
mysqli_close($conn);
}
?>
Why it comes out the data only one table?? When have include "FullName.php" and included "Location.php", it only displays fullname.php data only.
Picture with only one record
It is only showing one table because you are overridding the value.
for example, This is what you are doing
file1.php
a = 3
file2.php
a = 4
So when you include both files. file2.php will override the value of file1.php
so what you need to do is set file2.php's a variable to a different name. So ...
b = 4
And now you will have both values 3 and 4 just in different variables.
In your case just do this
Main.php
<?php
result = []
include"Location.php";
include"Fullname.php";
?>
<html>
<head>
<table id ="table">
<tr>
<th>Customer Name</th>
<th>Location From</th>
<th>Location To</th>
<th>Departure Date</th>
<th>Return Date</th>
<th>Travel</th>
</tr>
<?php
if(isset($result ) && !empty($result )){
while($location_row = $result[0]->fetch_assoc() and $fullname_row = $result[1]->fetch_assoc()){
echo "
<tr>
<td>{$fullname_row['Fullname']}</td>}}
<td>{$location_row['LocationFrom']}</td>
<td>{$location_row['LocationTo']}</td>
</tr>\n";
}
}
?>
</table>
</body>
</html>
Location.php
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT * FROM booking";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
Fullname.php
<?php
$user=filter_input(INPUT_POST,'user');
$fn=filter_input(INPUT_POST,'fn');
$email=filter_input(INPUT_POST,'email');
$ps=filter_input(INPUT_POST,'ps');
$rps=filter_input(INPUT_POST,'rps');
$from=filter_input(INPUT_POST,'from');
$to=filter_input(INPUT_POST,'to');
$departure=filter_input(INPUT_POST,'departure');
$return=filter_input(INPUT_POST,'return');
$flight=filter_input(INPUT_POST,'flight');
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="register";
$conn=new mysqli($servername,$dbusername,$dbpassword,$dbname);
if(mysqli_connect_errno()){
die('Connection Error('. mysqli_connect_errno() .')'. mysqli_connect_error());
}
else{
$sql = "SELECT Fullname FROM useraccount";
array_push($result, mysqli_query($conn,$sql));
mysqli_close($conn);
}
?>
Basically I fixed the second problem by looping through the rows of both location and full name at the same time. So every row in full name database is associated with the row in location that has the same index. It is a bad way to structure you database, but I assume you are new so it works for your needs
So I made my first database online. I used phpmyadmin, I created the table and the user.
Now I'd like to show the table on a page of my site, as well as giving the possibility to people to edit the database from the site.
My problem is that the database does not work: it doesn't connect. I have no idea what to do.
My database is called letstenf_santi and my table passeggeri.
This is the code I'm trying to use to show the table on the site.
<?php
//establishing connection
mysql_connect('localhost', 'root', '');
//selecting a database
mysql_select_db('letstenf_santi');
$sql = 'SELECT * FROM `letstenf_santi`.`passeggeri`';
$records=mysql_query($sql);
?>
<html>
<head>
<title>mostra</title>
</head>
<body>
<table width="300" border="1" cellpadding="10" cellspacing="1">
<tr>
<th>id pass</th>
<th>nome</th>
<th>eta</th>
<th>sesso</th>
</tr>
<?php
while($pass=mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$pass['idpasseggero']."</td>";
echo "<td>".$pass['nome']."</td>";
echo "<td>".$pass['eta']."</td>";
echo "<td>".$pass['sesso']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
instead of this,
mysql_connect('localhost', 'root', '');
mysql_select_db('letstenf_santi');
you can try this,
$connection=mysql_connect('localhost', 'root', '');
$db=mysql_select_db('letstenf_santi',$connection);
try this code
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "letstenf_santi";//your db name
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM tablename";//replace table name with your table name
$result = mysqli_query($conn, $sql); ?>
<html>
<head>
<title>mostra</title>
</head>
<body>
<table width="300" border="1" cellpadding="10" cellspacing="1">
<tr>
<th>id pass</th>
<th>nome</th>
<th>eta</th>
<th>sesso</th>
</tr>
<?php if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['idpasseggero']."</td>";
echo "<td>".$row['nome']."</td>";
echo "<td>".$row['eta']."</td>";
echo "<td>".$row['sesso']."</td>";
echo "</tr>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
</table>
</body>
</html>
I want to get data from my sql database into a table with html.
I have writed 1st part of code ended with ?>
and started with html table and end with html
My code getting only Empty table without getting data from my Database, here the Code, i dont know how to get data with that
<td>
<?php echo $result['nazwiskoimie'] ?>
</td>
Here's the full code :
<?php
$con=mysqli_connect("localhost","root","","listap");
if (mysqli_connect_errno()) {
echo "Blad przy polaczeniu z baza: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM 'lista'");
?>
<html>
<table border='1'>
<tr>
</tr>
<tr>
<td> <?php echo $result['nazwiskoimie'] ?> </td>
//in this part have problem to get my data from database
</html>
Here's also a screenshot of a result: Final After a Save my file
Please try this:
$result = mysqli_query($con,"SELECT * FROM lista");;
?>
<html>
<table border='1'>
<?php
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $row['nazwiskoimie']?></td>
</tr>
<?php
}
} ?>
</table>
</html>
New to this but loving it. I have a database of URLs of pictures of cats that I want to display in a webpage. I wrote some php to do this but all I'm seeing it the URL of the image and not the image itself. Here is my full code:
<html>
<body>
<h1>Katz!!</h1>
<!--Connect to Database-->
<?php
$db_host = "localhost";
$db_username = "Alex";
$db_pass = "";
$db_name = "cats";
#mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mySQL");
#mysql_select_db("$db_name") or die ("No database");
$sql="SELECT * FROM cats_test";
$records = mysql_query($sql);
?>
<!--Populate table from database-->
<table border="2" cellpadding="1" cellspacing="1">
<tr>
<th>cat table</th>
</tr>
<?php
while($cats_test=mysql_fetch_assoc($records)) {
echo "<tr>";
echo "<td>".$cats_test['image']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
As you can see, the database name is "cats" with a table called "cats_test" that holds all of the images in a column called "image" you can find a screenshot of that here
You can also see the URLs being displayed instead of images here
I've probably done something really stupid, so would appreciate any help you guys might have!!
Replace your :
echo "<td>".$cats_test['image']."</td>";
With :
echo "<td><img src='".$cats_test['image']."' ></td>";