0

I cannot update row datas.I cannot find what is wrong because my query in updating is 100% right for me.I hope so..But here is my codes so you can help me.

this is home_admin.php

 <?
include("connect.php");
include("addfunc.php");


echo"<link rel=stylesheet type=text/css href=design.css />";
echo"<center><img src=top.png></center>";
if(isset($_GET['add'])){
echo
"<table align=center id=table>


<tr align=center><td align=center>Title<input type=text name=title><br></tr></td>
<tr align=center><td align=center>Price<input type=text name=price><br></tr></td>
<tr align=center><td align=center>Stock<input type=text name=stock><br></tr></td>
<tr align=center><td align=center><input type=submit name=save value=SAVE><br></tr></td></table>

";
                        }
else      {

$result= mysql_query("SELECT * FROM books");

 echo "<div><table border=0 cellspacing='15' align=center id=table1>
        <tr>
            <th>Code</th>
            <th>Title</th>
            <th>Price</th>
            <th>Stock</th>

        </tr>";

while($row = mysql_fetch_array($result)) {  
$code = $row['Code'];   
 echo "<tr><td align=center>".$row['Code']."</td>";
 echo "<td align=center>".$row['Title']."</td>";
 echo "<td align=center>".$row['Price']."</td>";
 echo "<td align=center>".$row['Stock']."</td>";
 echo "<td align=center>"."<a href=delete.php?Code=".$row['Code']."><input type='image' src=erase.ico></a>"."</td>";
  echo"<td align=center>"."<a href='home_edit.php?Code=$code'> <input type='image' src=edit.png></a>"."</td></tr>";


                                     }  

 echo"</table></div>";



 echo"<table align=center><tr><td><input type=submit name=add value='ADD BOOKS'><br> ";
 echo "<center><a href=logout.php> Log-out </a></center>";




        }

 ?>

Edited by diafol: apply code tags

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by fobos
0

2nd page is: edit.php

    <?
include("connect.php");
$code =$_REQUEST['Code'];
$result = mysql_query("SELECT * FROM books WHERE Code='$code'");
$row = mysql_fetch_array($result);
if (!$result) 
        {
        die("Error: Data not found..");
        }
                $Title=$row['Title'] ;
                $Price=$row['Price'] ;
                $Stock=$row['Stock'] ;

if(isset($_GET['editsave']))
{   

$code =$_GET['Code'];
    $t= $_GET['title'];
    $p=$_GET['price'];
    $s=$_GET['stock'];;


    mysql_query("UPDATE books SET Title ='$t', Price ='$p',
         Stock ='$s'  WHERE Code = '$code'")
                or die(mysql_error()); 
    echo "Saved!";
        header("Location: home_edit.php");  

}
mysql_close($conn);
?>


<body>
<form method="GET">
<table>
    <tr>
        <td>Title:</td>
        <td><input type="text" name="title" value="<?php echo $Title ?>"/></td>
    </tr>
    <tr>
        <td>Price</td>
        <td><input type="text" name="price" value="<?php echo $Price ?>"/></td>
    </tr>
    <tr>
        <td>Stock</td>
        <td><input type="text" name="stock" value="<?php echo $Stock ?>"/></td>
    </tr>

    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="editsave" value="edit" /></td>
    </tr>
</table>

</body>
</html>

Edited by diafol: apply code tags

0

your edit link is wrong?

echo "<td align=center>"."<a href=delete.php?Code=".$row['Code']."><input type='image' src=erase.ico></a>"."</td>";
echo"<td align=center>"."<a href='home_edit.php?Code=$code'> <input type='image' src=edit.png></a>"."</td></tr>";

it says $code instead of $row['Code']

0

oh sorry ignore that you set $code further up ($code = $row['Code'];)

<form method="GET">
<table>
<tr>
<td>Title:</td>
<td><input type="text" name="title" value="<?php echo $Title ?>"/></td>
</tr>
<tr>
<td>Price</td>
<td><input type="text" name="price" value="<?php echo $Price ?>"/></td>
</tr>
<tr>
<td>Stock</td>
<td><input type="text" name="stock" value="<?php echo $Stock ?>"/></td>
</tr>

<tr>
<td>&nbsp;</td>
<td><input type="submit" name="editsave" value="edit" /></td>
</tr>
</table>

I dont see any id field passed into your form try adding a hidden input like so:

<form method="GET">
<input type='hidden' value='<?php echo $code;?>' name='Code'/>
<table>
<tr>
<td>Title:</td>
<td><input type="text" name="title" value="<?php echo $Title ?>"/></td>
</tr>
<tr>
<td>Price</td>
<td><input type="text" name="price" value="<?php echo $Price ?>"/></td>
</tr>
<tr>
<td>Stock</td>
<td><input type="text" name="stock" value="<?php echo $Stock ?>"/></td>
</tr>

<tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="editsave" value="edit" /></td>
</tr>
</table>
</form>
0

thank youuu!!!!!!!!!!!!!!!!!!!! so much im really running out of time.You people are great:))

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.