Okay... I think I may have been able to write a couple scripts to do what you want. I might make a suggestion that you define the table "gas" to have 2 columns. One being the type of gas (i.e. diesel, unleaded, etc.) and the other being the price for that type. For the type, I suggest defining it as a char of length 10, not null, and the primary key for the table. For the price, you can use the smallint of length 3 (or 4) depending on how you represent the price.
Then the code for the price display page would go something like this:
<html>
<body>
<?php
mysql_connect("localhost","root");
mysql_select_db("superstop");
$query = "SELECT * FROM gas"; // Query to get all the data from the table
$result = mysql_query($query); // Run the query
while($row = mysql_fetch_assoc($result)) // Do the following while rows exist in the result
{
echo "$row['type']: $row['price']
"; // Print the type of gas, followed by the price
}
mysql_free_result($result);
?>
</body>
</html>
And the code for the page which updates the price would go something like this:
<html>
<body>
<?php
mysql_connect("localhost","root");
mysql_select_db("superstop");
$query = "SELECT * FROM gas";
$result = mysql_query($query);
echo "Select type of gas to update price:";
?>
<form action = "<?php echo $PHP_SELF ?>" method = "post">
<select name="type" size="1">
<?php
while($row = mysql_fetch_assoc($result))
{
echo "<option value = $row['type']>$row['type']</option>"; // Add a list option for each type of gas
}
?>
</select>
New Gas Price: <input type = "text" name="price" value = ""> <!-- Get the new price -->
<input type = "submit" name="submit" value="Enter"> <!-- Submit button -->
</form>
<?php
if($submit)
{
$query = "UPDATE gas SET price='$price' WHERE type='$type'"; // Update the price for the selected type of gas
$result = mysql_query($query);
echo "Thank you! Information updated.";
}
?>
</body>
</html>
I believe that this will work. However, my webserver is currently down and I'm unable to test the scripts. But it should at least be a starting point.
Re-reading your original message and you said that the table is defined to have only one column for values, but I think you'll have more success using at least 2 columns. I think (though I may be wrong, as I'm learnng MySQL myself) in order to be able to update the table, you need to use one of the existing values as a reference point to search. Creating the column for the type of gas will let you do this. Making it the primary key will help in searching for the value to be updated. Then on the update price page, you'd have the drop-down list with the types of gas, and then you could enter the price from there. It will then use the selected value from the drop-down list as the field that it will search for, and then will update the price column for the selected value.
JW
Edit: hit the reply button too soon 😱