philipr Posted June 4, 2007 Share Posted June 4, 2007 ??? I am new to PHP/MySQL and I am returning to Web Development after many years away. I am hoping someone can help and I don't upset too many with the basics I have a form which I now want to be more dynamic. The datbase tables are builtbut I cannot get the fields to populate. When a member selects an age group from the first select statement and the dates that age group are scheduled to play a match are displayed in a second select statement. When both select ions have been made the rest of the form is displayed and can be filled in and the database updated. The code: <?php //prevents caching header("Expires: Sat, 01 Jan 2000 00:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: post-check=0, pre-check=0",false); session_cache_limiter(); session_start(); //this should the the absolute path to the config.php file //(ie /home/website/yourdomain/login/config.php or //the location in relationship to the page being protected - ie ../login/config.php ) require('config.php'); //this should the the absolute path to the functions.php file - see the instrcutions for config.php above require('functions.php'); //this is group name or username of the group or person that you wish to allow access to // - please be advise that the Administrators Groups has access to all pages. if (allow_access(Member) != "yes") { //this should the the absolute path to the no_access.html file - see above include ('no_access.html'); exit; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <LINK rel="stylesheet" type="text/css" name="style1" href="../Stylesheets/memstyle.css"> <TITLE>Pocklington RUFC - Match Reports</TITLE> </head> <body class="body"> <div align="center"> <div style="width:900px;font-weight:bold;color:#FFFFFF;background:#000099;padding:3px 3px 3px 3px;margin:0;">Pocklington Rugby Club Members Area</div> <div style="width:897px;background:#FFFFFF;border:1px solid #000099;"> <table width="630" bgcolor="#d6dff7" border="0" cellpadding="0" cellspacing="0" > <tr> <td align="center" class="bdytxt3"> <form method="post" name="rptform" id="rptform" action="<?php $PHP_SELF; ?>"> <div style="width:625;float:left;display:inline;margin:0;padding:2px 2px 2px 2px;border:1px solid #000099;"> <table class="member" id="table1" width="100%" cellspacing="0" cellpadding="0"> <caption class="bdytxt2">Submit a Match Report</caption> <tr> <?php $agegrp = !isset($_POST['agegrp'])? NULL : $_POST['agegrp']; ?> <td colspan="2" align="left" class="bdytxt2">Team: <SELECT NAME="agegrp" class="bdytxt2" onChange="document.rptform.submit()"> <OPTION SELECTED><?php echo "Select your team"; ?></option> <OPTION>--------------------</option> <OPTION value="7">Under 7's</option> <OPTION value="8">Under 8's</option> <OPTION value="9">Under 9's</option> <OPTION value="10">Under 10's</option> <OPTION value="11">Under 11's</option> <OPTION value="12">Under 12's</option> <OPTION value="13">Under 13's</option> <OPTION value="14">Under 14's</option> <OPTION value="15">Under 15's</option> <OPTION value="16">Under 16's</option> <OPTION value="17">Under 17's</option> </SELECT> </td> <?php $fixdate = !isset($_POST['fixdate'])? NULL : $_POST['fixdate']; if (isset ($_POST['agegrp'])) { //require the config file require ("config.php"); //make the connection to the database $connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error()); $db = @mysql_select_db($db_name,$connection)or die(mysql_error()); //build and issue the query $fsql ="SELECT * FROM prufc_fixt WHERE agegrp = '$_POST[agegrp]'"; $result1 = @mysql_query($fsql,$connection) or die(mysql_error()); while ($fsql = mysql_fetch_object($result1)) { $f_date = $sql -> fixt_date; $f_agegrp = $sql -> agegrp; $f_oppos = $sql -> opposition; $f_venue = $sql -> venue; $f_result = $sql -> result; $f_for = $sql -> ptsfor; $f_agst = $sql -> ptsagst; } ?> <td class="bdytxt2" colspan="2" align="center">Match Date: <SELECT NAME="fixdate" class="bdytxt2" onChange="document.rptform.submit()"> <?php if ($_POST[fixdate] != "") { echo "<option>$_POST[fixdate]</option>"; echo "<option value=\"\"></option>"; }else{ echo "<option></option>"; } //require the config file require ("config.php"); //make the connection to the database $connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error()); $db = @mysql_select_db($db_name,$connection)or die(mysql_error()); //build and issue the query $sql ="SELECT * FROM prufc_reports WHERE agegrp = '$_POST[agegrp]' AND match_date = '$_POST[fixdate]'"; $result = @mysql_query($sql,$connection) or die(mysql_error()); while ($sql = mysql_fetch_object($result)) { $rdate = $sql -> match_date; echo "<option value=\"$rdate\">$rdate</option>"; } ?> </select> </td> <?php }else{echo "No team set";} ?> </form> </tr> <?php if (($_POST[agegrp] != "") && ($_POST[fixdate] != "")) { //require the config file require ("config.php"); //make the connection to the database $connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error()); $db = @mysql_select_db($db_name,$connection)or die(mysql_error()); //build and issue the query $fsql ="SELECT * FROM prufc_fixt WHERE fixt_date = '$_POST[fixdate]' AND agegrp = '$_POST[agegrp]'"; $result1 = @mysql_query($fsql,$connection) or die(mysql_error()); while ($fsql = mysql_fetch_object($result1)) { $f_date = $sql -> fixt_date; $f_agegrp = $sql -> agegrp; $f_oppos = $sql -> opposition; $f_venue = $sql -> venue; $f_result = $sql -> result; $f_for = $sql -> ptsfor; $f_agst = $sql -> ptsagst; } $sql ="SELECT * FROM prufc_reports WHERE match_date = '$_POST[fixdate]' AND agegrp = '$_POST[agegrp]'"; $result = @mysql_query($sql,$connection) or die(mysql_error()); while ($sql = mysql_fetch_object($result)) { $m_date = $sql -> match_date; $m_agegrp = $sql -> agegrp; $m_title = $sql -> rpttitle; $m_text = $sql -> rpttext; $m_author = $sql -> rptauthor; $m_motm = $sql -> motm; } ?> </tr> <tr> <form method="post" action="add_report.php"> <div style="width:625;float:left;display:inline;margin:0;padding:2px 2px 2px 2px;border:1px solid #000099;"> <table class="member" name="addrpt" id="table1" width="100%" cellspacing="0" cellpadding="0"> <tr> <td align="right" class="bdytxt2">Date: </td> <td><input type="text" name="mdate" class="bdytxt2" value="<?php echo "$m_date"; ?> size="20"></td> <td align="right" class="bdytxt2">Team: </td> <td><input type="text" name="mteam" class="bdytxt2" value="<?php echo "$m_agegrp"; ?> size="30"></td> </tr> </tr> <tr> <td align="right" class="bdytxt2">Opposition: </td> <td><input type="text" name="fixoppos" class="bdytxt2" value="<?php echo "$f_oppos"; ?> size="30"></td> </tr> <tr> <td colspan="2" align="left" class="bdytxt3">Result: <SELECT NAME="result" class="bdytxt2"> <OPTION SELECTED></option> <OPTION value="Won">Won</option> <OPTION value="Draw">Draw</option> <OPTION value="Lost">Lost</option> </td> <td Class="bdytxt3">Points For:<input type="text" name="ptsfor" size="4" maxlength="3"> Against:<input type="text" name="ptsagst" size="4" maxlength="3"> </tr> <tr> <td align="right" class="bdytxt2">Report Title: </td> <td colspan="2"><input type="text" name="rpttitle" class="bdytxt3" style="width:270"></td> </tr> <tr> <td align="right" valign="top" class="bdytxt2">Enter Report: </td> <td colspan="3"><textarea name="rpttext" cols="75" rows="8" class="bdytxt2" ></textarea> </td> </tr> <tr> <td colspan="2" align="center" class="bdytxt2">Man of the Match: <input name="motm" class="bdytxt2" type="text" size="30"></td> <td align="right" valign="middle" class="bdytxt2">Submitted by: </td> <td><input name="rptauth" class="bdytxt2" type="text" size="30"></td> </tr> <tr> <td colspan="2" align="right"> <img src="Captcha/CaptchaSecurityImages.php?width=160&height=45&characters=7" alt="PHP CAPTCHA Generator"></td> <td colspan="2" class="bdytxt2">Enter Security code: <br><input id="security-code" name="security-code" class="bdytxt2" type="text"></td> </tr> <tr> <td align="center" colspan="4"> <INPUT TYPE="submit" value="Submit Report" class="bdytxt2"> <INPUT TYPE="reset" value="Reset Report" class="bdytxt2"> </td> </tr> </table> </form> </td> </tr> </table> </td> </tr> </tr> </table> <?php } else { echo "Please select some info"; } ?> </div> </div> </div> </BODY> </HTML> Any assistance would be gratefully received. Many Thanks Phil Link to comment https://forums.phpfreaks.com/topic/54131-update-a-ststic-html-form-to-dynamic-phpmysql/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.