For the practice, I started creating a customer profile database.
I've been troubleshooting syntax errors for 2 days and I came here as a last resort. There is something wrong with my sql query, but I just cant see it.
I lost hope with this, so I named the script and wrote it a character persona.
It didn't help.
PHP Code:
<?php
//this script prints to screen the client database
//and allowes for editing
// login to mysql database
$dbcnx = mysql_connect('localhost', 'jamie_mast', 'pass');
if (!$dbcnx) {
echo mysql_error();
}
// connect to database
!mysql_select_db('jamie_clt');
echo mysql_error();
// greeting
echo '<p>Adrian: welcome back Jamie, Im ready to be accessed </p>';
// echo data base contence
$result = mysql_query('SELECT * FROM clients');
if (!$result) {
echo '<p> Im sorry jamie, I have a mysql select error </p>';
echo mysql_error();
exit();
}
// take result set data and turn it into an array
// then declare that array as $row
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['id'];
echo ' | ' . $row['name'];
echo ' | ' . $row['mthp'];
echo ' | ' . $row['lastpm'];
}
//form inputs: row id, column to update, and updated data
?>
<html>
<body>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>Amend which id?
<input name="amdid" type="text" id="amdid">
</p>
<p>Amend which column?
<input name="amdcolumn" type="text" id="amdcolumn">
</p>
<p>
amend data
<input name="newdat" type="text" id="newdat">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
<?php
//load the mysql update command if form data is available
if ($formdat = $_POST['newdat']) {
// declare the variables for the form data
$newdat = $_POST['newdat'];
$amdcolumn = $_POST['amdcolumn'];
$amdid = $_POST['amdid'];
count($result);
$sql = "UPDATE clients SET
'$amdcolumn'='$newdat' WHERE ID ='$amdid'";
if (mysql_query($sql)) {
echo '<p>Adrian: I amended the indicated data, Jamie </p>';
} else {
echo '<p> Adrian: I have an error in processing.</p> ';
echo mysql_error();
}
}
echo '<p> Adrian: I am ready for commands. . . </p>';
//mem dump to check if vars are working
echo "$newdat $amdcolumn $amdid ";
?>






Bookmarks