0

I have a form that get's pre populated from an events_result table. It has fname,lastname,event,results column. I have a link to Update which is an action call to function UpdateResults. I want to be able to use this one form to show the results and be able to update the results column if needed. Below is the code. I did have the UpdateResults in a separate functions.php file but that really wasn't working. Right now my update command give's me everything i want but the new/edited results value. its not getting passed correctly some how.

// Make the query:
$query = "SELECT * FROM athlete,events,event_results where athlete.athlete_id = event_results.athlete_id
          and events.event = event_results.event ORDER BY $order_by LIMIT $start, $display";    

$res = mysql_query($query);

echo '<form name="form1" action="mathleteresults.php" method="post">';
// Table header:
echo '<table align="center" cellspacing="0" cellpadding="5" width="155%">
<tr>
    <td align="left"><b>Edit</b></td>
    <td align="left"><b>Delete</b></td>
    <td align="left"><b>FirstName</b></td>
    <td align="left"><b>LastName</b></td>
    <td align="left"><b><a href="mathleteresults.php?sort=eventorder">Event</a></b></td>
    <td align="left"><b><a href="mathleteresults.php?sort=result">Results</a></b></td>
    <td align="left"><b>Date</b></td>
</tr>';

// Fetch and print all the records....
$bg = '#eeeeee'; 
while ($row = sqlFetchArray($res)) {
    $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');

    //echo $a_id;
        echo '<tr bgcolor="' . $bg . '">
        <td align="left"><a href="?action=UpdateResult&athlete_id=' . $row['athlete_id'] . '&event=' .$row['event'] . '&result=' . $row['result'] .'" >Update </a></td>
        <td align="left"><a href="?action=DeleteResult&athlete_id=' . $row['athlete_id'] . '">Delete</a></td>
        <td align="left">' . $row['first_name'] . '</td>
        <td align="left">' . $row['last_name'] . '</td>
        <td align="left"><input name="event" size="10" id="event" value="' . $row['event'] . '"></td>
        <td align="left"><input type="text" name="result" id="result" size="8" value="' . $row['result'] . '" ></td>
        <td align="left">' . $row['date'] . '</td>
    </tr>';
} // End of WHILE loop.

echo '</table>';
echo '</form>';

    //request to edit/update result
if ((isset($_GET['action']))&&($_GET['action']=='UpdateResult')) 
{   echo "just cant find the result";

    $time = $_GET["result"];
    $event  = $_GET['event'];       
    $id     = $_GET['athlete_id']; 

  $sql = "UPDATE event_results set result='".$time."' Where event='$event' and athlete_id='$id'";
  echo $sql;
        $res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
        if (!empty($res))
            return 99;
        return false;

}

This is a pic of the form.

Edited by Nick Evan: Fixed formatting

Attachments formpic.jpg 77.01 KB
2
Contributors
35
Replies
36
Views
7 Years
Discussion Span
Last Post by debow
0

hmm... whats sqlQuery($sql)?
it should be...

$sql = "UPDATE event_results set result='".$time."' Where event='$event' and athlete_id='$id'";
mysql_query($sql);
0

Thanks for the reply, I tried that just to see what diff result I would have and its the same. The issue isn't with the sql but with getting $time from the form. I've put in a echo $sql to see whats getting ran and evertyhing gets pulled in but the new time/result. Below is what gets displayed. So for example if I type is 45 for "push up" and hit update nothing comes across.

This is from my echo. Notice how result is blank.
UPDATE event_results set result='' Where event='100m Swim' and athlete_id='150'

0

if thats the case then that means that the 'result' field in one of your table is null or empty, are you sure that you named it as 'result' not 'results'. As i see you had 3 tables, if you really want me to help you. can you gave me your database schema so i can test it here. Coz i can just imagine here and visualize what are the data in your database. im not sure if you query is right.

0

Below is the table schema for the 3 tables involved. I also attached the entire mathleteresults.php page so you can see the whole thing. It has some commented lines from my troubleshooting attempts so please ignore them.

--
-- Table structure for table `athlete`
--

