[thelist] php mysql update problem

Austin Harris austin at dotmail.co.uk
Fri Jun 27 06:37:50 CDT 2003


I am new to PHP and MySQL, this is my first go at it and have ground to a
halt on trying to update fields, I have searched and tried everything I
could find and have had no joy.

The code below is simplified to just (try and) update a specific field but
still with no joy :(

It can be viewed at <http://austin.mockup.co.uk/jaymel.php>

<html>
<head>
<title>Austin - testing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/style.css">
</head>
<body>
<form action="<?php echo($_SERVER[PHP_SELF]);?>" method="post">
<?php

function my_debug($my_str) {

  // set this var to true to show debugging info
  $show_debug = true;

  if ($show_debug) {
   echo("<span style=\"color: green;font-size: x-small;\">DEBUG:
</span><span style=\"color: red;font-size: x-small;\">$my_str</span><br
/>");
  }
}

// -- attempt connection
    $db = mysql_connect("localhost", "austin", "FridgeMagnet")
    or die("Could not connect: " . mysql_error());
    my_debug("Connection to DB made");
// -- attempt end

// do the update before getting records.
  if ($_POST['submit']=='Submit') {
    // do the update
    $update_sql = "UPDATE jayandmel SET Present='2' WHERE Present='House'";
    my_debug("SQL -- $update_sql");
  }
  
// carry on and grab the required records as normal.

mysql_select_db("austin",$db);

$result = mysql_query("SELECT * FROM jayandmel",$db);

if ($myrow = mysql_fetch_array($result)) {

echo "<table border=0 cellpadding=2 cellspacing=2>\n";

echo "<tr 
bgcolor=#CC0000><td><h1>ID</h1></td><td><h1>Present</h1></td><td><h1>Price</
h1></td><td><h1>Web site</h1></td><td><h1>Availabilty</h1></td></tr>\n";

do {

    $color = array("1"=>"FFCCCC", "2"=>"FFCCCC", "3"=>"FFCCCC",
"4"=>"FFCCCC", "12"=>"FFCCCC", "0"=>"99CCFF");

    $availability = array("1"=>"1 Available","2"=>"2 Available","3"=>"3
Available","4"=>"4 Available", "12"=>"12 Available", "0"=>"Already bought");

    printf("<tr 
bgcolor=#".$color[$myrow[Availability]]."><td><p>$myrow[id]</p></td><td><p>$
myrow[Present]</p></td><td><p>£$myrow[Price]</p></td><td><p><a
href=http://$myrow[url]
target='$myrow[url]'>$myrow[url]</a></p></td><td><p>".$availability[$myrow[A
vailability]]."</p></td></tr>\n", $myrow[id], $myrow[Present],
$myrow["Price"], $myrow["url"], $myrow[Availability]);

    } while ($myrow = mysql_fetch_array($result));

    echo "</table>\n";
    
} else {

    echo "no records found";
    
}
    
?>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

Any help is much appreciated, as would be a good online tutorial or book on
the basics of PHP.

Many thanks in advance, Austin



More information about the thelist mailing list