Jump to content


Photo

Expert eye need to to spot mistakes!! - PLEASE


  • Please log in to reply
5 replies to this topic

#1 N30Cr0n

N30Cr0n
  • Members
  • PipPip
  • Member
  • 21 posts
  • LocationUK

Posted 01 August 2006 - 12:55 PM

hi, can somebody please have look over this code and tell me where i am goin wrong?

i am trying to pull data from an sql table, display it on a php page, using text area, so i can alter the data and them update the table all in one simple page.

i can seem to get the UPDATE syntax to, well, update the table! lol

ARGH!

<?php

if (!eregi("modules.php", $_SERVER['SCRIPT_NAME'])) {
    die ("You can't access this file directly...");
}

require_once("mainfile.php");
-$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "- Premier League Table Admin";

/**********************************/
/* Configuration                  */
/*                                */
/* $index = 0; (right side off)   */
/**********************************/
$index = 1;
$subject = "$sitename Premier League Table Admin";
/**********************************/

include("header.php");
global $prefix, $db;

$premadmin = $db->sql_query("SELECT team_id, team, shortname, played, points FROM wcs_premtable ORDER BY points DESC");

if ($db->sql_numrows($premadmin) == 0) {
   include("header.php");
   include("footer.php");
}

if ($db->sql_numrows($premadmin) > 0) {
    $r_options = "";
    if (isset($cookie[4])) { $r_options .= "&amp;mode=$cookie[4]"; }
    if (isset($cookie[5])) { $r_options .= "&amp;order=$cookie[5]"; }
    if (isset($cookie[6])) { $r_options .= "&amp;thold=$cookie[6]"; }
	
OpenTable();
	
	echo "<table class=forumline cellpadding=\"3\" border=\"0\" width='100%'>"
    ."<form name=\"PremAdmin\" action=\"modules.php?name=$module_name\" method=\"post\">";

	echo "<center><table border=\"0\" width=\"210\" align=\"center\" cellpadding=\"1\">"
    	. "<tr><td align=\"center\" width=\"100\" bgcolor=\"#6a6eff\"><b>Team</b></td><td align=\"center\" width=\"5\"> </td><td align=\"center\" width=\"50\" bgcolor=\"#6a6eff\"><b>Played</b></td><td align=\"center\" width=\"5\"> </td><td align=\"center\" width=\"50\" bgcolor=\"#6a6eff\"><b>Points</b></td></tr>";
    
	 	while ($row = $db->sql_fetchrow($premadmin)) {
			$team_id = stripslashes($row['team_id']);
	 	 	$team = stripslashes($row['team']);
	 	 	$played = stripslashes($row['played']);
	 	 	$points = stripslashes($row['points']);

		echo "<tr><td align=\"center\" width=\"100\" bgcolor=\"#d6d7ff\">$team</a></td><td align=\"center\" width=\"5\"> </td><td><input type=\"text\" name=\"played\" value=\"$played\" size=\"6\" maxlength=\"5\"></td><td align=\"center\" width=\"5\"> </td><td><input type=\"text\" name=\"points\" value=\"$points\" size=\"6\" maxlength=\"5\"></td></tr>";
        		
			}
		
		echo "</center></table>";
		
	echo "<br>";

	echo "<input type=\"hidden\" name=\"team_id\" value=\"$team_id\">";
	echo "<input type=\"hidden\" name=\"team\" value=\"$team\">";
	echo "<input type=\"hidden\" name=\"played\" value=\"$played\">";
	echo "<input type=\"hidden\" name=\"points\" value=\"$points\">";
	echo "<input type=\"hidden\" name=\"op\" value=\"update\">";
	echo "<center><input class=button type=\"submit\" value=\"Update Table\"></center>";
	
	}
	
	echo "</form>";
    
CloseTable();

include("footer.php");

function update($team_id, $team, $played, $points) {
	global $user_prefix, $db, $module_name;
	
    $sql = "SELECT * FROM wcs_premtable LIMIT 0,30";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
	$db->sql_query("LOCK TABLES wcs_premtable WRITE");
	$db->sql_query("UPDATE wcs_premtable SET played = '$played', points = '$points' WHERE team_id = '$team_id'");
    }

   Header("Location: modules.php?name=$module_name");

switch($op) {

    case "update":
	update($team_id, $team, $played, $points);
	break;
}

?>

thanks guys
..:: [SG]N30Cr0n ::..
-= Co-Founder =-

Smokin Gunz [SG] Evolution

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 02 August 2006 - 02:38 PM

Welll, post the interpolated query, and any associated MySQL errors.  BTW, shouldn't you be unlocking the table after the UPDATE statement?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 N30Cr0n

N30Cr0n
  • Members
  • PipPip
  • Member
  • 21 posts
  • LocationUK

Posted 04 August 2006 - 09:51 AM

ok after hours of friggin around, i have come up blank. the page displays, meaning i have no major errors (i think) and i can enter new data into the text area i have set out, but as soon as i click the Update button on the form, the section of code that should write it all back to the datbase, doesn't work, it just refreshes the page, and removes all the data i have jus entered, and resets it back to its original values.

