So yes I freely admit that I am a total noob when it comes to doing web dev beyond basic html code. So hopefully everyone can help, here is my problem:
I am trying to create a page where I display the last record in a certain database so that I can update it with more information after the record has been created. (The displayed information is just so that I update the correct record.) I keep getting the same error message when loading the site:
PHP Fatal error: Uncaught Error: Call to a member function query() on null in /home/****/public_html/ins/end/index.php:32 Stack trace:
0 {main}
thrown in /home/****/public_html/ins/end/index.php on line 32
Here is my conumdrum: I used the same code to pull the information from the database on a seperate page, in which it worked just as expected. All I did is copy and paste that portion of the code from that page into the one that I am now working on. I just update the database name etc. Am I missing something? The Code from the complete page is:
<html>
<title>Jake's Instacart Info: Add a New Batch</title>
<header>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<h1 align="center">Step 1: Updating a batch</h1>
</header>
<style>
table, th, td {
padding: 10px;
border: 2px solid black;
border-collapse: collapse;
}
p {
font-size:x-large;
}
</style>
<body>
<?php
$servername = "localhost";
$username = "******";
$password = "******";
$dbname = "******";
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully <br><br>" ;
$query = "SELECT * FROM `batch` WHERE 1";
if ($result = $conn->query($query)) {
while ($row = $result->fetch_assoc()) {
$field1name = $row["id"];
$field2name = $row["batch"];
$field3name = $row["date"];
echo '<b>Last entry information:</b> <br><br>';
echo '<b>Record ID: '.$field1name.'</b><br />';
echo '<b>Date: '.$field3name.'</b><br>';
echo '<b>Batch Code: '.$field2name.'</b><br>';
}
/*freeresultset*/
$result->free();
}
?>
<center>
<form action="ins1.php" method="post">
<table>
<tr>
<th>
<p>Batch Date Code:</p>
</th>
<td>
<input type="NUMBER" name="code">
</td>
</tr>
<tr>
<th>
<p>Date:</p>
</th>
<td>
<input type="DATE" name="date">
</td>
</tr>
<tr>
<th>
<p>Store:</p>
</th>
<td>
<p>
<select name="store">
<option>Fred Myers Nampa</option>
<option>CostCo Nampa</option>
<option>Albertsons 415 Caldwell</option>
<option>Albertsons 2500 Caldwell</option>
</select>
</p>
</td>
</tr>
<tr>
<th>
<p>Estimated IC Payment:</p>
</th>
<td>
<input type="number" min="1" step="any" name="esicpay"/>
</td>
</tr>
<tr>
<th>
Estimated Tip:
</th>
<td>
<input type="number" min="1" step="any" name="estippay"/>
</td>
</tr>
<tr>
<th>
Beginning Mileage Reading:
</th>
<td>
<input type="number" min="1" step="any" name="begmile"/>
</td>
</tr>
<tr>
<th>
</th>
<td>
<input type="submit" value="Next">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Please tell me is something simple...hehehe The bottom of the code hasnt been update for the new page as it is also copied and pasted into the new file. Thank you for any advice. Trying to learn off the web is a nightmare...