CREATE TABLE IF NOT EXISTS `athlete` (
  `athlete_id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(20) DEFAULT NULL,
  `last_name` varchar(20) DEFAULT NULL,
  `sex` varchar(10) DEFAULT NULL,
  `category` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`athlete_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=151 ;

--
-- Dumping data for table `athlete`
--

INSERT INTO `athlete` (`athlete_id`, `first_name`, `last_name`, `sex`, `category`) VALUES
(89, 'Test1', 'Test', NULL, 'men'),
(150, 'Test2', 'Test', NULL, 'men');

-- --------------------------------------------------------
-- --------------------------------------------------------

--
-- Table structure for table `events`
--

CREATE TABLE IF NOT EXISTS `events` (
  `eventid` int(11) NOT NULL AUTO_INCREMENT,
  `event` varchar(16) NOT NULL,
  `eventorder` int(11) NOT NULL,
  `category` varchar(10) NOT NULL,
  `time` varchar(10) DEFAULT NULL,
  `date` year(4) DEFAULT NULL,
  `location` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`eventid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=84 ;

--
-- Dumping data for table `events`
--

INSERT INTO `events` (`eventid`, `event`, `eventorder`, `category`, `time`, `date`, `location`) VALUES
(6, '100m ', 6, 'men', '00:00', 2010, 'Park'),
(8, '400m ', 8, 'men', '00:00', 2010, 'Park'),
(1, '100m Swim', 1, 'men', '00:00', 2010, 'Y'),
(2, 'Push Ups', 2, 'men', '0000', 2010, 'Y'),
(4, 'Pull Ups', 4, 'men', '0000', 2010, 'Y'),
(10, '1 Mile', 10, 'men', '00:00', 2010, 'Park'),
(3, 'Wall Sits', 3, 'men', '00:00', 2010, 'Y'),
(5, 'Med Ball', 5, 'men', '00:00', 2010, 'Y'),
(9, 'Shuttle Run', 9, 'men', '00:00', 2010, 'Park'),
(7, 'Long Jump', 7, 'men', '00:00', 2010, 'Park');

-- --------------------------------------------------------

--
-- Table structure for table `event_results`
--

CREATE TABLE IF NOT EXISTS `event_results` (
  `athlete_id` int(11) NOT NULL,
  `event` varchar(16) NOT NULL,
  `category` varchar(10) NOT NULL,
  `result` varchar(10) NOT NULL,
  `date` year(4) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `event_results`
--

INSERT INTO `event_results` (`athlete_id`, `event`, `category`, `result`, `date`) VALUES
(89, 'Long Jump', 'men', '13:12', 0000),
(89, 'Shuttle Run', 'men', '8:12', 0000),
(89, 'Med Ball', 'men', '41:12', 0000),
(89, 'Wall Sits', 'men', '3:12', 0000),
(89, '1 Mile', 'men', '7:02', 0000),
(89, 'Pull Ups', 'men', '11', 0000),
(89, 'Push Ups', 'men', '53', 0000),
(89, '100m Swim', 'men', '00:59:12', 0000),
(89, '400m ', 'men', '59:12', 0000),
(89, '100m ', 'men', '11:12', 0000),
(150, 'Long Jump', 'men', '', 2010),
(150, 'Shuttle Run', 'men', '', 2010),
(150, 'Med Ball', 'men', '', 2010),
(150, 'Wall Sits', 'men', '', 2010),
(150, '1 Mile', 'men', '', 2010),
(150, 'Pull Ups', 'men', '', 2010),
(150, 'Push Ups', 'men', '0', 2010),
(150, '100m Swim', 'men', '', 2010),
(150, '400m ', 'men', '', 2010),
(150, '100m ', 'men', '', 2010);

-- --------------------------------------------------------

Edited by debow: n/a

Attachments
<?php 
require_once ('includes/functions.php');
require_once ('includes/config.inc.php'); 
include ('includes/header.html');

// Set the page title and include the HTML header:
$page_title = 'Edit Results';
$url = BASE_URL . 'index.php';

error_reporting(E_ALL); 
// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['username'])) {
	ob_end_clean(); // Delete the buffer.
	header("Location: $url");
	//exit(); // Quit the script.
}
?>


<div id="leftcolumn">
<?php include "sidebar.php"; ?>
<br/>	
</div>	


<div id="main">
<?php

// Number of records to show per page:
$display = 10;

// Determine how many pages there are...
if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined.
	$pages = $_GET['p'];
} else { // Need to determine.
 	// Count the number of records:
	//$q = "SELECT COUNT(athlete_id) FROM athlete";
	$query = mysql_query("SELECT * FROM
					athlete,
					events,
					event_results
					where athlete.athlete_id = event_results.athlete_id and events.event = event_results.event");
	//$r = @mysqli_query ($dbc, $q);
	$res = mysql_query($query);
	
	//$row = @mysqli_fetch_array ($r, MYSQLI_NUM);
	$row = mysql_num_rows($query);
	$records = $row;
	
	// Calculate the number of pages...
	if ($records > $display) { // More than 1 page.
		$pages = ceil ($records/$display);
	} else {
		$pages = 1;
	}
} // End of p IF.

// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
	$start = $_GET['s'];
} else {
	$start = 0;
}

// Determine the sort...
// Default is by category date.
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'eventorder';

// Determine the sorting order:
switch ($sort) {
	case 'result':
		$order_by = 'result ASC';
		break;
	default:
		$order_by = 'eventorder ASC';
		$sort = 'eventorder';
		break;
}

// Make the query:
$query = "SELECT * FROM athlete,events,event_results where athlete.athlete_id = event_results.athlete_id
		  and events.event = event_results.event ORDER BY $order_by LIMIT $start, $display";	

//$r = @mysqli_query ($dbc, $q); // Run the query.
$res = mysql_query($query);


//echo '<form id="results" action="mathleteresults.php" method="post">';
echo '<form name="form1" action="mathleteresults.php" method="post">';

// Table header:
echo '<table align="center" cellspacing="0" cellpadding="5" width="155%">
<tr>
	<td align="left"><b>Edit</b></td>
	<td align="left"><b>Delete</b></td>
	<td align="left"><b>FirstName</b></td>
	<td align="left"><b>LastName</b></td>
	<td align="left"><b><a href="mathleteresults.php?sort=eventorder">Event</a></b></td>
	<td align="left"><b><a href="mathleteresults.php?sort=result">Results</a></b></td>
	<td align="left"><b>Date</b></td>
</tr>';
//<td align="left"><a href="?action=UpdateResult&athlete_id=' . $row['athlete_id'] . '">Update</a></td>
// Fetch and print all the records....
$bg = '#eeeeee'; 
while ($row = sqlFetchArray($res)) {
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
	
	//echo $a_id;
		echo '<tr bgcolor="' . $bg . '">
		<td align="left"><a href="?action=UpdateResult&athlete_id=' . $row['athlete_id'] . '&event=' .$row['event'] . '&result=' . $row['result'] .'" >Update </a></td>
		<td align="left"><a href="?action=DeleteResult&athlete_id=' . $row['athlete_id'] . '">Delete</a></td>
		<td align="left">' . $row['first_name'] . '</td>
		<td align="left">' . $row['last_name'] . '</td> 
		<td align="left"><input name="event" size="10" id="event" value="' . $row['event'] . '"></td>
		<td align="left"><input type="text" name="result" id="result" size="8" value="' . $row['result'] . '" ></td>
		<td align="left">' . $row['date'] . '</td>
	</tr>
	';
	//$time = $_GET['athlete_id.result'] ;
	//echo $time;

} // End of WHILE loop.

echo '</table>';
echo '</form>';
	//request to add a new contact so call the show_form function 
if ((isset($_GET['action']))&&($_GET['action']=='UpdateResult')) 
{   //echo "just cant find the result";
	//extract(array_merge($_POST,$_GET));
	//$time = "";
	
 $time = ($_GET['result']); // have to get this to work somehow
 //$time[] = $_GET['result'];
 //$time[] = $row['result'];
 
 $event  = $_GET['event'];       
 $id     = $_GET['athlete_id']; 

  $sql = "UPDATE event_results set result='".$time."' Where event='$event' and athlete_id='$id'";

		echo $sql;
		mysql_query($sql);
		//$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
		if (!empty($res))
			return 99;
		return false;
  
}

sqlFreeResult($res);
mysql_close($db_link);
// Make the links to other pages, if necessary.
if ($pages > 1) {
	
	echo '<br /><p>';
	$current_page = ($start/$display) + 1;
	
	// If it's not the first page, make a Previous button:
	if ($current_page != 1) {
		echo '<a href="mathleteresults.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
	}
	
	// Make all the numbered pages:
	for ($i = 1; $i <= $pages; $i++) {
		if ($i != $current_page) {
			echo '<a href="mathleteresults.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
		} else {
			echo $i . ' ';
		}
	} // End of FOR loop.
	
	// If it's not the last page, make a Next button:
	if ($current_page != $pages) {
		echo '<a href="mathleteresults.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
	}
	
	echo '</p>'; // Close the paragraph.
	
} // End of links section.
?>
</div>


<div id="footer">
<?php include ('includes/footer.php'); ?>
</div>
0

1st of all re-design your database... coz its very hard to join tables coz your not using foreign keys

paste this code in the SQL portion of phpmyadmin to test the query results

SELECT a.firstname, a.lastname, e.name, er.result, e.date
FROM event_results er
LEFT JOIN athletes a ON ( er.athlete_id = a.id )
LEFT JOIN EVENTS e ON ( er.event_id = e.id )

here just rename this to any name you want and append a .sql ex. test.sql and import it to phpmyadmin

Attachments
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 26, 2010 at 12:29 AM
-- Server version: 5.1.37
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `test2`
--

-- --------------------------------------------------------

--
-- Table structure for table `athletes`
--

CREATE TABLE IF NOT EXISTS `athletes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(100) NOT NULL,
  `lastname` varchar(100) NOT NULL,
  `gender` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `athletes`
--

INSERT INTO `athletes` (`id`, `firstname`, `lastname`, `gender`) VALUES
(1, 'Naruto', 'Uzumaki', ''),
(2, 'Sasuke', 'Uchiha', '');

-- --------------------------------------------------------

--
-- Table structure for table `events`
--

CREATE TABLE IF NOT EXISTS `events` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `category` varchar(100) NOT NULL,
  `date` datetime NOT NULL,
  `location` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `events`
--

INSERT INTO `events` (`id`, `name`, `category`, `date`, `location`) VALUES
(1, 'Kunai Throwing', 'men', '2010-06-30 00:08:08', 'Konoha'),
(2, 'Genjutsu Casting', 'women', '2010-06-29 00:08:16', 'Suna');

-- --------------------------------------------------------

--
-- Table structure for table `event_results`
--

CREATE TABLE IF NOT EXISTS `event_results` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `athlete_id` int(11) NOT NULL,
  `event_id` int(11) NOT NULL,
  `result` time NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `event_results`
--

INSERT INTO `event_results` (`id`, `athlete_id`, `event_id`, `result`) VALUES
(1, 1, 1, '05:30:00'),
(2, 2, 2, '05:50:00');
0

I'll work on a better database layout and post the results. Thanks for the help thus far.

0

just use my attached sql file, i already created that database for you just change the file extension to .sql ex. test2.sql and import it to your database via phpmyadmin

0

So I've redesigned my tables made a few changes to the code/queries. I've got a little better results and its running the update command I'm just unable to put it a new value for result. If I type it in and hit update it submit's the old value for results. Attached are is the code and tables. I've put a screen shot on what I get. I put an "echo $res" to see what gets ran after hitting update. The orig value for results was 59:12:00 I typed in a new value hit update and it just submits the old value not the new one.

Edited by debow: n/a

Attachments mathleteresult.jpg 27.23 KB
<?php 
require_once ('includes/functions.php');
require_once ('includes/config.inc.php'); 
include ('includes/header.html');

// Set the page title and include the HTML header:
$page_title = 'Edit Results';
$url = BASE_URL . 'index.php';

error_reporting(E_ALL); 
// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['username'])) {
	ob_end_clean(); // Delete the buffer.
	header("Location: $url");
	//exit(); // Quit the script.
}
?>


<div id="leftcolumn">
<?php include "sidebar.php"; ?>
<br/>	
</div>	


<div id="main">
<?php

// Number of records to show per page:
$display = 10;

// Determine how many pages there are...
if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined.
	$pages = $_GET['p'];
} else { // Need to determine.
 	// Count the number of records:
	$query = "select count(*)
				FROM event_results er
				LEFT JOIN athlete a ON ( er.athlete_id = a.id )
				LEFT JOIN events e ON ( er.event = e.event )";
	$res = mysql_query($query);
	
	$row = sqlNumRows($res);
	$records = $row;
	
	// Calculate the number of pages...
	if ($records > $display) { // More than 1 page.
		$pages = ceil ($records/$display);
	} else {
		$pages = 1;
	}
} // End of p IF.

	// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
	$start = $_GET['s'];
	} else {
	$start = 0;
}


