after 16 hours in the pc.. nonstop,
I can't understand.
when retrieving data rows,
if the php code is above the <form> code
once the data comes, even refreshing the page
(under localhost) the data stay there.
when placing the code below, then it works fine.
you'll see I'm not good on this,
each time I load the following page,
it writes a record, before doing anything,
I don't understand why the variable opcode (in the form)
is always set up, even the first time I load the page...
I'm working locally (under XP).
I'm not getting the philosophy of PHP.
When it calls itself (SELF), I suppose it sends the page data
to the server, executes (there) the php logic
and returns...
now, why the document. data are still there?
how can I control (from php) when to reset document. data
or when keep them...
sorry for so much buble....
this is abreviated
<?php
$msg = "";
if (isset($_POST['opcode'])) {
if ($senal > 3 or $senal < 1){
$senal = 0;
} else {
$senal = 1 ;
}
}
// I don't know why $senal is always 1
//.....
if ($senal = 1){
$dbcnx = @mysql_connect("localhost");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server</P>" ); exit(); }
if (! @mysql_select_db("sia_acidentes") ) {
echo( "<P>Unable to locate the " .
"database</P>" ); exit(); }
}
if ($senal == 1){
// pass document.data to php variables
$reg_data = $_POST['reg_data'];
//....
}
if ($senal == 1){
// issue command to update database
//$sql = "INSERT sia_registro SET reg_data = '$reg_data' ,
//......
$result = mysql_query($sql);
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
$senal = -1;
$msg = "transaction failed" ;
} else {
$senal = 9;
$msg = "data updated";
$opcode = 0;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>SIA</TITLE>
<script>
// for PHP comm.
// check if php had written something
// called when user click the button to update
function checkdata(){
if (ok){
document.caso.opcode.value = "1"
document.caso.submit()
}
}
</script>
</head>
<BODY>
<script>
dataforphp()
// writes all the hidden input field to store values for the
// transaction
function dataforphp(){
document.write('<form name=caso ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>')
document.write('<input type=hidden name=opcode value="">')
//.....
}
</script>
<!-- table in html to display data -->
<!-- update button -->
</body>
</html>