0

So I am changing a php application for my company. I understand the basics and have been fine changing on my own until now. Basically the program has an admin side and a user side. A database is already set up that stores user information and I can add users/edit. What I want to do is have on the admin side a little script to select "available" or not available with a radio button, then on the user side it would echo a different image for "available" or "not available". Would this work or do I have to store the check boxed value in the database so it will keep the value?

Admin

<form name="f1" method="POST" action="SAVE TO DATABASE??">
 <input class="no-check-border-win" type="checkbox" name="Availability" value="y"     />Available<br/> 
 <input type="submit"/>
</form>

User

    if((isset($_POST['Availability'])) && ($_POST['Availability'] == 'y'))
{
echo '<img src="http://mysite/image1.png" border=0>';
}
else
{
echo '<img src="http://mysite/image2.png" border=0>'
}
3
  • 3
    you have missed ; after second echo Commented Aug 29, 2013 at 23:24
  • It sounds like you'll need to store the value for later use, either in a database or otherwise. $_POST data is only available to the browser that submitted the form and will not be available on the "user side". Commented Aug 29, 2013 at 23:24
  • You'll probably want to store that in the database, otherwise you won't be able to pull it up for the user. Or you can store it in a file, but that runs the risk of someone being able to edit it if you don't lock up the file correctly. Commented Aug 29, 2013 at 23:25

3 Answers 3

1

You must store the value in database.

To do it you must do:

  1. Connect to Database

    $mysql = mysqli_connect('localhost','username','password');

  2. Select the database

    mysqli_select_db("databasename",$mysql);

  3. Store the value onto a table (let's assume that you created one table called settings) mysqli_query("INSERT INTO settings (name,value) VALUES ('active','1') ON DUPLICATE KEY UPDATE value='1' ",$mysql);

Now the value is stored in the database.

To get it you must do as following:

  1. Connect to Database

    $mysql = mysqli_connect('localhost','username','password');

  2. Select the database

    mysqli_select_db("databasename",$mysql);

  3. Retreive value from table settings

    $res = mysqli_query("SELECT value FROM settings WHERE name='available'",$mysql);

    $row = mysqli_fetch_array($res);

    $value = $row['value'];

    Now $value will contain the value you stored in db (in this case will contain 1)

Sign up to request clarification or add additional context in comments.

1 Comment

Shame on you for using mysql. The MySQL Extension is depreciated. Look into the MySQLi Extension or PDO Extension.
0

You need to store the value somewhere. It can be a file to. or you can swap out the image, and force your clients to reload it on every pageload. But the db solution is the better one.

Comments

0

$_POST is data sent to the sever, but only usable by whoever $_POSTed it. Ie when you click the form, the data is sent to whatever action="" is set, another file, same file, whatever, but it's not saved anywhere after that and so you cannot access it later to serve it to your users.

You would need to store your settings somewhere, and a database is ideal for this.
Then your admin area is managing your users and saving the settings you make for them in a DB. When they login/view pages the script being served to them for the page they are viewing would get the data from the database (you saved) and serve it to them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.