Jump to content

Select-modify-display record


scooterlibby

Recommended Posts

I have 3 scripts

select record from file    works ok  once I select record it

displays record to modify  6 fields,  2 I want to be input capable  seems to work ok

 

  once I make changes to record  on screen it should transfer to script#3 which displays the record just modified.

 

Script #3 outputs to screen however it does not display any fields or perform update.

 

is there something crazy going on with update cmd?

 

fields changed in script2 are $fx & $fy  last two.

 

Any help on why data does not seem to persist would be appreciated.

 

 

 

<?php

include 'config.php';  
include 'opendb.php';

// update record after xxx xxy now xxz
  
$sql = "UPDATE petaluma SET date1 = \"$fa\",  group1sts = \"$fx\", group2sts = \"$fy\"  WHERE date1 = \"$fa\"";

$sql_result = mysql_query($sql, $conn) or die ("zero-connection to the Petaluma file");


//   Update record


If (!$sql_result) {
echo "<p> record not updated</p> ";
} else {

// format results by row 
  
echo "
<html>
<body><center>
<table width=602><tr><td><fieldset>
<font face=arial><center>
<h3>Petaluma Schedule Modified</h3>
<br>Use this screen to check previous modification performed<br><br>

<table width=600>
<tr><td colspan=3> <center>  <b>Class Dates</b> <br><br></td></tr>
<tr><td align=center  colspan=3><fieldset><b>$fa</b>      
$fb    $fc </fieldset></td></tr>

<tr>
<td align=center colspan=3> <fieldset><br><br>
Group 1 message $fx
<br><br>  
Group 2 message $fy  <br><br> 
</fieldset>
</td>

</tr>

<tr><td colspan=3>
<center>
<br><br>

</tr>
</table>

</fieldset>
</td></tr></table>

</body>
</html>
";

}

  
// free resources
mysql_free_result($sql_result);
mysql_close($dbh); 

?>

Link to comment
https://forums.phpfreaks.com/topic/41902-select-modify-display-record/
Share on other sites

sorry to say this did not work.

 

before modification I was getting the 3rd screen to display with no data.  Looking behind at thefile the update did not happen.

 

I applied  your suggested modification  and all I get this time is  zero connectio to file. 

$sql = "UPDATE petaluma SET  date1 = ".$fa.",  group1sts = ".$fx.", group2sts = ".$fy." WHERE date1 = ".$fa;

$sql_result = mysql_query($sql, $conn) or die ("zero-connection to the Petaluma file");

 

$fa , $fx and $fy come from the previous screen  is there something about data persisting from screen to screen  from script2 FORM command loos like this

 

<FORM method=\"POST\" action=\"xxz.php\"> 

Sorry,

 

Not sure what you mean by this.

 

should 

$fa = $_post["date1"];

$fx = $_post["group1sts"];

$fy = $_post["group2sts"];

or

$fa = $_post["fa"];

$fx = $_post["fx"];

$fy = $_post["fy"];

 

appear on the update script or the second script which captures the new info ???

 

Have tried both with no success

$sql = "UPDATE petaluma SET  date1 = \"$fa\",    group1sts = \"$fx\", group2sts = \"$fy\" WHERE date1 = \"$fa\" ";

 

This is the only statement that gets any sort of return.

All other combinations do not work.

 

I am unsure as to where the post commands go.

 

To recap.  3 scripts

#1  select the record I wand from a drop down list.  Works ok.

#2 display the record with input capable fields and modify

#3 update the record with any changes made in script # 2

 

Sorry this is how the tutorial I am following has designed the process.

 

Script 1 & 2 work as desired, however on script3 the update does not seem to work or the fields from script2 have not transferred to script 3.

How can I determine that the fields are coming over or not.

 

 

 

 

I dont know, maybe I am presenting my issue incorrectly  so here it is in simple form 3 scripts

#1 works and passes info to script#2

 

# 2 I think should pass the modified fields to #3 where the file is updated with the record id selected in #1

 

All I am seeing is the html screen   no data in # 3 and the file does not get updated.

 

#1

<?php
include 'config.php';
  	include 'opendb.php';
//
  
$sql = "SELECT * FROM petaluma ORDER BY sequence";
$sql_result = mysql_query($sql, $conn) or die ("zero-connection to the Petaluma file");

// results formatting  26

echo "
<center><font face=verdana size=2>

<table width=750>
<tr><td><center>
<table width=700 bgcolor=#ffffff  >
<tr><td>
<center>

<h4>Amend Schedule</h4>


<Form method=\"POST\" action=\"xxy.php\">

<table width=650>
<tr><td align=right><font size=2><strong>Date and Class</strong> &nbsp</td> 
<td>
<select name=\"sel_record\">
<option value=\"\"> <font size=2>--Select date to amend   --</option>
";

// format results by row 
while ($row = mysql_fetch_array($sql_result)) {

$fa = $row["date1"];
$fb = $row["date2"];
$fc = $row["date3"];
$fg1 = $row["grp1"];
$fga0 = $row["g1t1"];
$fga1 = $row["g1t2"];
$fga2 = $row["g1t3"];

$fg2 = $row["grp2"];
$fgb0 = $row["g2t1"];
$fgb1 = $row["g2t2"];
$fgb2 = $row["g2t3"];

$fx = $row["status"];
$fy = $row["comment"];

echo " 
	<font face=verdana size=2> 
	 <option value=\"$fa\">$fa  &nbsp ($fb - $fc) - $fg1    $fg2  </option>

";
}

echo "
</select>
</td>
</tr>
<tr><td colspan=2><br><br><center>
<INPUT type=\"submit\" value=\"Select Date\"></td>
</tr>
</table>
</FORM>

</td></tr>
</table>
</td></tr>
</table>
</body>
</html>

