Jump to content

Archived

This topic is now archived and is closed to further replies.

N30Cr0n

Expert eye need to to spot mistakes!! - PLEASE

Recommended Posts

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 [b]UPDATE[/b] syntax to, well, update the table! lol

ARGH!

[code]<?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;
}

?>[/code]

thanks guys

Share this post


Link to post
Share on other sites
Welll, post the interpolated query, and any associated MySQL errors.  BTW, shouldn't you be unlocking the table after the UPDATE statement?

Share this post


Link to post
Share on other sites
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

[code]<?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;

}

?>[/code]

Share this post


Link to post
Share on other sites
I'm still not seeing the final query string being passed to MySQL...

Share this post


Link to post
Share on other sites
[quote author=fenway link=topic=102570.msg409570#msg409570 date=1154703751]
I'm still not seeing the final query string being passed to MySQL...
[/quote]

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

Share this post


Link to post
Share on other sites
Echo what you're passing to the mysql_query function.

Share this post


Link to post
Share on other sites

×

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.