// Determine the sort...
// Default is by category date.
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'event';

// Determine the sorting order:
switch ($sort) {
	case 'result':
		$order_by = 'result ASC';
		break;
	default:
		$order_by = 'event ASC';
		$sort = 'event';
		break;
}

// Make the query:	
$query = "SELECT a.id, a.firstname, a.lastname, e.event, er.result, er.date
			FROM event_results er
			LEFT JOIN athlete a ON ( er.athlete_id = a.id )
			LEFT JOIN events e ON ( er.event = e.event ) ORDER BY $order_by LIMIT $start, $display";
//$res = mysql_query($query);
$res = sqlQuery($query); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());


echo '<form name="list" action="mathleteresults.php" method="post">';
// Table header:
echo '<table align="center" cellspacing="0" cellpadding="5" width="155%">
<tr>
	<td align="left"><b>Edit</b></td>
	<td align="left"><b>FirstName</b></td>
	<td align="left"><b>LastName</b></td>
	<td align="left"><b><a href="mathleteresults.php?sort=event">Event</a></b></td>
	<td align="left"><b><a href="mathleteresults.php?sort=result">Results</a></b></td>
	<td align="left"><b>Date</b></td>
</tr>';

// Fetch and print all the records....
$bg = '#eeeeee'; 
while ($row = sqlFetchArray($res)) {
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
	
		echo '<tr bgcolor="' . $bg . '">
		<td align="left"><a href="?action=UpdateResult&id=' . $row['id'] . '&event=' .$row['event'] . '&result=' . $row['result'] .'">Update </a></td>
		<td align="left">' . $row['firstname'] . '</td>
		<td align="left">' . $row['lastname'] . '</td> 
		<td align="left"><input name="event" size="10" id="event" value="' . $row['event'] . '"></td>
		<td align="left"><input type="text" name="result" id="result" size="8" value="' . $row['result'] . '" ></td>
		<td align="left">' . $row['date'] . '</td>
	</tr>
	';

} // End of WHILE loop.

