Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
Doulos
Life Cycles Becoming CPU Cycles



Joined: Jun 06, 2005
Posts: 732

PostPosted: Fri Aug 15, 2014 12:59 pm Reply with quote

Any suggestions would help with fixing these errors thrown by a custom module. I know enough about php, sql, etc to get myself a white page - maybe not that bad, but close. Using RN2.51, PHP 5.4.17, mysql 5.5.37-cll, ficubice theme.

I have successfully gotten rid of all php errors except these:
Quote:
[15-Aug-2014 14:29:55 America/New_York] PHP Notice: Undefined variable: desire_name in /home/meme/public_html/modules/Joinus/index.php on line 95
[15-Aug-2014 14:29:55 America/New_York] PHP Notice: Undefined variable: real_name in /home/meme/public_html/modules/Joinus/index.php on line 99
[15-Aug-2014 14:29:55 America/New_York] PHP Notice: Undefined variable: steam_id in /home/meme/public_html/modules/Joinus/index.php on line 108
[15-Aug-2014 14:29:55 America/New_York] PHP Notice: Undefined variable: Age in /home/meme/public_html/modules/Joinus/index.php on line 120
[15-Aug-2014 14:29:55 America/New_York] PHP Notice: Undefined variable: Gender in /home/meme/public_html/modules/Joinus/index.php on line 131
[15-Aug-2014 14:29:55 America/New_York] PHP Notice: Undefined variable: Location in /home/meme/public_html/modules/Joinus/index.php on line 150
[15-Aug-2014 14:29:55 America/New_York] PHP Notice: Undefined variable: message in /home/meme/public_html/modules/Joinus/index.php on line 154
[15-Aug-2014 14:29:55 America/New_York] PHP Notice: Undefined variable: opi in /home/meme/public_html/modules/Joinus/index.php on line 164

Here is the module:
Code:
<?php

/************************************************************************/
/* PHP-NUKE: NUKE4GAMERS Clan Join Form                                 */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi                                */
/* http://phpnuke.org & http://www.nuke4gamers.com                      */
/*                                                                      */
/* This program is free software. You can redistribute it               */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/* Need help with the block then drop by http://www.nuke4gamers.com     */
/************************************************************************/



if (!defined('MODULE_FILE')) {

   die ("You can't access this file directly...");

}



require_once("mainfile.php");

$module_name = basename(dirname(__FILE__));

get_lang($module_name);



/**********************************/

/* Configuration                  */

/*                                */

/* You can change this:           */

/* $index = 0; (right side off)   */

/**********************************/

$index = 1;

$subject = "$sitename "._JOINUS."";

/**********************************/

include("header.php");
$cookie[0] = intval($cookie[0]);

if ($cookie[1] != "") {
   $row = $db->sql_fetchrow($db->sql_query("SELECT name, username, user_email FROM ".$user_prefix."_users WHERE user_id='$cookie[0]'"));
   if ($row['name'] != "") {
      $sender_name = $row['username'];   
      } else {
         $sender_name = $row['username'];
      }
         $sender_email = $row['user_email'];
         }



$form_block = "

    <center><font size=\"6\"><b>$sitename</font><br /><font size=\"4\">"._JUSTITLE."</b></font>

    <br /><br /><font size=\"2\">"._JUSNOTE."</font>
    <br /><br />
     <table>
<tr> 
<td>
    <font class=\"content\">

    <FORM METHOD=\"post\" ACTION=\"modules.php?name=$module_name\">

    <P><strong>"._YOURNAME.":</strong>&nbsp&nbsp;<font size=\"3\">$sender_name</font></p>
   
   <P><strong>"._YOUREMAIL.":</strong>&nbsp&nbsp;<font size=\"3\">$sender_email</font></p>

 <P><strong>"._DESIRENAME.":</strong>&nbsp&nbsp;   

    <INPUT type=\"text\" NAME=\"desire_name\" VALUE=\"$desire_name\" SIZE=50></p>

    <P><strong>"._YOURFIRSTNAME.":</strong>&nbsp&nbsp;   

    <INPUT type=\"text\" NAME=\"real_name\" VALUE=\"$real_name\" SIZE=20></p>
   
    <P><strong>"._YOURSTEAMID.":</strong>&nbsp&nbsp;   

    <INPUT type=\"text\" NAME=\"steam_id\" VALUE=\"$steam_id\" SIZE=20></p>

</TR>
</TABLE></p>
<P><TABLE width=20% border=0 cellpadding=0 cellspacing=0 align='center'>
<TR>
<TD><strong>Age:</strong></TD>
<TD><select name=\"Age\" value=\"$Age\">
    <option>Under 18</option>
    <option>18 to 24</option>
    <option>25-30</option>
   <option>Over 30</option>   
    </select></TD>
