Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, in order to make it dynamic you need a way to store these values: $title, $desc somewhere. The most common way while working with PHP would be to store them in a database.</p> <p>Your frontend (provided by you above) would therefore retrieve values $title and $desc from the database, while you backend would allow you to edit these values, and hence update the records saved in your database.</p> <p>You have not provided any information about any storage you are currently using, so I will just randomly select MySQL as a database, and provide an example with it.</p> <p>This is how you will get your values from the database : </p> <pre><code>&lt;?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('SELECT title,descripton FROM database.database WHERE id=1'); if (!$result) { die('Invalid query: ' . mysql_error()); } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { $title = $row["title"]; $desc = $row["desc"]; } mysql_close($link); ?&gt; </code></pre> <p>This is how you will write your values to the database :</p> <p>//form receiver <pre><code>$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database" ,$link); $sql = "INSERT INTO database.database (title, descripton) VALUES (" . $_POST['$title'] . "," . $_POST['$description'] . ")"; mysql_query($sql); ?&gt; </code></pre> <p>//backend <pre><code>$result = mysql_query('SELECT title,descripton FROM database.database WHERE id=1'); if (!$result) { die('Invalid query: ' . mysql_error()); } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { $title = $row["title"]; $desc = $row["desc"]; } mysql_close($link); ?&gt; &lt;form action="php-form-processor.php" method="post"&gt; &lt;input type="text" name="title" maxlength="50" value="&lt;?=$title;?&gt;" /&gt; &lt;input type="text" name="description" maxlength="50" value="&lt;?=$description;?&gt;" /&gt; &lt;input type="submit" name="formSubmit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>You will need both a webform to gather the values, and PHP code that will write it to the database, while it is common to actually do this using AJAX, I will provide an example which redirects to a php page to submit values, as easier to understand example :)</p> <p>You probably will end up with 3 files. 1 backend, 1 fronted, and 1 to process the form into the database. In order to create the database I used in my example you will need to run a database query :</p> <pre><code>CREATE SCHEMA `database` DEFAULT CHARACTER SET latin1 ; CREATE TABLE `calendar`.`database` ( `id` INT NOT NULL AUTO_INCREMENT , `title` VARCHAR(225) NOT NULL , `description` TEXT NOT NULL , PRIMARY KEY (`id`) ); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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