Note that there are some explanatory texts on larger screens.

plurals
  1. POForm submitting to a OO-PHP Crud
    text
    copied!<p>Trying to make a CRUD class in PHP. I'm basically trying to stick with making everything I do OO. My question is, how do I submit my form values to the class itself, I have a standard form that's just outputting to this file name . </p> <p>However, I need it to refer to the right class... Cheers in advance for the help!</p> <pre><code>&lt;?php require('connection/connection.php'); class Crud{ public function __construct(){ $v_title = $_POST['v_id']; $v_title = $_POST['v_title']; $v_features = $_POST['v_features']; $yt_id = $_POST['yt_id']; $v_subject = $_POST['v_subject']; $taname = "videohubapp"; echo $v_title; } protected static function Create($v_id, $v_title, $v_features, $yt_id, $v_subject){ #Creates entries $query = $conn-&gt;prepare("INSERT INTO $taname (v_title, v_features, yt_id, v_subject) VALUES (:v_title, :v_features, yt_id, v_subject)"); $query-&gt;bindParam(":v_title", $v_title); $query-&gt;bindParam(":v_features", $v_features); $query-&gt;bindParam(":yt_id", $yt_id); $query-&gt;bindParam(":v_subject", $v_subject); $query-&gt;execute(); } public static function Read($v_id, $v_title, $v_features, $yt_id, $v_subject){ #Reads database entries $query = $conn-&gt;prepare("SELECT * FROM $taname ORDER BY v_id"); $query-&gt;setFetchMode(PDO::FETCH_ASSOC); while($row = $conn-&gt;fetch()) { echo $row['v_id'] . "\n"; echo $row['v_title'] . "\n"; echo $row['v_features'] . "\n"; echo $row['yt_id'] . "\n"; echo $row['v_subject'] . "\n"; } } protected static function Update($v_id, $v_title, $v_features, $yt_id, $v_subject){ #Updates database entries $query = $conn-&gt;prepare("UPDATE $taname SET (v_title = :v_title, v_features = :v_features, yt_id = :yt_id, v_subject = :v_subject) WHERE v_id = :v_id"); $query-&gt;bindParam(":v_id", $v_id); $query-&gt;bindParam(":v_title", $v_title); $query-&gt;bindParam(":v_features", $v_features); $query-&gt;bindParam(":yt_id", $yt_id); $query-&gt;bindParam(":v_subject", $v_subject); $query-&gt;execute(); } protected static function Delete($v_id, $v_title, $v_features, $yt_id, $v_subject){ #Delete entries from the database $query = $conn-&gt;prepare("DELETE FROM $taname WHERE v_id = :v_id"); $query-&gt;bindParam(":v_id", $v_id); $query-&gt;execute(); } public static function XMLWebService(){ #XMLParse $query = $conn-&gt;prepare("SELECT * FROM $taname"); $query-&gt;execute(); } } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload