MySQL Forums
Forum List  »  PHP

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

Lanze

Ok got most of it fixed.

let me give you the url aabees.org/library_maint.htmp

<!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>

The above works as you can see if you access the url above

______________________________________________________

<?php

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


$search=$_POST['search'];

$data = 'SELECT * FROM `library` WHERE `index` = "'.$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="index" value="<?php echo $data2[index]?>"/> <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="hidden" name="index" value="<?php echo $search?>">
<input type="submit" value="submit">
</form>


</body>

</html>


The above is the library_search page code

This seens to work also

______________________________________________________

Here's the kicker

I got rid of the syntax errors and all looks like it is working but nothing gets updated on the database. I am stumped.

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

$Index=$_POST['index'];
$Title=$_POST['title'];
$Author=$_POST['author'];
$Status=$_POST['status'];


$data = "UPDATE library SET title = '" . $Title . "', author = '" . $Author . "', status = '" . $Status . "' WHERE index = $Index";

echo $data;

echo "Rows affected: ", mysql_affected_rows();

echo $_SERVER['REQUEST_URI'];


?>

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

<body>

<!-- JUNK BELOW HERE

$Index=$_POST['indexfield'];
$Title=$_POST['titlefield'];
$Arthor=$_POST['authorfield'];

$data = "UPDATE library SET title = '" . $Title . "', author = '" . $Author . "', status = '" . $Status . "' WHERE index = $Index ";

$data = "UPDATE library SET title = '" . $Title . "', author = '" . $Author . "' WHERE index = '" . $search . "'";

$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());

echo "Rows affected: ", mysql_affected_rows();

echo $_SERVER['REQUEST_URI'];


$data = "UUPDATE library SET title = '" . $Title . "', author = '" . $Author . "', status = '" . $Status . "' WHERE index = '" . $Index . "'";
echo $data;


include('dblibrary.php');


display the changed record from database
Title: <?php echo $Title?><br>
Author: <?php echo $Author?><br><br>

-->

</body>
</html>

Can you see why the DB does not get changed/updated ??

Oh yea - there are only 3 recordes in the test DB 1, 2, and 3 index numbers

Ollie

Options: ReplyQuote


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


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.