Forum Moderators: coopster
This sceipt below is supposed to take a db entry by id and allow me to alter just the $diwtitle variable. This it does successfully.. But after I change it and go to MySQL and look at the db, it has changed the $diwtitle variable in every row of the table. And that was not an intended outcome.
How can I make it change just the one entry?
[php]
<?php
// Connect to database
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost!");
mysql_select_db("testdiw")
or die("Could not select that database!");
if(!empty($_REQUEST['action']) && $_REQUEST['action'] == 'update')
{
$id = $_REQUEST['id'];
$_GET['id'] = $id;
$query = "UPDATE `mktime` SET diwtitle = '".$_REQUEST['newtitle']."'";
$result = mysql_query($query) or die("<b>mySQL Error:</b>".mysql_errono()."<br>".mysql_error());
if(!$result)
{
echo 'Error processing request.';
}
else
{
echo 'Request processed successfully.';
}
}
$id = $_GET['id'];
// The ID is passed through the URL to specify the row,
// Or it is set in the previous script.
$query = "SELECT * FROM mktime WHERE id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo '<form name="update" method="post">
<input type="hidden" value="update" name="action">
<input type="hidden" name="id" value="'.$id.'">
<input type="text" name="newtitle" value="'.$row['diwtitle'].'"><br>
<input type="submit" value="Update">
</form>';
?> [/php]
that worked.. only changed the one line.. :)
EDIT: Thank you topr! Looks like I figured out how to do exactly what you intended me to do.. For all I know, CRITERIA may be some MySQL function which I had never heard aobut.. lol