Constants

  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

Below, is the code from a joining page I'm setting up, but I keep getting the following line appearing in the Login box

<br><b>Warning</b>: Undefined variable: form in <b>C:\Intranet\testing\php\example\join.php</b> on line <b>90</b><br>

here is the code, hope somebody can help.

Thanks,
Tommy

Code: [ Select ]

<?php

include("dblib.inc");
include("clublib.inc");

$message="";

if ( isset( $actionflag ) && $actionflag=="join")

    {

    if ( empty( $form['login'] ) ||
        
        empty( $form['password'] ) ||
        empty( $form['password'] ) )
        
        $message .= "you must fill in all fields<br>\n";

    if ( $form['password'] != $form['password2'] )

        $message .= "Your passwords did not match<br>\n";

    if ( strlen( $form['password'] ) > 8 )

        $message.= "Your password must be less than 8 characters<br>\n";

    if ( strlen( $form['login'] ) > 8 )
    
        $message .= "Your login ID must be less than 8 characters<br>\n";

    if ( getRow( "clubs", "login", $form['login'] ) )
    
        $message .= "login \"$form[login]\" already exists. Try another<br>\n";

    if ( $message == "" ) //we found no errors

        {

        $id = newUser( $form[login], $form[password] );
        cleanMemberSession( $id, $form[login], $form[password] );
        header( "Location: updateclub.php?".SID );
        exit;

        }

    }

?>

<html>
<head>
<title>Join!</title>
</head>

<body>

<?php

include("publicnav.inc");

?>

<p>

<h1> Join </h1>

<?php

if ( $message != "" )

    {

    print "<b>$message</b><p>";

    }

?>

<p>

<form action="<?php print $PHP_SELF;?>">
<input type="hidden" name="actionflag" value="join">
<input type="hidden" name="<?php print session_name() ?>" value="<?php print session_id() ?>"

</p>

<p>

Login: <br>
<input type="text" name="form[login]" value="<?php print $form['login'] ?>" maxlength=8>

</p>
<p>

Password: <br>

<input type="password" name="form[password]" value="" maxlength=8>

</p>
<p>

Confirm Password: <br>

<input type="password" name="form[password2]" value="" maxlength=8>

</p>
<p>

<input type="submit" value="update">

</p>
</form>

</body>
</html>
  1. <?php
  2. include("dblib.inc");
  3. include("clublib.inc");
  4. $message="";
  5. if ( isset( $actionflag ) && $actionflag=="join")
  6.     {
  7.     if ( empty( $form['login'] ) ||
  8.         
  9.         empty( $form['password'] ) ||
  10.         empty( $form['password'] ) )
  11.         
  12.         $message .= "you must fill in all fields<br>\n";
  13.     if ( $form['password'] != $form['password2'] )
  14.         $message .= "Your passwords did not match<br>\n";
  15.     if ( strlen( $form['password'] ) > 8 )
  16.         $message.= "Your password must be less than 8 characters<br>\n";
  17.     if ( strlen( $form['login'] ) > 8 )
  18.     
  19.         $message .= "Your login ID must be less than 8 characters<br>\n";
  20.     if ( getRow( "clubs", "login", $form['login'] ) )
  21.     
  22.         $message .= "login \"$form[login]\" already exists. Try another<br>\n";
  23.     if ( $message == "" ) //we found no errors
  24.         {
  25.         $id = newUser( $form[login], $form[password] );
  26.         cleanMemberSession( $id, $form[login], $form[password] );
  27.         header( "Location: updateclub.php?".SID );
  28.         exit;
  29.         }
  30.     }
  31. ?>
  32. <html>
  33. <head>
  34. <title>Join!</title>
  35. </head>
  36. <body>
  37. <?php
  38. include("publicnav.inc");
  39. ?>
  40. <p>
  41. <h1> Join </h1>
  42. <?php
  43. if ( $message != "" )
  44.     {
  45.     print "<b>$message</b><p>";
  46.     }
  47. ?>
  48. <p>
  49. <form action="<?php print $PHP_SELF;?>">
  50. <input type="hidden" name="actionflag" value="join">
  51. <input type="hidden" name="<?php print session_name() ?>" value="<?php print session_id() ?>"
  52. </p>
  53. <p>
  54. Login: <br>
  55. <input type="text" name="form[login]" value="<?php print $form['login'] ?>" maxlength=8>
  56. </p>
  57. <p>
  58. Password: <br>
  59. <input type="password" name="form[password]" value="" maxlength=8>
  60. </p>
  61. <p>
  62. Confirm Password: <br>
  63. <input type="password" name="form[password2]" value="" maxlength=8>
  64. </p>
  65. <p>
  66. <input type="submit" value="update">
  67. </p>
  68. </form>
  69. </body>
  70. </html>


[/code]
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

The problem is on this line according to the error message you got...I don't write PHP so I can't offer a definitive answer but the way you call login with ' ' and w/out ' '...looks problematic

Code: [ Select ]
name="form[login]" value="<?php print $form['login']
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

The problem is that you are calling the form variable before it has been initialized.
after the if form is submitted statement add an else statement that declares form as an array

But then again it will give you an undefined index error.

Umm okay so then do a check before printing the $form variable

PHP Code: [ Select ]
 
if (!empty($form['key']){
 
  //print values here
 
}else{
 
  //print empty string
 
}
 
 
  1.  
  2. if (!empty($form['key']){
  3.  
  4.   //print values here
  5.  
  6. }else{
  7.  
  8.   //print empty string
  9.  
  10. }
  11.  
  12.  


I think this should work
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

sorry bout this mate but I'm not altogether sure I know where you want me to put that section of code :?

do you mean at the top of the first IF Statement?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

PHP Code: [ Select ]
<input type="text" name="form[login]" value="<?php
 
if (!empty($form['login'])){
 
  print $form['login'];
 
}
 
>" maxlength=8>
 
 
  1. <input type="text" name="form[login]" value="<?php
  2.  
  3. if (!empty($form['login'])){
  4.  
  5.   print $form['login'];
  6.  
  7. }
  8.  
  9. >" maxlength=8>
  10.  
  11.  


Put this code where you are telling php to print the value to the text box

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 44 guests
  • 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 post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.