echo '</table>';
echo '</form>';
	//request to add a new contact so call the show_form function 
if ((isset($_GET['action']))&&($_GET['action']=='UpdateResult')) 
{   
	
 $time = ($_GET['result']); // have to get this to work somehow
 $event  = $_GET['event'];       
 $id     = $_GET['id']; 

  $sql = "UPDATE event_results set result='".$time."' Where event='$event' and athlete_id='$id'";

		echo $sql;
		mysql_query($sql);
		//$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
		if (!empty($res))
			return 99;
		return false;
  
}

sqlFreeResult($res);
mysql_close($db_link);
// Make the links to other pages, if necessary.
if ($pages > 1) {
	
	echo '<br /><p>';
	$current_page = ($start/$display) + 1;
	
	// If it's not the first page, make a Previous button:
	if ($current_page != 1) {
		echo '<a href="mathleteresults.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
	}
	
	// Make all the numbered pages:
	for ($i = 1; $i <= $pages; $i++) {
		if ($i != $current_page) {
			echo '<a href="mathleteresults.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
		} else {
			echo $i . ' ';
		}
	} // End of FOR loop.
	
	// If it's not the last page, make a Next button:
	if ($current_page != $pages) {
		echo '<a href="mathleteresults.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
	}
	
	echo '</p>'; // Close the paragraph.
	
} // End of links section.
?>
</div>