i have changed a few things in the code, to clean it up and everything, and will post the new page code below.

BTW, i am using PHP-Nuke 7.8 CMS as a framework, if that makes any difference.

Thanks

<?php

if (!eregi("modules.php", $_SERVER['SCRIPT_NAME'])) {
    die ("You can't access this file directly...");
}

require_once("mainfile.php");
-$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "- Premier League Table Admin";

/**********************************/
/* Configuration                  */
/*                                */
/* $index = 0; (right side off)   */
/**********************************/
$index = 1;
$subject = "$sitename Premier League Table Admin";
/**********************************/

include("header.php");
global $prefix, $db, $premadmin;

$premadmin = $db->sql_query("SELECT team_id, team, played, points FROM wcs_premtable ORDER BY points DESC");

if ($db->sql_numrows($premadmin) == 0) {
   include("header.php");
   include("footer.php");
}

if ($db->sql_numrows($premadmin) > 0) {
    $r_options = "";
    if (isset($cookie[4])) { $r_options .= "&amp;mode=$cookie[4]"; }
    if (isset($cookie[5])) { $r_options .= "&amp;order=$cookie[5]"; }
    if (isset($cookie[6])) { $r_options .= "&amp;thold=$cookie[6]"; }
	
OpenTable();
	
	echo "<center><font class=\"title\">Premiership League Table Admin</font><br><br>"
	. "<font class=\"content\"><b>ADMIN ONLY:</b> Here you can alter the number of games played and the points scored for each team, and it will be directly reflected on the Premiership League Table.</font></center><br><br>";

	echo "<table cellpadding=\"1\" cellspacing=\"0\" border=\"0\" width='100%'>"
    ."<form name=\"PremAdmin\" action=\"modules.php?name=$module_name\" method=\"post\">";
	
	echo "<center><table border=\"0\" width=\"210\" align=\"center\" cellpadding=\"1\">"
    	. "<tr><td align=\"center\" width=\"100\" bgcolor=\"#6a6eff\"><b>Team</b></td><td align=\"center\" width=\"5\"> </td><td align=\"center\" width=\"50\" bgcolor=\"#6a6eff\"><b>Played</b></td><td align=\"center\" width=\"5\"> </td><td align=\"center\" width=\"50\" bgcolor=\"#6a6eff\"><b>Points</b></td></tr>";
    
	 	while ($row = $db->sql_fetchrow($premadmin)) {
			$team_id = stripslashes($row['team_id']);
	 	 	$team = stripslashes($row['team']);
	 	 	$played = stripslashes($row['played']);
	 	 	$points = stripslashes($row['points']);

		echo "<tr><td align=\"center\" width=\"100\" bgcolor=\"#d6d7ff\">$team</a></td><td align=\"center\" width=\"5\"> </td><td><input type=\"text\" name=\"tot_plyd\" value=\"$played\" size=\"6\" maxlength=\"5\"></td><td align=\"center\" width=\"5\"> </td><td><input type=\"text\" name=\"tot_pnts\" value=\"$points\" size=\"6\" maxlength=\"5\"></td></tr>";
        		
			}
		
	}
		
	echo "<tr><td colspan=\"5\" align=\"center\">";
	echo "<input type=\"hidden\" name=\"team_id\" value=\"$premadmin[team_id]\">";
	echo "<input type=\"hidden\" name=\"team\" value=\"$premadmin[team]\">";
	echo "<input type=\"hidden\" name=\"op\" value=\"premup\">";
	echo "<br><br><center><input class=button type=\"submit\" value=\"Update League\"></center>";
	
	echo "</form></td></tr></table></center>";
    
CloseTable();

include("footer.php");

function premup($team_id, $team, $played, $points) {
	global $user_prefix, $db, $module_name, $premadmin;

	$db->sql_query("LOCK TABLES wcs_premtable WRITE");
	print mysql_error() . "<br />";
	$db->sql_query("UPDATE wcs_premtable SET played = '".$_POST["tot_plyd"]."', points = '".$_POST["tot_pnts"]."' WHERE team_id = '".$_POST["team_id"]."'");
	print mysql_error() . "<br />";
	$db->sql_query("UNLOCK TABLES");
	print mysql_error() . "<br />";

   Header("Location: modules.php?name=$module_name");

}

switch($op) {

    case "premup":
	premup($team_id, $team, $played, $points);
	break;

}

?>

..:: [SG]N30Cr0n ::..
-= Co-Founder =-

Smokin Gunz [SG] Evolution

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 August 2006 - 03:02 PM

I'm still not seeing the final query string being passed to MySQL...
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 N30Cr0n

N30Cr0n
  • Members
  • PipPip
  • Member
  • 21 posts
  • LocationUK

Posted 05 August 2006 - 06:22 PM

I'm still not seeing the final query string being passed to MySQL...


well thats probably my problem, i don't know how to do it, thats why i posting in here!! maybe point me in the right direction fenway??
..:: [SG]N30Cr0n ::..
-= Co-Founder =-

Smokin Gunz [SG] Evolution

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 05 August 2006 - 07:40 PM

Echo what you're passing to the mysql_query function.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users