Re: Retrieve data from a table, edit/add it and enter it in a new table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I see one bug in your code , that is you never "rewind" the pointer of
mysql_fetch_array($result), so at the end of the first cycle ...while
($r=mysq...)... the pointer is at the end of the query resource. You should
use mysql_data_seek($result,0) to rewind before doing another while cycle.
Hope it can help

Bye

Francesco Basile (PHP_newbee)

"Justin" <123harry@xxxxxxxxxx> ha scritto nel messaggio
news:007101c44f77$efe23b60$9d489b82@xxxxxxxx
Hi,

I am trying to do the following:

Retrieve some information from a table, edit it by appending some further
information to it (a few more fields) and then enter the new data record
into a new table, and delete the old data in the original table. Sounds
confusing I know.

The code is below (I apologise for its poor style etc as I am very new to
php), but when I click on the  'Enter Information' button, nothing happens.
The existing data is retrieved without any problems and I can select it
using the radio button. But when I try and add data to the new fields
('option_close_price' and 'notes'), nothing happens.

Any help appreciated.


<form action="<? echo $PHP_SELF ?>" method="post">
<?
mysql_pconnect("localhost","root","password");
mysql_select_db("options");
if(!$cmd)
{
    $result = mysql_query("select * from open_trades");
    while($r=mysql_fetch_array($result))
    {
        $open_date=$r["open_date"];
        $share=$r["share"];
        $code=$r["code"];
        $short_long_trade=$r["short_long_trade"];
        $id=$r["id"];
        $expiry=$r["expiry"];
        $exercise=$r["excercise"];
        $option_price=$r["option_price"];
        $no_purchased=$r["no_purchased"];
        $no_sold=$r["no_sold"];
        $income_in=$r["income_in"];
        $income_out=$r["income_out"];

print "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
print "<td></td><td>Open Date</td><td>Share</td><td>Code</td><td>Short
or<br> Long Trade</td><td>Expiry</td><td>Excercise</td><td>Option
Price</td><td>Number<br> Purchased</td><td>Number Sold</td><td>Income
In</td><td>Income Out</td><td>
</tr>";

while ($row = mysql_fetch_array($result))

{
    print "<tr><td>";
    print "<INPUT TYPE='RADIO' NAME='id' VALUE='echo $id'>";
    print "</td><td>";
    print $row["open_date"];
    print "</td><td>";
    print $row["share"];
    print "</td><td>";
    print $row["code"];
    print "</td><td>";
    print $row["short_long_trade"];
    print "</td><td>";
    print $row["expiry"];
    print "</td><td>";
    print $row["excercise"];
    print "</td><td>";
    print $row["option_price"];
    print "</td><td>";
    print $row["no_purchased"];
    print "</td><td>";
    print $row["no_sold"];
    print "</td><td>";
    print $row["income_in"];
    print "</td><td>";
    print $row["income_out"];
    print "</td></tr>\n";
}
print "</table>\n";

?>

<? }?>
<input type="submit" name="cmd" value="Close"></form>

<? }
 ?>

<?

if($cmd=="Close")
{
    if (!$submit)
    {



        $result = mysql_query("select * from open_trades");
        while($myrow=mysql_fetch_array($result))
?>


<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">

Option Close Price<INPUT TYPE="TEXT" NAME="option_close_price" VALUE="<?PHP
echo $myrow["option_close_price"]?>" SIZE=7 ><br>
Notes:<INPUT TYPE="TEXT" NAME="notes" VALUE="<?php echo $myrow["notes"] ?>"
SIZE=60><br>
<input type="hidden" name="cmd" value="edit">
<input type="Submit" name="submit" value="Enter information">
</form>
<? } ?>



<?
    if($submit)
    {

    $query = "INSERT INTO closed_trades SET code='$code',
option_price='$option_price', option_close_price='$option_close_price',
no_sold='$no_sold', open_date='$open_date',
short_long_trade='$short_long_trade, share='$share', expiry='$expiry',
excercise='$excercise', no_purchased='$no_purchased',
income_in='$income_in', income_out='$income_out', notes='$notes', id=$id'";
    $result = mysql_query($ql);

  $query = "DELETE FROM open_trades WHERE id=$id";
  $result = mysql_query($sql);


        echo "Thank you! Information updated.";

    }
}
?>
    </td>
   </table>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux