PHP Help - Script Broken after Move from .com to .net

Discussion in 'PHP' started by Wilkz, Nov 25, 2007.

  1. #1
    Ok, here is the situation... I had my website set up at .com and then I moved it to another host and purchased the .net domain name instead. Myself and the other webmaster copied everything over, including this script. All of the other scripts work fine. This script is a rankings editor. I open it up and I change the #'s on each person's rank for their win/loss record and then when I click submit, it is supposed to update the MYSQL database. Unfortunately, when I click submit now, the page just reloads with the old ranking and never updates. I have other forms that came over to the new site with no problems. This is the only one that is broken. Any help would be appreciated.



    <?

    require('..global.inc.php');
    SQLConnect();

    // If a submit is issued, do a submit
    if($action == 'Submit' && $failsafe == 'ReallySubmit')
    {
    // Select all IDs that are activated
    $result = @mysql_query("SELECT ID FROM Users WHERE Activated = 'y'");

    // Loop it
    while($data = mysql_fetch_array($result))
    {
    // Build streak
    $iStreak = intval($StreakSign[$data['ID']] . $StreakNum[$data['ID']]);

    // Build update query
    $sQuery =
    'UPDATE Users SET ' .
    'Won = ' . $Won[$data['ID']] . ', ' .
    'Lost = ' . $Lost[$data['ID']] . ', ' .
    'Draw = ' . $Draw[$data['ID']] . ', ' .
    'TagWon = ' . $TagWon[$data['ID']] . ', ' .
    'TagLost = ' . $TagLost[$data['ID']] . ', ' .
    'TagDraw = ' . $TagDraw[$data['ID']] . ', ' .
    'Titles = ' . $Titles[$data['ID']] . ', ' .
    'LastRank = ' . $LastRank[$data['ID']] . ', ' .
    'Streak = ' . $iStreak . ' ' .
    'WHERE ID = ' . $data['ID'];

    // Execute
    if(!@mysql_query($sQuery))
    {
    // An error occured, report it and die
    Die('MySQL Error: ' . mysql_error() . '<br>Query: ' . $sQuery);
    }
    }

    PrintPage('Done', 'The rankings have been updated<br>Click <a href="http://www.hiwf.net/rankings.php">here</a> to go to rankings!');
    Exit;
    }

    // Format a streak into a dropdown with Lost or Won and a number
    function FormatStreak($iStreak, $ID)
    {
    // Default
    $sSign['-'] = '';
    $sSign['+'] = '';

    // Define sign
    if($iStreak < 0)
    $sSign['-'] = 'SELECTED';
    else
    $sSign['+'] = 'SELECTED';

    // Build select and box
    $sReturn =
    '<select name="StreakSign[' . $ID . ']">' .
    '<option value="+" ' . $sSign['+'] . '>Won</option>' .
    '<option value="-" ' . $sSign['-'] . '>Lost</option>' .
    '</select>' .
    '<input type="text" name="StreakNum[' . $ID . ']" style="width: 20px;" value="' . abs($iStreak) . '">';

    // Return
    Return $sReturn;
    }

    // Execute a query based on min and max, sort and format
    Function GetSection($iMin, $iMax, &$iRank, $sColor)
    {
    // Default result
    $sResult =
    ' <tr>' . chr(10) .
    ' <td>ERROR</td>' . chr(10) .
    ' </tr>' . chr(10);

    // Build WHERE clause
    $sWhere = 'WHERE Activated = \'y\' AND (Won + TagWon + Lost + TagLost + Draw + TagDraw) >= ' . $iMin . ' ';

    // If $iMax is not NULL, use it
    if($iMax != NULL)
    $sWhere .= 'AND (Won + TagWon + Lost + TagLost + Draw + TagDraw) <= ' . $iMax . ' ';

    // Build query
    $sQuery =
    'SELECT ID, Name, Email, Won, Lost, Draw, TagWon, TagLost, TagDraw, Streak, Titles, ' .
    'IFNULL( ( (Won + TagWon) / ( (Won + TagWon) + (Lost + TagLost) ) * 10 ), 0 ) AS PCT, ' .
    '(Won + TagWon + Lost + TagLost + Draw + TagDraw) AS Total ' .
    'FROM Users ' .
    $sWhere .
    'ORDER BY PCT DESC, Total DESC, Name;';

    // Execute
    if(!$result = @mysql_query($sQuery))
    {
    // Error
    $sResult =
    ' <tr>' . chr(10) .
    ' <td>MySQL Error: ' . mysql_error() . '<br>' . $sQuery . '</td>' . chr(10) .
    ' </tr>' . chr(10);
    }
    else
    {
    // Check for data
    if(@mysql_numrows($result) == 0)
    $sResult = '';
    else
    {
    // Loop results and format
    $sResult = '';
    while($data = mysql_fetch_array($result))
    {
    // Build PCT
    if($data['PCT'] >= 10)
    $PCT = '1.000';
    else
    $PCT = SubStr(sprintf("%0.3f", ($data['PCT'] / 10)), 1);

    $sResult .=
    ' <tr>' . chr(10) .
    ' <td width="17" align="center" height="14">' . chr(10) .
    ' <font face="Arial Black" size="1" color="' . $sColor . '">' . $iRank . '</font></td>' . chr(10) .
    ' <td width="90" height="14">' . chr(10) .
    ' <a href="mailto:' . $data['Email'] . '" style="text-decoration: none">' . chr(10) .
    ' <font face="Arial Black" size="1" color="' . $sColor . '">' . htmlspecialchars($data['Name']) . '</font></a></td>' . chr(10) .
    ' <td width="112" align="center" height="14">' . chr(10) .
    ' <font face="Arial Black" size="1" color="' . $sColor . '"><input style="width: 20px;" type="text" name="Won[' . $data['ID'] . ']" value="' . $data['Won'] . '">-<input style="width: 20px;" type="text" name="Lost[' . $data['ID'] . ']" value="' . $data['Lost'] . '">-<input style="width: 20px;" type="text" name="Draw[' . $data['ID'] . ']" value="' . $data['Draw'] . '"></font></td>' . chr(10) .
    ' <td width="112" align="center" height="14">' . chr(10) .
    ' <font face="Arial Black" size="1" color="' . $sColor . '"><input style="width: 20px;" type="text" name="TagWon[' . $data['ID'] . ']" value="' . $data['TagWon'] . '">-<input style="width: 20px;" type="text" name="TagLost[' . $data['ID'] . ']" value="' . $data['TagLost'] . '">-<input style="width: 20px;" type="text" name="TagDraw[' . $data['ID'] . ']" value="' . $data['TagDraw'] . '"></font></td>' . chr(10) .
    ' <td align="center" height="14">' . chr(10) .
    ' <font face="Arial Black" size="1" color="' . $sColor . '">' . FormatStreak($data['Streak'], $data['ID']) . '</font></td>' . chr(10) .
    ' <td align="center" height="14">' . chr(10) .
    ' <font face="Arial Black" size="1" color="' . $sColor . '"><input style="width: 20px;" type="text" name="Titles[' . $data['ID'] . ']" value="' . $data['Titles'] . '"></font></td>' . chr(10) .
    ' <td align="center" height="14">' . chr(10) .
    ' <font face="Arial Black" size="1" color="' . $sColor . '"><input type="hidden" name="LastRank[' . $data['ID'] . ']" value="' . $iRank . '">' . $iRank . '</font></td>' . chr(10) .
    ' </tr>' . chr(10);

    // Rank + 1
    $iRank++;
    }
    }
    }

    // Return
    Return $sResult;
    }

    ?>
    <html>

    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>.::. High Impact Wrestling Federation .::.</title>
    <base target="main">

    <link REL="SHORTCUT ICON" HREF="http://www.hiwf.net/images/favicon.ico">





    <style type="text/css">
    <!--input {background-color: #000000; font-family: Arial; font-size: 10pt; color: #FFFFFF;}-->
    <!--BODY {scrollbar-DarkShadow-Color:#FFFFFF; scrollbar-Track-Color:#000000; scrollbar-Face-Color:#000000; scrollbar-Shadow-Color:#006000; scrollbar-Highlight-Color:#000000; scrollbar-3dLight-Color:#000000; scrollbar-Arrow-Color:white}-->

    </style>

    <style type="text/css">
    A:active {COLOR: #FFFF00; TEXT-DECORATION: none}A:link {COLOR: #FFFF00; TEXT-DECORATION: shadow}A:visited {COLOR: #FFFF00; TEXT-DECORATION: glow}A:hover {COLOR: #FFFFFF; TEXT-DECORATION: glow}
    </style>
    <script language=JavaScript>



    </script>
    </head>
    <body text="#FFFFFF" bgcolor="#000000" link="#FFFF00" vlink="#FFFF00" alink="#FFFFFF" topmargin="0" leftmargin="0" bgproperties="fixed" background="backgrounds/ratings.jpg">
    <table border="0" cellspacing="0" style="border-collapse: collapse" width="484" id="AutoNumber1" cellpadding="0">
    <tr>
    <td width="100%">
    <div align="center">
    <center><img border="0" src="http://www.hiwf.net/banners/ratings.jpg"><br>
    &nbsp;</center>
    </div>
    <div align="center">
    <center>
    <table border="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber3" cellpadding="0">
    <tr>
    <td>
    <p align="center"><img border="0" src="http://www.hiwf.net/misc/9.jpg"></td>
    <td>
    <img border="0" src="http://www.hiwf.net/misc/29.jpg"></td>
    <td>
    <img border="0" src="http://www.hiwf.net/misc/49.jpg"></td>
    <td>
    <img border="0" src="http://www.hiwf.net/misc/99.jpg"></td>
    <td>
    <img border="0" src="http://www.hiwf.net/misc/100.jpg"></td>
    </tr>
    </table>
    <center><p>&nbsp;</p>
    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="hidden" name="action" value="Submit">
    <input type="hidden" name="failsafe" value="ReallySubmit">
    <table border="0" cellspacing="0" style="border-collapse: collapse" width="485" id="AutoNumber4" cellpadding="0" height="394">
    <tr>
    <td colspan="11" width="485" height="25">
    <img border="0" src="http://www.hiwf.net/misc/rankhead.jpg"></td>
    </tr>

    <?
    // Set base rank (1)
    $iRank = 1;

    // Get top ranking users (100+)
    echo GetSection(100, NULL, $iRank, '#FFFFFF');

    // Get veterans (50 - 99)
    echo GetSection(50, 99, $iRank, '#FFFF00');

    // Get experienced (30 - 49)
    echo GetSection(30, 49, $iRank, '#FF0000');

    // Get normal (10 - 29)
    echo GetSection(10, 29, $iRank, '#0066FF');

    // Get rookies (0 - 9)
    echo GetSection(0, 9, $iRank, '#00FF00');

    ?>

    </table>
    <input type="submit" value="Submit">
    </form>
    </center>
    </center></div></td></tr></table>
    </BODY>
    </HTML>
     
    Wilkz, Nov 25, 2007 IP
  2. danzor

    danzor Peon

    Messages:
    208
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Looks like your old host had register_globals set to true and your new one doesn't.

    Change

    if($action == 'Submit' && $failsafe == 'ReallySubmit')
    Code (markup):
    to

    if($action == $_POST['Submit'] && $failsafe == $_POST['ReallySubmit'])
    Code (markup):
     
    danzor, Nov 25, 2007 IP
  3. Wilkz

    Wilkz Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I did as you suggested and now my page has this error when I go to it.


    MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Lost = , Draw = , TagWon = , TagLost = , TagDraw = , Titles = , LastRank = , St' at line 1
    Query: UPDATE Users SET Won = , Lost = , Draw = , TagWon = , TagLost = , TagDraw = , Titles = , LastRank = , Streak = 0 WHERE ID = 2
     
    Wilkz, Nov 25, 2007 IP
  4. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #4
    it seemed that you have lost all your variables, this would be hell if you have all your script set for through register_globals, i would suggest just enabling the register_globals directive(security discretion, depends on how many files will be affected) and also make sure to put quotes ' ' for all the string values that you want to insert in your database
     
    serialCoder, Nov 25, 2007 IP
  5. Wilkz

    Wilkz Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Where would I need to go to turn on register_globals? I'm not aware of turning it off. We moved to a new server.
     
    Wilkz, Nov 25, 2007 IP
  6. danzor

    danzor Peon

    Messages:
    208
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It would be something that your host would enable/disable in php.ini

    You can turn it on, although it is strongly advised not to.

    Put this at the top of your code
    ini_set('register_globals' 1);
    Code (markup):
     
    danzor, Nov 25, 2007 IP
  7. Wilkz

    Wilkz Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ok, just to clarify...I have to convince my host to turn it on by putting that line at the top of his php,ini file, or can I put that coding at the top of my own file to turn it on?
     
    Wilkz, Nov 25, 2007 IP
  8. danzor

    danzor Peon

    Messages:
    208
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Put it at the top of your PHP code
     
    danzor, Nov 25, 2007 IP