<div id="footer">
<?php include ('includes/footer.php'); ?>
</div>
-- Table structure for table `athlete`
--

CREATE TABLE IF NOT EXISTS `athlete` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(20) DEFAULT NULL,
  `lastname` varchar(20) DEFAULT NULL,
  `gender` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=188 ;

--
-- Dumping data for table `athlete`
--

INSERT INTO `athlete` (`id`, `firstname`, `lastname`, `gender`) VALUES
(187, 'Test', 'Test', 'men');

-- --------------------------------------------------------

--
-- Table structure for table `events`
--

CREATE TABLE IF NOT EXISTS `events` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `event` varchar(16) NOT NULL,
  `date` year(4) DEFAULT NULL,
  `location` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=84 ;

--
-- Dumping data for table `events`
--

INSERT INTO `events` (`id`, `event`, `date`, `location`) VALUES
(6, '100m ', 2010, 'Macken Park'),
(8, '400m ', 2010, 'Macken Park'),
(1, '100m Swim', 2010, 'YMCA'),
(2, 'Push Ups', 2010, 'YMCA'),
(4, 'Pull Ups', 2010, 'YMCA'),
(10, '1 Mile', 2010, 'Macken Park'),
(3, 'Wall Sits', 2010, 'YMCA'),
(5, 'Med Ball', 2010, 'YMCA'),
(9, 'Shuttle Run', 2010, 'Macken Park'),
(7, 'Long Jump', 2010, 'Macken Park');

-- --------------------------------------------------------

--
-- Table structure for table `event_results`
--

CREATE TABLE IF NOT EXISTS `event_results` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `athlete_id` int(11) DEFAULT NULL,
  `event` varchar(16) DEFAULT NULL,
  `gender` varchar(10) DEFAULT NULL,
  `result` varchar(10) DEFAULT NULL,
  `date` year(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `event_results`
--

INSERT INTO `event_results` (`id`, `athlete_id`, `event`, `gender`, `result`, `date`) VALUES
(1, 187, '100m Swim', 'men', '59:12:00', 2010);

-- --------------------------------------------------------

--
-- Table structure for table `login`
--

CREATE TABLE IF NOT EXISTS `login` (
  `loginid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(30) NOT NULL,
  `password` varchar(50) NOT NULL,
  `email` varchar(255) NOT NULL,
  `actcode` varchar(45) NOT NULL,
  `disabled` tinyint(1) NOT NULL DEFAULT '0',
  `activated` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`loginid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `login`
--

INSERT INTO `login` (`loginid`, `username`, `password`, `email`, `actcode`, `disabled`, `activated`) VALUES
(1, 'admin', 'ec4a7c1b752c5a8d05becf0b0589dcc0a1afb105', 'damon1977@hotmail.com', 'qyjegSsqTSKe8NLfh1Mz', 0, 1);

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `user` varchar(20) NOT NULL,
  `first_name` varchar(20) NOT NULL,
  `last_name` varchar(40) NOT NULL,
  `email` varchar(80) NOT NULL,
  `pass` char(40) NOT NULL,
  `user_level` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `active` char(32) DEFAULT NULL,
  `registration_date` datetime NOT NULL,
  PRIMARY KEY (`user_id`),
  UNIQUE KEY `email` (`email`),
  KEY `login` (`email`,`pass`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`user_id`, `user`, `first_name`, `last_name`, `email`, `pass`, `user_level`, `active`, `registration_date`) VALUES
(1, 'admin', 'Damon', 'Powell', 'damon1977@hotmail.com', 'ec4a7c1b752c5a8d05becf0b0589dcc0a1afb105', 1, NULL, '2010-06-18 12:00:53');
0

actually you did updated it, but you didn't notice the change coz your still passing the old value....

examine your query string....

<a href="?action=UpdateResult&athlete_id=' . $row['athlete_id'] . '&event=' .$row['event'] . '&result=' . $row['result'] .'" >Update </a>

have you noticed? your result value is equal to the old result value which is $row. your result should be the value of the result textfield not the $row which is the old one. So let's use javascript to get the value of the result textfield.

put this in the head section of your html code

<script type="text/javascript">
function jfunc(athlete,event,res){
var result = document.getElementById('textres'+res).value;
window.location='?action=UpdateResult&athlete_id='+athlete+'&event='+event+'&result='+result;
}
</script>

then replace your old anchor tag from

<a href="?action=UpdateResult&athlete_id=' . $row['athlete_id'] . '&event=' .$row['event'] . '&result=' . $row['result'] .'" >Update </a

to

<a href='javascript:void(0)' onclick="jfunc(<?=$row['athlete_id']?>,<?=$row['event']?>,<?=$i?>)" />Update</a>

and replace your result textfield from

<input type="text" name="result" id="result" size="8" value="' . $row['result'] . '" >

to

<input type="text" name="textres<?=$i?>" id="textres<?=$i?>" value="<?=$row['result']?>" />

then put $i=1 above while ($row = sqlFetchArray($res)) and increment the $i in the end of the loop, it will look something like this

$i = 1;
while ($row = sqlFetchArray($res)) {
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
echo '<tr bgcolor="' . $bg . '">
<td align="left"><a href="javascript:void(0)" onclick="jfunc('.$row["athlete_id"].','.$row["event"].','.$i.'" />Update</a></td>
<td align="left"><a href="?action=DeleteResult&athlete_id=' . $row['athlete_id'] . '">Delete</a></td>
<td align="left">' . $row['first_name'] . '</td>
<td align="left">' . $row['last_name'] . '</td>
<td align="left"><input name="event" size="10" id="event" value="' . $row['event'] . '"></td>
<td align="left"><input type="text" name="textres'.$i.'" id="textres'.$i.'" value="'.$row['result'].'" /></td>
<td align="left">' . $row['date'] . '</td>
</tr>';
$i++;
}

the incremental $i is very important as it will be the one to name your result textfield uniquely, so we dont have problem getting the exact result textfield

Edited by vaultdweller123: n/a

0

Have everything in place, just have to figure out the parse error the below line. I'm sure it a missing " or ' or the need for another, just not seeing it yet.

<a href='javascript:void(0)' onclick="jfunc(<?=$row['athlete_id']?>,<?=$row['event']?>,<?=$i?>)" />Update</a>

Parse error: parse error, expecting `','' or `';'' in mathleteresult.php

0

just take extra careful when you use echo, if you use double qoutes, use single qoutes inside, if you want to use double qoutes then escape it, and if you use single qoutes it vice versa.

example

echo "<input type='text' name='txttest' />";

if you want to use double qoutes inside, escape them

echo "<input type=\"text\" name=\"txttest\" />";

if you use single qoutes on echo then you do the opposite

echo '<input type="text" name="txttest" />';

if you want to use single qoutes inside, escape them

echo '<input type=\'text\' name=\'txttest\' />';

but if you encounter concatenation, you can use single or double qoutes, it doesn't matter coz concatenation makes it outside the string

echo "<input type='text' name='txttest' value='".$row['sample']."' />";

or just use what i have already make for you
this part

echo '<tr bgcolor="' . $bg . '">
<td align="left"><a href="javascript:void(0)" onclick="jfunc('.$row["athlete_id"].','.$row["event"].','.$i.'" />Update</a></td>
<td align="left"><a href="?action=DeleteResult&athlete_id=' . $row['athlete_id'] . '">Delete</a></td>
<td align="left">' . $row['first_name'] . '</td>
<td align="left">' . $row['last_name'] . '</td>
<td align="left"><input name="event" size="10" id="event" value="' . $row['event'] . '"></td>
<td align="left"><input type="text" name="textres'.$i.'" id="textres'.$i.'" value="'.$row['result'].'" /></td>
<td align="left">' . $row['date'] . '</td>
</tr>';

i hope you get my point

Edited by vaultdweller123: n/a

0

First off, thanks a lot for the help. I'm past any parse errors and back to a page that I can type in the new result I want hit update but I don't see my echo statment called so I'm thinking I'm not calling the javascript correclty. Can you help explain what this is doing and maybe I can see what it might be wrong.


I'm not sure if the jfunc(athlete,event,res) are tables or variables. Because either way I don't have those 3 tables and if they are variables what is athlete&res from? Just to make sure I also have this at the very top of the page before they <?php section starts. That is correct right.

<script type="text/javascript">
		function jfunc(athlete,event,res){
		var result = document.getElementById('textres'+res).value;
		window.location='?action=UpdateResult&athlete_id='+athlete+'&event='+event+'&result='+result;
		}
      </script>
0

athlete, event and res are javascript variables, during a click event

<a href="javascript:void(0)" onclick="jfunc('.$row["athlete_id"].','.$row["event"].','.$i.'" />Update</a>

and they will be redirection by using the window.location

window.location='?action=UpdateResult&athlete_id='+athlete+'&event='+event+'&result='+result;
0

may i know the name of your main php file?

this code

// Make the query:
$query = "SELECT * FROM athlete,events,event_results where athlete.athlete_id = event_results.athlete_id
and events.event = event_results.event ORDER BY $order_by LIMIT $start, $display";	

$res = mysql_query($query);

echo '<form name="form1" action="mathleteresults.php" method="post">';
// Table header:
echo '<table align="center" cellspacing="0" cellpadding="5" width="155%">
<tr>
<td align="left"><b>Edit</b></td>
<td align="left"><b>Delete</b></td>
<td align="left"><b>FirstName</b></td>
<td align="left"><b>LastName</b></td>
<td align="left"><b><a href="mathleteresults.php?sort=eventorder">Event</a></b></td>
<td align="left"><b><a href="mathleteresults.php?sort=result">Results</a></b></td>
<td align="left"><b>Date</b></td>
</tr>';

// Fetch and print all the records....
$bg = '#eeeeee'; 
while ($row = sqlFetchArray($res)) {
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');

//echo $a_id;
echo '<tr bgcolor="' . $bg . '">
<td align="left"><a href="?action=UpdateResult&athlete_id=' . $row['athlete_id'] . '&event=' .$row['event'] . '&result=' . $row['result'] .'" >Update </a></td>
<td align="left"><a href="?action=DeleteResult&athlete_id=' . $row['athlete_id'] . '">Delete</a></td>
<td align="left">' . $row['first_name'] . '</td>
<td align="left">' . $row['last_name'] . '</td>
<td align="left"><input name="event" size="10" id="event" value="' . $row['event'] . '"></td>
<td align="left"><input type="text" name="result" id="result" size="8" value="' . $row['result'] . '" ></td>
<td align="left">' . $row['date'] . '</td>
</tr>';
} // End of WHILE loop.

echo '</table>';
echo '</form>';

//request to edit/update result
if ((isset($_GET['action']))&&($_GET['action']=='UpdateResult')) 
{ echo "just cant find the result";

$time = $_GET["result"];
$event = $_GET['event']; 
$id = $_GET['athlete_id']; 

$sql = "UPDATE event_results set result='".$time."' Where event='$event' and athlete_id='$id'";
echo $sql;
$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
if (!empty($res))
return 99;
return false;

}

what's the name of this php file?

Edited by vaultdweller123: n/a

0

are you sure? that seems like the database schema you gave to me, well if that's really the file name then try editing this part

from

window.location='?action=UpdateResult&athlete_id='+athlete+'&event='+event+'&result='+result;

to

window.location='mathleteresults.php?action=UpdateResult&athlete_id='+athlete+'&event='+event+'&result='+result;
0

So not updating with new result value. Attached is the entire code I'm working from now. I put a echo "hello" in the script function and never see it so its like that's not getting called.

Attachments
<script type="text/javascript">
		function jfunc(athlete,event,res){
		var result = document.getElementById('textres'+res).value;
		window.location='mathleteresults.php?action=UpdateResult&athlete_id='+athlete+'&event='+event+'&result='+result;
		}
      </script>   

<?php 
require_once ('includes/functions.php');
require_once ('includes/config.inc.php'); 
include ('includes/header.html');

// Set the page title and include the HTML header:
$page_title = 'Edit Results';
$url = BASE_URL . 'index.php';

error_reporting(E_ALL); 
// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['username'])) {
	ob_end_clean(); // Delete the buffer.
	header("Location: $url");
	//exit(); // Quit the script.
}
?>


<div id="leftcolumn">
<?php include "sidebar.php"; ?>
<br/>	
</div>	


<div id="main">
<?php

// Number of records to show per page:
$display = 10;

// Determine how many pages there are...
if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined.
	$pages = $_GET['p'];
} else { // Need to determine.
 	// Count the number of records:
	$query = "select count(*)
				FROM event_results er
				LEFT JOIN athlete a ON ( er.athlete_id = a.id )
				LEFT JOIN events e ON ( er.event = e.event )";
	$res = mysql_query($query);
	
	$row = sqlNumRows($res);
	$records = $row;
	
	// Calculate the number of pages...
	if ($records > $display) { // More than 1 page.
		$pages = ceil ($records/$display);
	} else {
		$pages = 1;
	}
} // End of p IF.

	// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
	$start = $_GET['s'];
	} else {
	$start = 0;
}