</TR>

</TABLE></p>
<P><TABLE width=20% border=0 cellpadding=0 cellspacing=0 align='center'>
<TR>
<TD><strong>Gender:</strong></TD>
<TD><select name=\"Gender\" value=\"$Gender\">
    <option>Male</option>
    <option>Female</option>
   
    </select></TD>
</TR>

</TABLE></p>
<P><TABLE width=20% border=0 cellpadding=0 cellspacing=0 align='center'>
<TR valign=top>
<TD><strong>Location:</strong>
<TD><select name=\"Location\" value=\"$Location\" align=\"left\">
    <option>USA</option>
    <option>Canada</option>
    <option>Other</option>
       
    </select></TD>
   

</TR>
</TABLE></p>
   
   <P><strong>Tell us more about yourself and why you want to join us.</strong><br>

    <TEXTAREA NAME=\"message\" COLS=70 ROWS=15 WRAP=virtual>$message</TEXTAREA></p>

    <INPUT type=\"hidden\" name=\"opi\" value=\"ds\">

    <P><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\""._SEND."\"></p>

    </FORM></center>

";



OpenTable();

if ($opi != "ds") {

   echo "$form_block";

} elseif ($opi == "ds") {

   if ($sender_name == "") {

      $name_err = "<center><font class=\"option\"><b><i>"._JUSENTERNAME."</i></b></font></center><br>";

      $send = "no";

   }

   if ($real_name == "") {

      $name_err = "<center><font class=\"option\"><b><i>"._JUSENTERFIRSTNAME."</i></b></font></center><br>";

      $send = "no";

   }
   
   if ($desire_name == "") {

      $name_err = "<center><font class=\"option\"><b><i>"._JUSENTERDESIRENAME."</i></b></font></center><br>";

      $send = "no";

   }   

   if ($sender_email == "") {

      $email_err = "<center><font class=\"option\"><b><i>"._JUSENTEREMAIL."</i></b></font></center><br>";

      $send = "no";

   }

   if ($message == "") {

      $message_err = "<center><font class=\"option\"><b><i>"._JUSENTERMESSAGE."</i></b></font></center><br>";

      $send = "no";

   }
   
   if ($steam_id == "") {

      $message_err = "<center><font class=\"option\"><b><i>"._JUSENTERSTEAMID."</i></b></font></center><br>";

      $send = "no";

   }

   if ($send != "no") {

      $sender_name = removecrlf($sender_name);

      $sender_email = removecrlf($sender_email);
      
      $Location = removecrlf($Location);

      $msg = "$sitename\n\n";

      $msg .= ""._SENDERNAME.": $sender_name\n";

      $msg .= ""._YOURFIRSTNAME.": $real_name\n";
      
      $msg .= ""._DESIRENAME.": $desire_name\n";

      $msg .= ""._SENDEREMAIL.": $sender_email\n";
      
      $msg .= ""._YOURSTEAMID.": $steam_id\n";
      
      $msg .= "Age: $Age\n";
      
      $msg .= "Gender: $Gender\n";      
      
         $msg .= "Location: $Location\n";
   
      
//      $msg .= "Location: $sender_location\n";
      
//      $msg .= "Vent & Mic: $Mic\n";

      $msg .= ""._MESSAGE.": $message\n\n";

      $to = 'ricklynn@charter.net';
      
        $mailheaders = "From: [ Only registered users can see links on this board! Get registered or login! ]\n";

      $mailheaders .= "Reply-To: $sender_email\n\n";

      mail($to, $subject, $msg, $mailheaders);

      echo "<P><center>"._JUSMAILSENT."</center></p>";

      echo "<P><center>"._JUSTHANKSFORCONTACT."</center></p>";

   } elseif ($send == "no") {

      OpenTable2();

      echo "$name_err";

      echo "$email_err";

      echo "$message_err";

      CloseTable2();

      echo "<br><br>";

      echo "$form_block";

   }

}
CloseTable();

include("footer.php");

?>


Thanks
 
View user's profile Send private message
neralex
Site Admin



Joined: Aug 22, 2007
Posts: 1772

PostPosted: Fri Aug 15, 2014 2:49 pm Reply with quote

As it is written in the error messages, you should not let the variables undefined. If you are using the variables in if-statesments, then make sure you have for all used variables an fallback if is it no in use. You could do this inside and before the if-statement.

Example:

php Code:
if ($variable == 'x') {

$value = '1';
} elseif ($variable == 'y') {
$value = '2';
}


Now is the 1st question, what is if $variable is not defined?

php Code:
if (!isset($variable)) $variable = '';


if ($variable == 'x') {
$value = '1';
} elseif ($variable == 'y') {
$value = '2';
}


Now we have a fallback for $variable but what is with $value if $variable isn't x or y?

php Code:
if (!isset($variable)) $variable = '';


if ($variable == 'x') {
$value = '1';
} elseif ($variable == 'y') {
$value = '2';
} else {
$value = '';
}


If $value also used in other statements or functions you could go the first way like this:

php Code:
if (!isset($variable)) $variable = '';

if (!isset($value)) $value = '';

if ($variable == 'x') {
$value = '1';
} elseif ($variable == 'y') {
$value = '2';
}


Wink

_________________
Github: RavenNuke 
View user's profile Send private message
Doulos







PostPosted: Mon Aug 18, 2014 12:08 pm Reply with quote

Thanks for your reply but as I said I am ignorant when it comes to PHP so I am not sure how to use your answer. The variable in question are not being used in an "if" but inside a <form>

For instance:

$form_block = "<form method><P><strong>"._DESIRENAME.":</strong>&nbsp&nbsp;

<INPUT type=\"text\" NAME=\"desire_name\" VALUE=\"$desire_name\" SIZE=50></p></form>";

_DESIRENAME is defined in language file, but $desire_name throws an error

Quote:
[18-Aug-2014 13:40:12 America/New_York] PHP Notice: Undefined variable: desire_name in /home/m3/public_html/modules/joinus/index.php on line 88



I really appreciate your reply.
 
neralex







PostPosted: Tue Aug 19, 2014 2:07 am Reply with quote

The formblock is inside a if-statement and its exaclty the same way. The form-tag is only a part of the html markup for the client side.

But your module is very old and the code is really outdated. It needs a re-coding. I would split the module in two functions with curent filterings. Maybe if i have time for that today, i will try to recode it for RN.


Last edited by neralex on Fri Aug 22, 2014 9:02 am; edited 1 time in total 
Doulos







PostPosted: Tue Aug 19, 2014 10:57 am Reply with quote

I tried rewriting it myself using example from the internet but could not get it to send all the information like the original does.

I work 60+ hours a week so I don't really have time now to learn PHP. For instance, I spent hours going through the Donations modules one error at a time fixing something that probably could have be fixed in 20 mins if I knew what I was doing.

Thanks for you reply.
 
neralex







PostPosted: Tue Aug 19, 2014 12:43 pm Reply with quote

Try this an report errors if you will get some of them, please!
[ Only registered users can see links on this board! Get registered or login! ]

Add these lines to the language file of the module:

php Code:
if(!defined('_YOURAGE')) define('_YOURAGE','Age');

if(!defined('_YOURGENDER')) define('_YOURGENDER','Gender');
if(!defined('_YOURLOCATION')) define('_YOURLOCATION','Location');
if(!defined('_TELLUSMORE')) define('_TELLUSMORE','Tell us more about yourself and why you want to join us');


After that you can delete these 4 lines from the index.php!
 
Doulos







PostPosted: Tue Aug 19, 2014 3:06 pm Reply with quote

Whoa, I certainly didn't expect you, or anyone, to go to that much work. Thank-you, thank-you, thank-you.
 
neralex







PostPosted: Tue Aug 19, 2014 3:15 pm Reply with quote

No worries, it was not hard to code. Test it please, i have it only written but not tested. If you should get errors, please post the error-messages or if things will not work.

Edit: Download the gist again and replace the file, please! Because i have found some issues - that should be fixed now. Nobody is perfect... Wink
 
Doulos







PostPosted: Tue Aug 19, 2014 3:29 pm Reply with quote

Module worked with one error:

Quote:
PHP Notice: Undefined variable: validmail in /home/meme/public_html/modules/Join_us/index.php on line 94


I copied what you did and added
Code:
if (!isset($validmail)) $validmail = '';


Changed text sizes, ran module and it works great without any errors. I cannot thank you enough. PM me an email address and I will send you some compensation - happy to do so.

Thanks again.
 
neralex







PostPosted: Tue Aug 19, 2014 3:39 pm Reply with quote

Ok wait, that is not the solution, i have the gist updated again:
[ Only registered users can see links on this board! Get registered or login! ]

Replace the file again, please! Test it also, if you leave some needed fields empty.
 
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1122

PostPosted: Fri Aug 22, 2014 2:50 am Reply with quote

I just took a fast view of what Neralex has been changed from this old module and it is amazing how efficient and clean restoration he has been made. We should follow the same path to convert or code any block, module, addons, themes. etc. in the future of Ravennuke.

:clap: speedtype
 
View user's profile Send private message
Doulos







PostPosted: Fri Aug 22, 2014 9:18 am Reply with quote

neralex, thanks. No errors. Unfortunately, I will need to go through all my other custom modules that I modified to get rid of errors to make sure I didn't use the same method to "fix" them.

Thanks again neralex.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©