MySQL Forums
Forum List  »  PHP

Re: Trouble with updating Mysql table data
Posted by: Oliver Snyder
Date: March 22, 2012 09:03PM

Let me give yhe whole thing:

Start

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">;
<html>
<head>
<title>Record Selection Form foe Library Maintainance</title>
<?php

include("menu.php");
include('dblibrary.php');

?>
</head>

<body>



<!-- form to get key detail of record in database -->

<form name="form1" method="POST" action="library_search.php">

<table align=center>

<th align=center><h2>Library Maintenance Form</h2></th>

<tr><td align=center>Enter Publication Index Number</td></tr>

<tr><td align=center><input type="text" size="2" name="search"></td></tr>

<tr><td>&nbsp;</td></tr>

<tr><td align=center><input type="submit" value="submit"></td></tr>

</table>

</form>

</body>

</html>


Next

<?php

include("menu.php");
include('dblibrary.php');


$search=$_POST['search'];

$data = 'SELECT * FROM `library` WHERE `id` = "'.$search.'"';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">;
<html>
<head>
<title></title>
</head>

<body>

<!-- form to display record from database -->
<form name="form" method="POST" action="library_results.php">
ID: <input type="text" name="id" value="<?php echo $data2[id]?>"/> <br>
Title: <input type="text" name="title" value="<?php echo $data2[title]?>"/> <br>
Author: <input type="text" name="author" value="<?php echo $data2[author]?>"/> <br>
Status: <input type="text" name="status" value="<?php echo $data2[status]?>"/><br><br>
<input type="submit" value="submit">
</form>


</body>

</html>


Last

<?php

$Id=$_POST['id'];
$Title=$_POST['title'];
$Author=$_POST['author'];
$Status=$_POST['status'];


echo $Id;
echo $Title;
echo $Author;
echo $Status;


$dbhost = 'localhost';
$dbuser = 'mdwvo_aaba';
$dbpass = 'Pw7fn4j4oS';

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = "UPDATE library SET title = '" . $Title . "', author = '" . $Author . "', status = '" . $Status . "', WHERE id = $Id ";


mysql_select_db('mdwvo_aaba');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
?>

Results (I puy the spaces and lf between the values)

3 Honey Extraction Some body Yes

Could not update data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = 3' at line 1

Options: ReplyQuote


Subject
Written By
Posted
Re: Trouble with updating Mysql table data
March 22, 2012 09:03PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.