// Determine the sort...
// Default is by category date.
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'event';

// Determine the sorting order:
switch ($sort) {
	case 'result':
		$order_by = 'result ASC';
		break;
	default:
		$order_by = 'event ASC';
		$sort = 'event';
		break;
}

// Make the query:	
$query = "SELECT a.id, a.firstname, a.lastname, e.event, er.result, er.date
			FROM event_results er
			LEFT JOIN athlete a ON ( er.athlete_id = a.id )
			LEFT JOIN events e ON ( er.event = e.event ) ORDER BY $order_by LIMIT $start, $display";
//$res = mysql_query($query);
$res = sqlQuery($query); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());

echo '<form name="list" action="mathleteresults.php" method="post">';
// Table header:
echo '<table align="center" cellspacing="0" cellpadding="5" width="155%">
<tr>
	<td align="left"><b>Edit</b></td>
	<td align="left"><b>FirstName</b></td>
	<td align="left"><b>LastName</b></td>
	<td align="left"><b><a href="mathleteresults.php?sort=event">Event</a></b></td>
	<td align="left"><b><a href="mathleteresults.php?sort=result">Results</a></b></td>
	<td align="left"><b>Date</b></td>
</tr>';
//<td align="left"><a href="?action=UpdateResult&id=' . $row['id'] . '&event=' .$row['event'] . '&result=' . $row['result'] .'">Old </a></td>
//<td align="left"><input type="text" name="newresult" id="result" size="8" value="' . $row['result'] . '" ></td>
// Fetch and print all the records....
#
$i = 1;
$bg = '#eeeeee'; 
while ($row = sqlFetchArray($res)) {
	//echo $row['id'];
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
	  echo '<tr bgcolor="' . $bg . '">
      <td align="left"><a href="javascript:void(0)" onclick="jfunc('.$row["id"].','.$row["event"].','.$i.'" />Update</a></td>
      <td align="left">' . $row['firstname'] . '</td>
      <td align="left">' . $row['lastname'] . '</td>
      <td align="left"><input name="event" size="10" id="event" value="' . $row['event'] . '"></td>
      <td align="left"><input type="text" name="textres'.$i.'" id="textres'.$i.'" value="'.$row['result'].'" /></td>
      <td align="left">' . $row['date'] . '</td>
      </tr>';
	
	  $i++;
} // End of WHILE loop.
echo '</table>';
echo '</form>';
	//request to add a new contact so call the show_form function 
