giraffemedia Posted January 15, 2008 Share Posted January 15, 2008 I'm currently putting together an admin update page that will display all the records in my matches table and have a link to edit that specific record on each row returned. Because there will be a lot of matches I thought this would be the best way to do this. What I want to do is click the link on a row and edit that record only but i'm having real problems. I was going to pass the data to an execution page but would it be better to do all the editing in one page? I'm desperate to get this working asap, so if you can help i'd be so grateful. Here is the code I have written: <?php //Start session session_start(); //Check whether the session variable //SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) { header("location: ./library/access_denied.php"); exit(); } include ('includes/config.php'); include ('includes/opendb.php'); $query="SELECT match_id, DATE_FORMAT(match_date,'%a %D %b %Y') as match_date, TIME_FORMAT(match_time, '%l %p') as match_time, match_team, match_venue FROM matches ORDER BY DATE_FORMAT(match_date,'%m/%d/%Y')"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } $numrows=mysql_num_rows($result); ?> <html> <head> <title>. : Cricket Club - Edit Matches : .</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="main_nav"> <?php include ('main_nav.php'); ?> </div> <div id="main_content"> <div id="main_content_inner"> <h1>Fixtures and Results</h1> <form method="post" action="library/edit_fixture_result_exec.php"> <table width="100%" border="0" cellspacing="5" cellpadding="0" id="fixtures_results"> <tr> <th width="5%" height="30" align="left" valign="top"><h2>ID</h2></th> <th width="15%" height="30" align="left" valign="top"><h2>Date</h2></th> <th width="10%" height="30" align="left" valign="top"><h2>Time</h2></th> <th width="35%" height="30" align="left" valign="top"><h2>Team</h2></th> <th width="20%" height="30" align="left" valign="top"><h2>Venue</h2></th> <th width="20%" height="30" align="left" valign="top"><h2>Result</h2></th> </tr> <?php $i=0; while ($i < $numrows) { $match_info=mysql_fetch_assoc($result); $id=mysql_result($result,$i,"match_id"); $match_date=mysql_result($result,$i,"match_date"); $match_time=mysql_result($result,$i,"match_time"); $match_team=mysql_result($result,$i,"match_team"); $match_venue=mysql_result($result,$i,"match_venue"); $match_result=mysql_result($result,$i,"match_result"); ?> <tr> <td width="5%" align="left" valign="top"><p><a href="library/edit_fixture_result_exec.php?id=$id"><?php echo "$id"; ?></a></p></td> <td width="15%" align="left" valign="top"><p><?php echo "$match_date"; ?></p></td> <td width="10%" align="left" valign="top"><p class="time"><?php echo "$match_time"; ?></p></td> <td width="35%" align="left" valign="top"><p><?php echo "$match_team"; ?></p></td> <td width="20%" align="left" valign="top"><p><?php echo "$match_venue"; ?></p></td> <td width="20%" align="left" valign="top"><p><?php echo "$match_result"; ?></p></td> </tr> <?php $i++; } ?> </table></form> </div> </div> <div id="main_content_right"> <div id="main_content_right_inner"> <?php include ('latest_news.php'); ?> </div> </div> <div id="footer"></div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/ Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 I would personally have a seperate page. Just keeps things simple. When you setup the link to edit just add in the id details www.example.co.uk/edit.php?id=$id. Then on the edit page $GET['id'] and search the database on that Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439779 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 Adam, i've tried that but it's not passing the id in the url. Is my syntax wrong? James Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439805 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 this <td width="5%" align="left" valign="top"><p><a href="library/edit_fixture_result_exec.php?id=$id"><?php echo "$id"; ?></a></p></td> should be <td width="5%" align="left" valign="top"><p><a href="library/edit_fixture_result_exec.php?id=<?php echo $id; ?>"><?php echo "$id"; ?></a></p></td> Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439809 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 ok, that works fine. (Strangely - I was just about to try that here on my mac!!) Now do I request each table entry like... $match_id = $_GET['match_id']; and then echo the variable to pre-populate the form fields like... <p>Match ID:</p> <input type="text" name="match_id" value="<? echo $match_id; ?>"> Is this correct, or do have to add any code before all this to get the info I have passed from the previous page? James Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439816 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 What you have is fine. Now to get the rest of the match information query your datanase on $match_id Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439817 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 I presume I am only passing the $match_id variable to the update page and that if I need to update several fields on the form I have to pass all the variables to the update page by appending them like: <td width="5%" align="left" valign="top"><p><a href="library/edit_fixture_result_exec.php?id=<?php echo $match_id,$match_date; ?>"><?php echo "$match_id"; ?></a></p></td> If I do this, the data is showing on my update page but not pre-populating the fields. James Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439838 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 No you just need to query the database for everything with the ID number from the URL. Not sure really what your asking for Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439846 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 Like... $query="SELECT * FROM matches WHERE match_id = $match_id"; Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439849 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 You have got it then put in a while loop to get all the info while($row = mysql_fetch_array($result)){ $match_Title = $row['title']; $match_date = $row['date']; } Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439850 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 Sorry to be a pain Adam, but where does this bit of code go? I really appreciate your time helping me. Here's what I have so far... <?php //Start session session_start(); //Check whether the session variable //SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) { header("location: library/access_denied.php"); exit(); } include('../includes/config.php'); include('../includes/opendb.php'); $query="SELECT * FROM matches WHERE match_id = '$match_id'"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } $numrows=mysql_num_rows($result); while($row = mysql_fetch_array($result)){ $match_id = $row['match_id']; $match_date = $row['match_date']; } ?> <html> <head> <title>. : Cricket Club - Edit Result : .</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../kilvecc.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="main_nav"> <?php include ('../admin_nav.php'); ?> </div> <div id="main_content"> <div id="main_content_inner"> <form action="" method="post"> <input type="hidden" name="ud_id" value="<? echo $match_id; ?>"> <p>The record ID number is: <? echo $match_id; ?></p><br> Match Date: <input type="text" name="match_date" value="<? echo $match_date; ?>"><br> <br> <input type="Submit" value="Update"> </form> </div> </div> <div id="main_content_right"> <div id="main_content_right_inner"> <?php include ('./latest_news.php'); ?> </div> </div> <div id="footer"></div> </div> </body> </html> <?php include ('./includes/closedb.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439860 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 i am now really confused with what you are trying to do. You have a page that creats a dynamic link library/edit_fixture_result_exec.php?id=<?php echo $id?> that takes a user to edit_fixture_result_exec.php. Now what do you want to happen here. Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439861 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 I want the update page to populate the form with the fields from the record I have selected so I can edit them and update them. Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439863 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 <?php //Start session session_start(); //Check whether the session variable //SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) { header("location: library/access_denied.php"); exit(); } include('../includes/config.php'); include('../includes/opendb.php'); $query="SELECT * FROM matches WHERE match_id = '$match_id'"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } $numrows=mysql_num_rows($result); while($row = mysql_fetch_array($result)){ $match_id = $row['match_id']; $match_date = $row['match_date']; } ?> <html> <head> <title>. : Cricket Club - Edit Result : .</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../kilvecc.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="main_nav"> <?php include ('../admin_nav.php'); ?> </div> <div id="main_content"> <div id="main_content_inner"> <form action="" method="post"> <input type="hidden" name="ud_id" value="<? echo $match_id; ?>"> <p>The record ID number is: <? echo $match_id; ?></p><br> Match Date: <input type="text" name="match_date" value="<? echo $match_date; ?>"><br> <br> <input type="Submit" value="Update"> </form> </div> </div> <div id="main_content_right"> <div id="main_content_right_inner"> <?php include ('./latest_news.php'); ?> </div> </div> <div id="footer"></div> </div> </body> </html> <?php include ('./includes/closedb.php'); ?> What you have here is correct what seems to be the problem Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439865 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 I'm not getting anything other than the $match_id variable showing. Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439880 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 you do have a feild in your database called 'match_date' also <form action="" method="post"> <input type="hidden" name="ud_id" value="<?php echo $match_id; ?>"> <p>The record ID number is: <?php echo $match_id; ?></p><br> Match Date: <input type="text" name="match_date" value="<?php echo $match_date; ?>"><br> <br> <input type="Submit" value="Update"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439882 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 Yes I have all of that. The id is in the url and the id echo's on the page fine but that's it. Is there an error with the while loop. I'm not quite sure where I have to put the two seperate bits. Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439890 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 post the code for everything you have on the edit page. Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439891 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 <?php //Start session session_start(); //Check whether the session variable //SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) { header("location: library/access_denied.php"); exit(); } include('../includes/config.php'); include('../includes/opendb.php'); $query="SELECT * FROM matches WHERE match_id = '$match_id'"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } $numrows=mysql_num_rows($result); $match_id = $_GET['id']; $match_date = $_GET['match_date']; ?> <html> <head> <title>. : Cricket Club - Edit Result : .</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../kilvecc.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="main_nav"> <?php include ('../admin_nav.php'); ?> </div> <div id="main_content"> <div id="main_content_inner"> <form action="" method="post"> <input type="hidden" name="ud_id" value="<? echo $match_id; ?>"> <input type="hidden" name="ud_id" value="<? echo $match_date; ?>"> <p>The record ID number is: <? echo $match_id; ?></p><br> Match Date: <input type="text" name="match_date" value="<? echo $match_date; ?>"><br> <br> <input type="Submit" value="Update"> </form> </div> </div> <div id="main_content_right"> <div id="main_content_right_inner"> <?php include ('./latest_news.php'); ?> </div> </div> <div id="footer"></div> </div> </body> </html> <?php include ('./includes/closedb.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439897 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 try this <?php //Start session session_start(); //Check whether the session variable //SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) { header("location: library/access_denied.php"); exit(); } include('../includes/config.php'); include('../includes/opendb.php'); $query="SELECT * FROM matches WHERE match_id = '$match_id'"; $result=mysql_query($query) $numrows=mysql_num_rows($result); while(mysql_fetch_array(result)) { $match_id = $_GET['id']; $match_date = $_GET['match_date']; } ?> <html> <head> <title>. : Cricket Club - Edit Result : .</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../kilvecc.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="main_nav"> <?php include ('../admin_nav.php'); ?> </div> <div id="main_content"> <div id="main_content_inner"> <form action="" method="post"> <input type="hidden" name="ud_id" value="<? echo $match_id; ?>"> <input type="hidden" name="ud_id" value="<? echo $match_date; ?>"> <p>The record ID number is: <? echo $match_id; ?></p><br> Match Date: <input type="text" name="match_date" value="<? echo $match_date; ?>"><br> <br> <input type="Submit" value="Update"> </form> </div> </div> <div id="main_content_right"> <div id="main_content_right_inner"> <?php include ('./latest_news.php'); ?> </div> </div> <div id="footer"></div> </div> </body> </html> <?php include ('./includes/closedb.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439910 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 Blank page - maybe i've got a typo somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439913 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 Delete everything from the update page and just have <?php //Start session session_start(); //Check whether the session variable //SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) { header("location: library/access_denied.php"); exit(); } include('../includes/config.php'); include('../includes/opendb.php'); $query="SELECT * FROM matches WHERE match_id = '$match_id'"; $result=mysql_query($query) $numrows=mysql_num_rows($result); while(mysql_fetch_array(result)) { $match_id = $_GET['id']; $match_date = $_GET['match_date']; } echo $match_id; echo $match_date; ?> Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439916 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 Blank page again. Strange Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439918 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 you have just code the code i showed above. Also put error_reporting(E_ALL); at the top and tell me any errors. Also at change $result=mysql_query($query) to $result=mysql_query($query) or die('Error: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439923 Share on other sites More sharing options...
giraffemedia Posted January 15, 2008 Author Share Posted January 15, 2008 still the blank page Quote Link to comment https://forums.phpfreaks.com/topic/86121-solved-really-need-help/#findComment-439926 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.