Jump to content

Recommended Posts

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>


Link to comment
https://forums.phpfreaks.com/topic/86121-solved-really-need-help/
Share on other sites

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>

 

 

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

 

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

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'); ?>

<?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

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>

 

 

<?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'); ?>

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'); ?>

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;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.