if ((isset($_GET['action']))&&($_GET['action']=='UpdateResult')) 
{   
	
	//$time = ($_GET['result']); // have to get this to work somehow
	$event  = $_GET['event'];       
	$id     = $_GET['id']; 
	//$i      = $_POST['textres'];
	//$time2 =$_POST['newresult'];
	//echo $time2;

	$sql = "UPDATE event_results set result='".$i."' Where event='$event' and athlete_id='$id'";
	echo $sql;
	
	mysql_query($sql);
		//$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
		if (!empty($res))
			return 99;
		return false;
  
}

sqlFreeResult($res);
mysql_close($db_link);
// Make the links to other pages, if necessary.
if ($pages > 1) {
	
	echo '<br /><p>';
	$current_page = ($start/$display) + 1;
	
	// If it's not the first page, make a Previous button:
	if ($current_page != 1) {
		echo '<a href="mathleteresults.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
	}
	
	// Make all the numbered pages:
	for ($i = 1; $i <= $pages; $i++) {
		if ($i != $current_page) {
			echo '<a href="mathleteresults.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
		} else {
			echo $i . ' ';
		}
	} // End of FOR loop.
	
	// If it's not the last page, make a Next button:
	if ($current_page != $pages) {
		echo '<a href="mathleteresults.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
	}
	
	echo '</p>'; // Close the paragraph.
	
} // End of links section.
?>
</div>


<div id="footer">
<?php include ('includes/footer.php'); ?>
</div>
0

coz there is wrong with you update

$sql = "UPDATE event_results set result='".$i."' Where event='$event' and athlete_id='$id'";

why are you passing the $i?

it should be

$id = $_GET['athlete_id'];
$event = $_GET['event'];
$result = $_GET['result'];


$sql = "UPDATE event_results set result='".$result."' Where event='".$event."' and athlete_id='".$id."'";
0

Sorry, that was missed but I fixed it and it still doesnt work. I think the issue is the jfunc isn't getting called or isn't correct becuase my echo $sql after the update is not displayed anymore. It was being displayed when the update was running but just not correctly. Now it doesn't which makes me think that the function UpdateResults isn't being called.

0

ok...upon clicking the update button did it reload? can you paste the query string? i mean the url generated upon clicking the update. coz you will see there if what value are been passed, as i examined you code in order to reach the update and your echoed $sql we have to satisfy the if statement

if ((isset($_GET['action']))&&($_GET['action']=='UpdateResult'))

if clicking the update button regenerates this url
mathleteresults.php?action=UpdateResult&athlete_id=187&event=100m swim&result=1:30

so that means we had these data

$_GET = 'UpdateResult'
$_GET = 187
$_GET = '100m swim'
$_GET = '1:30'

so because of the $_GET = 'UpdateResult' we satisfied the if statement and we should access the update part.

0

So when I type in a new result and hover over Update all I see in the left corner is javascript:void(0). After hitting update nothing happens. The page does not reload. If I refresh the page the old value comes back. Nothing is displayed in the url or from any of the echo's.

0

that's weird??? coz. i can redirect here in my test

this is just a sample script so i can test the redirection

<script type="text/javascript">
function jfunc(athlete,event,res){
var result = document.getElementById('time'+res).value;
window.location = "?athlete="+athlete+"&event="+event+"&res="+result;
}
</script>
<a href='javascript:void(0)' onclick="jfunc(1,1,1)" />click</a><input type="text" name="time1" id="time1" />
0

I just dl'd firebug to see if it would help and I can that when I hover over update it's pulling in data but when clicking either jfunc isn't getting called or is wrong.

See the screen shot.

Attachments mathleteresult.jpg 84.51 KB
0

i don't know why its not calling the jfunc(), where did you put the javascript? can u put it on the head <head> section of the page, coz i dont know what's wrong here

0

That firebug tool is giving me this after I hit update. Not sure where its pointing to.

Attachments mathleteresult.jpg 26.13 KB
0

yeah i found it, the jfunction has no closing parenthesis.

change it from

onclick="jfunc('.$row["id"].','.$row["event"].','.$i.'"

to

onclick="jfunc('.$row["id"].','.$row["event"].','.$i.')"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.