OK I figured out how to use php to update my DB ... but here is the BIG BUT.
I use 3 pages:
1 - the search form (one entry field)
2 - the page with fields they will be populated with the data found in that row, to be altered with the changes and then
3 - the page that will do the actual update.
AS SAID... it works with the ID column.
Let's say I search for ID "14". the second page' fields will be filled with the data. I then change any data I like, not touching the others, click update and - voila, it's done ...
So where is the problem?
A) It works only on one table - not on another (how is exactly the same, everything ... it's just another spare table to do the same experiments on, that's all.
B) The moment I change from the ID column to ANY other column, I get a strange knock telling me
"Could not connect: Unknown column 'Peter' in 'where clause"
So my search for "Peter" which is now under the "name-column" has now turned into the name-column itself ... strange

(before I searched for "14" inder ID and it gave me all data from row 14. I can't see any reaso why it shouldn't do the same with row "Peter"???)
And here is my magic code, in the sequences of 1-2-3
PHP Code:
<form action="update1.php" method="post">
Input ID <input type="text" name="ID" size="22" />
<input type="submit" value="Update" />
</form>
HTML Code:
<html>
<head>
<title></title>
</head>
<body>
<?php
// get ID variable from previous form (the one that selects which record to update) to
// ensure we are updating the correct record
$id = ($_POST['ID']);
if (!$id)
{
die("Variable id not defined. Script terminating.");
}
?>
<?php
// set database variables
include 'dbcall.php';
?>
<?php
// connect to MySQL
$con = mysql_connect($hostname, $user, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
<?php
// select database on $con
$db_selected = mysql_select_db($database, $con) or die(mysql_error
());
?>
<?php
// set string containing query
$sql = "SELECT * FROM clients WHERE ID=" . $id . "";
?>
<?php
// query table (grab the data)
$result = mysql_query($sql, $con) or die('Could not connect: ' . mysql_error());
if (!$result)
{
die('Result did not function:' . mysql_error());
}
?>
<?php
//close the connection
mysql_close();
?>
<?php
// display the form with details obtained from database
while ($row = mysql_fetch_assoc($result))
{
echo "<form action='zagga2.php' method='post'>";
echo "<br /><br />";
echo "<input type='hidden' name='ID' value='$id' />";
echo "<input type='text' name='first_name' value='$row[first_name]' />first name<br />";
echo "<input type='text' name='last_name' value='$row[last_name]' />last name<br />";
echo "<input type='text' name='dob' value='$row[dob]' />DOB<br />";
echo "<input type='text' name='country_origin' value='$row[country_origin]' />Country<br />";
echo "<input type='text' name='primary_email' value='$row[primary_email]' />Country<br />";
echo "<br /><br />";
echo "<input type='submit' value='Update Event' />";
echo "</form>";
}
?>
</body>
</html>
PHP Code:
<?php
// get variables from previous form
$id = ($_POST['ID']);
$first = ($_POST['first_name']);
$last = ($_POST['last_name']);
$dob = ($_POST['dob']);
$country = ($_POST['country_origin']);
$email =($_POST['primary_email']);
?>
<html>
<head>
<title></title>
</head>
<!-- open a page (in this case, displaying the database) once this page has loaded -->
<body onload="location.href='display.php'">
<?php
// set database variables
include 'dbcall.php';
?>
<?php
// connect to MySQL
$con = mysql_connect($hostname, $user, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
<?php
// select database on $con
$db_selected = mysql_select_db($database, $con) or die(mysql_error
());
?>
<?php
// update the database
$sql = ("UPDATE clients SET first_name='$first', last_name='$last', dob='dob', country_origin='$country', primary_email='$email' WHERE ID='$id'");
// show error message if update fails
if (!mysql_query($sql, $con))
{
die('Error: ' . mysql_error());
}
?>
<?php
// close the database
mysql_close($con);
?>
Someone has any idea what is missing or stuffed up, better?
