I've pretty much just started with PHP and I'm trying to make small app/script.
At the moment, the script works well for adding to the DB and viewing from the DB but I'm struggling on how to go about updating the DB.
This is the page when it lists the DB entries and works pretty much how I want it to:
Code: Select all
<?php
//Shows any errors in the script
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
include("includes/db_config.php");
include("includes/check_sql.php");
//SQL statement
$result = mysqli_query($con,"SELECT * FROM tbl_customers");
//Display results in table
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Company Name</th>
<th>Firstname</th>
<th>Lastname</th>
<th>E-mail</th>
<th>Update</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['companyname'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
?>
<td><a href="update.php?id=<?echo $row['id'];?>">Update</td>
<?
echo "</tr>";
}
echo "</table>";
?>Code: Select all
<?php
//Shows any errors in the script
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
include("includes/db_config.php");
include("includes/check_sql.php");
//Gets the ID string from the URL
$id = $_GET['id'];
//SQL statement
$result = mysqli_query($con,"SELECT * FROM tbl_customers WHERE id=$id");
//Display results in table
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Company Name</th>
<th>Firstname</th>
<th>Lastname</th>
<th>E-mail</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
?>
<form method="post" action"edit_customer.php">
<td><input name="companyname" type="text" id="companyname" value="<? echo $row['companyname'] ?>"></td>
<td><input name="firstname" type="text" id="firstname" value="<? echo $row['firstname'] ?>"></td>
<td><input name="lastname" type="text" id="lastname" value="<? echo $row['lastname'] ?>"></td>
<td><input name="email" type="text" id="email" value="<? echo $row['email'] ?>"></td>
<?
echo "</tr>";
}
echo "</table>";
?>
<input type="submit" value="Submit">
</form>Hope this makes sense and any help would be greatly appreciated.
Thanks