I know there are several similar questions like mine. But I've gone through most of them but found only similar answers that don't solve my situation:
I am creating a PHP website using OOP and wish to edit a record from the database. Here is the link to edit_short.php
:
<td><a href="edit_short.php?id=<?php echo $short->id; ?>">Edit</a></td>
This record id is received in edit_short.php
as follows:
<?php
require_once("short.php");
$id = null;
// $short = new stdClass(); **I was told to use this but it didn't work**
if (isset($_GET['id'])) {
$id=$_GET['id'];
$short = Short::find_by_id($id);
}
if (isset($_POST['edit_short_btn'])) {
$short->title = $_POST['title']; //the error is on this line
$short->short_text = $_POST['short_text'];
}
Here is my the relevant section of my Short
class:
public static function find_by_id($id=0) {
global $database;
$result_array = self::find_by_sql("SELECT * FROM short WHERE id=$id LIMIT 1");
return !empty($result_array) ? array_shift($result_array) : false;
}
Some answers on stackoverflow and other websites i was told to define $short
as an object of the stdClass()
but that doesn't apply here since $short
object in my case must be of the Short
class.
Thanks you very much for any help..