Paulo Soares Paulo Soares - 1 year ago 92
PHP Question

PHP form submit values don't stay put. What do?

I've been wanting to create a dynamic editing page for my website. I've been using PHP to do so, and I want to know if I'll have to integrate my MySQL DB so that the changes stay put.

This is what I've done:

first, the items I want changed:

<ul class="menu">
<div class="color">
<li><a href="?p=home"><?php echo $_POST['homepage'] ?></a></li>
<li><a href="?p=apendix"><?php echo $_POST['apendix'] ?></a></li>
<li><a href="?p=about"><?php echo $_POST['about'] ?></a></li>
<li><a href="?p=contato"><?php echo $_POST['contato'] ?></a></li>

As it can be seen, I have put the $_POST where I want the menu item names to stay.

Next is the form I have used to do so:

if (isset ($_POST['Carregar'])):
$hometitle = $_POST['homepage'];
$apendix = $_POST['apendix'];
$aboutMe = $_POST['about'];
$contact = $_POST['contato'];
<div class="section1">
<h3 style="padding-top:10px;">menu items</h3>
<form method="post" action="">
<label for=""><?php echo $_POST['homepage'] ?>:</label>
<input type="text" id="home" name="homepage">
<label for="apendice"><?php echo $_POST['apendix'] ?>:</label>
<input type="text" name="apendix">
<label for=""><?php echo $_POST['about'] ?>:</label>
<input type="text" name="about">
<label for=""><?php echo $_POST['contato'] ?>:</label>
<input type="text" name="contato">
<input type="submit" value="Carregar" name="carregar">

What happens is that the change is done, but as soon as I go to another page the change is lost, and all the said zones go blank. Can I solve this with PHP only, or will I need to involve MySQL in the deal? If so, how?

Much thanks in advance

Answer Source

For what you're trying to do, you will have to persist your data somewhere.

Judging by the behaviour you want it doesn't look like a $_SESSION var or even a $_COOKIE var will work. The $_SESSION is destroyed when your browser is closed. Even if you used a cookie, it is local to your browser. Other users will not have access to the data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download