Hi guys, I am having a little trouble with the following:
First of all I can't work out how to incorporate how to select the current data from the database first, then change the data and click update. In my script below the update part isnt working at all. I am not worried about security because this will not be visible to the web:
Here is my code:
<?php
if(isset($_POST['update']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'mypass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$mon = $_POST['mon'];
$die = $_POST['die'];
$mit = $_POST['mit'];
$don = $_POST['don'];
$fre = $_POST['fre'];
$sql = "UPDATE essen SET mon='$mon', die='$die', mit='$mit', don='$don', fre='$fre'";
mysql_select_db('mydb');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else
{
?>
<div id="content_wrapper"><span class="top"></span><span class="bottom"></span>
<div id="content">
<div class="cleaner_h40"></div>
<h2>What the world is saying:</h2>
<div id="login_box">
<form method="post" action="<?php $PHP_SELF; ?>">
<input id="loginfield" type="text" name="mon" id="mon" value="<?php echo $mon; ?>" />
<input id="loginfield" type="text" name="die" id="die" value="<?php echo $die; ?>" />
<input id="loginfield" type="text" name="mit" id="mit" value="<?php echo $mit; ?>" />
<input id="loginfield" type="text" name="don" id="don" value="<?php echo $don; ?>" />
<input id="loginfield" type="text" name="fre" id="fre" value="<?php echo $fre; ?>" />
<input id="loginbutton" type="submit" value="update" id="update" />
</form>
</div>
<?php
}
?>
</div> <!-- end of content -->
Any help to fix the update and incorporate a select statement first will be great, hopefully I will learn something. 🙂