";


// free resources
mysql_free_result($sql_result);
mysql_close($dbh); 

?>

 

#2

 

<?php

include 'config.php';  
include 'opendb.php';
//
  
$sql = "SELECT * FROM petaluma WHERE date1 = \"$sel_record\"";
$sql_result = mysql_query($sql, $conn) or die ("zero-connection to the Petaluma file");

//   Modify record


If (!$sql_result) {
echo "<p> record not found</p> ";
} else {

// format results by row 
$row = mysql_fetch_array($sql_result) ;

$fa = $row["date1"];
$fb = $row["date2"];
$fc = $row["date3"];
$fg1 = $row["grp1"];
$fga0 = $row["g1t1"];
$fga1 = $row["g1t2"];
$fga2 = $row["g1t3"];
$fg2 = $row["grp2"];
$fgb0 = $row["g2t1"];
$fgb1 = $row["g2t2"];
$fgb2 = $row["g2t3"];
$fx = $row["group1sts"];
$fy = $row["group2sts"];

echo "
<html>
<body><center>
<table width=602><tr><td><fieldset>
<font face=arial><center>
<h3>Petaluma Schedule Modification</h3>
<br>Use this screen to add a message for the classes on the date selected<br><br>

<FORM method=\"POST\" action=\"xxz.php\">

<table width=600>
<tr><td colspan=3> <center>  <b>Class Dates</b> <br><br></td></tr>
<tr><td align=center  colspan=3><fieldset><b><INPUT type=\"text\" readonly=\"readonly\" name=\"date1\" value=\"$fa\"> </b>      
$fb    $fc </fieldset></td></tr>

<tr>
<td align=center colspan=3> <fieldset><br><br>
Group 1 message <INPUT type=\"text\" name=\"group1sts\" value=\"$fx\" size=30 maxlength=25> 
<br><br>  
Group 2 message <INPUT type=\"text\" name=\"group2sts\" value=\"$fy\" size=30 maxlength=25>  
</fieldset>
</td>

</tr>

<tr><td colspan=3>
<center>
<br><br>
<INPUT type=\"submit\" value=\"Modify Record\"><br><bR></td>
</tr>


</table>
</form>
<br><br>
<font size=1>  

</fieldset>
</td></tr></table>

</body>
</html>
";

}



// free resources
//mysql_free_result($sql_result);
//mysql_close($dbh); 

?>

#3

 

<?php

include 'config.php';  
include 'opendb.php';

// update record after xxx xxy now xxz
  
//  $sql = "UPDATE petaluma SET  date1 = '$fa',    group1sts = "$fx", group2sts = "$fy" WHERE date1 = "$fa"";
// does nt like $sql = "UPDATE petaluma SET date1 = \'$fa\', group1sts = \'$fx\', group2sts = \'$fy\' WHERE date1 = $fa  " ;
//  blank screen  $sql = "UPDATE petaluma SET date1 = '$fa', group1sts = '$fx', group2sts = '$fy' WHERE date1 = $fa  " ;
// blank screen 





$sql = "UPDATE petaluma SET  date1 = \"$fa\",    group1sts = \"$fx\", group2sts = \"$fy\" WHERE date1= \"$fa\" ";

$sql_result = mysql_query($sql, $conn) or die ("zero-connection to the Petaluma file");

//   Update record


If (!$sql_result) {
echo "<p> record not updated</p> ";
} else {

// format results by row 
  
echo "
<html>
<body><center>
<table width=602><tr><td><fieldset>
<font face=arial><center>
<h3>Petaluma Schedule Modified</h3>
<br>Use this screen to check previous modification performed<br><br>

<table width=600>
<tr><td colspan=3> <center>  <b>Class Dates</b> <br><br></td></tr>
<tr><td align=center  colspan=3><fieldset><b>$fa</b>      
$fb    $fc </fieldset></td></tr>

<tr>
<td align=center colspan=3> <fieldset><br><br>
Group 1 message $fx
<br><br>  
Group 2 message $fy  <br><br> 
</fieldset>
</td>

</tr>

<tr><td colspan=3>
<center>
<br><br>

</tr>


</table>

<br><br>
<font size=1>  

</fieldset>
</td></tr></table>

</body>
</html>
";

}

  
// free resources
mysql_free_result($sql_result);
mysql_close($dbh); 

?>

 

What am I doing wrong between # 2 and #3  I am completely at a loss and all the php/mysql books have answers all of which I have tried but none work.

 

These scripts are based on a set of scripts from PHP Essentials -Melon1

 

 

Is it possible that "UPDATE petaluma SET  date1 = \"$fa\",    group1sts = \"$fx\", group2sts = \"$fy\" WHERE date1= \"$fa\" "; is incorrect where I am updating Date1 and using it as the key to the file at the same time (Date1 will never be updated here only group1sts and group2sts

 

I am thinking about this at work today, but wont be able to fix this until this evening.  Any comments anyone? please :P

yeah your sql queries are being parsed wrong because of the way your escaping quotes, you dont have to escape single quotes in a double quoted string, doing so will cause an error. also, you can't use double-quotes inside a double quote string and escape them because it will die when it goes to process the query.

 

try these couple of queries

 

$sql = "UPDATE petaluma SET date1='$fa', group1sts='$fx', group2sts='$fy' WHERE date1='$fa' "
$sql = "UPDATE petaluma SET `date1`='$fa', `group1sts`='$fx', `group2sts`='$fy' WHERE `date1`='$fa' "

and for your query results, this will tell you what the sql problem is

$sql_result = mysql_query($sql, $conn) or die(mysql_error());


 

also, be sure on every page you are posting to (both 2 & 3) that you define the posted variables however you wish before attempting to call any of them

 

$fa = $_POST['NAME_OF_FIELD'];

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.