Jump to content

[SOLVED] Beginner Project, small problem holding me up


Stagnate

Recommended Posts

Hey guys,

 

My project is a small one to get started with PHP, I hope to build this up from a simple framework that I am currently working on.

 

Im trying to make a site my myself and friends to add events to such as parties/dinners etc. Anyone can add to the site without a username and password but an activater is sent to the persons email so it can be added or monitored. I give each entry a random value to make them unique... This is where my problem is at.

 

<H1>STEP1</H1>



<form action="connect.php" method="post">
Name
<br>
<input type="text" name="name" size="20" />
<br>
<br />

<?php


Function ShowFromDate($year_interval,$YearIntervalType) { 
GLOBAL $day,$month,$year; 

//DAY 
echo "<select name=day>\n"; 
$i=1; 
$CurrDay=date("d"); 
If(!IsSet($day)) $day=$CurrDay; 
while ($i <= 31) 
      { 
       If(IsSet($day)) { 
         If($day == $i || ($i == substr($day,1,1) && (substr($day,0,1) == 0))) { 
                  echo"<option selected> $day\n"; 
                  $i++; 
         }Else{ 
                If($i<10) { 
                   echo "<option> 0$i\n"; 
                }Else { 
                   echo "<option> $i\n"; 
                } 
                $i++; 
         } 
       }Else { 
              If($i == $CurrDay) 
                If($i<10) { 
                   echo "<option selected> 0$i\n"; 
                }Else { 
                   echo"<option selected> $i\n"; 
                } 
              Else { 
                If($i<10) { 
                   echo "<option> 0$i\n"; 
                }Else { 
                   echo "<option> $i\n"; 
                } 
              } 
              $i++; 
       } 
      } 
echo "</select>\n"; 

//MONTH 
echo " / <select name=month>\n"; 
$i=1; 
$CurrMonth=date("m"); 
while ($i <= 12) 
     { 
      If(IsSet($month)) { 
         If($month == $i || ($i == substr($month,1,1) && (substr($month,0,1) == 0))) { 
            echo"<option selected> $month\n"; 
            $i++; 
         }Else{ 
            If($i<10) { 
               echo "<option> 0$i\n"; 
            }Else { 
               echo "<option> $i\n"; 
            } 
            $i++; 
         } 
      }Else { 
            If($i == $CurrMonth) { 
              If($i<10) { 
                 echo "<option selected> 0$i\n"; 
              }Else { 
                 echo "<option selected> $i\n"; 
              } 
            }Else { 
              If($i<10){ 
                 echo "<option> 0$i\n"; 
              }Else { 
                 echo "<option> $i\n"; 
              } 
            } 
            $i++; 
      } 
} 
  echo "</select>\n"; 

//YEAR 
  echo " / <select name=year>\n"; 
  $CurrYear=date("Y"); 
  If($YearIntervalType == "Past") { 
      $i=$CurrYear-$year_interval+1; 
      while ($i <= $CurrYear) 
           { 
            If($i == $year) { 
               echo "<option selected> $i\n"; 
            }ElseIf ($i == $CurrYear && !IsSet($year)) { 
               echo "<option selected> $i\n"; 
            }Else { 
               echo "<option> $i\n"; 
            } 
            $i++; 
           } 
       echo "</select>\n"; 
  } 
  If($YearIntervalType == "Future") { 
      $i=$CurrYear+$year_interval; 
      while ($CurrYear < $i) 
           { 
            if ($year == $CurrYear) echo "<option selected> $CurrYear\n"; 
              else echo "<option> $CurrYear\n"; 
            $CurrYear++; 
           } 
       echo "</select>\n"; 
  } 
  If($YearIntervalType == "Both") { 
      $i=$CurrYear-$year_interval+1; 
      while ($i < $CurrYear+$year_interval) 
           { 
            if ($i == $CurrYear) echo "<option selected> $i\n"; 
              else echo "<option> $i\n"; 
            $i++; 
           } 
       echo "</select>\n"; 
  } 
} 

//Ussage Example : 
ShowFromDate(4,"Future"); 
?>

<br>
<br>
    
Description<BR>
<TEXTAREA NAME="description" COLS=40 ROWS=6></TEXTAREA>

<br>
<br>
Address<br>
<input type="text" name="address" size="20" />   
    
<br>
<br>
    
    
Email<br>
<input type="text" name="email" size="20" />

<br>
<br>
<?php
function RandomValue() {

    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $pass = '' ;

    while ($i <= 7) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }

    return $pass;

}

// Usage
$eventid = RandomValue();
echo "Your random event id is: $eventid";

?>
<br>
<br>    
<input type="submit" value="Store in database" />
<input type="reset" value="Reset fields" />
</form>

 

 

connect.php

 

<H1>STEP2</H1>

<?php
//get the form information
$name = $_POST['name'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$description = $_POST['description'];
$address = $_POST['address'];
$email = $_POST['email'];
$eventid = $_POST['eventid'];

//connecting
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("partyplanner") or die(mysql_error());

//inserting the data
mysql_query("INSERT INTO events 
(name, day, month, year, description, active, email, eventid) VALUES('$name', '$day', '$month', '$year', '$description', '0', '$email', '$eventid') ") 
or die(mysql_error());  

echo "<strong>The Information was submitted but not yet activated.</strong> <br><br>Check you email";

?>
<br><br><hr>
<?php
echo "<H3>$name</H3>$day, $month $year";
echo "<br><br>";
echo "$description";
echo "<br><br>";
echo "$address";
echo "<br><br>";
echo "$email";
echo "<br><br>";
echo "$eventid";
?>
<br><br><hr>


<?php
/*
$recipient = '$email';
$subject = '$name';
$message = 'Greetings,'
."\n\n\t".'<A HREF=\"mailto:$email\">I have checked this information, activate now</A>'
."\n\n".'Thanks';
$headers = 'From: noreply@partyplanner'."\r\n";

if (mail($recipient, $subject, $message, $headers)) {
echo 'Mail Sent';
} else {
echo 'Mail NOT Sent';
}
*/
?>

<a href="index.php">Return Home</a>

 

The problem I am having is that I cant get the $eventid to post through to connect.php.

 

I must stress that I am a beginner so my code is probably horrible :) Any tips are greatly appreciated

Link to comment
Share on other sites

Why don't you just do this?

 

$name = $_POST['name'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$description = $_POST['description'];
$address = $_POST['address'];
$email = $_POST['email'];
$eventid = rand(1,90000);

 

Also, what is the event id for?

Link to comment
Share on other sites

I wanted to have an event ID for each event for the activation, so when the email gets sent to the person how uploads it so that the event can be activated :S. Initially each event as it gets uploaded is set to Active=0, the link that is generated by the eventid sets the active to 1 and it can be seen.

 

I dnt want to use just the Auto-incremented because someone could just go through and activate 1,2,3,4....

Link to comment
Share on other sites

Ok I got it :) Thanks man, I didnt realise that variables must be put into components :). Still got lots to learn it would seem.

 

<H1>STEP1</H1>



<form action="connect.php" method="post">
Name
<br>
<input type="text" name="name" size="20" />
<br>
<br />

<?php


Function ShowFromDate($year_interval,$YearIntervalType) { 
GLOBAL $day,$month,$year; 

//DAY 
echo "<select name=day>\n"; 
$i=1; 
$CurrDay=date("d"); 
If(!IsSet($day)) $day=$CurrDay; 
while ($i <= 31) 
     { 
      If(IsSet($day)) { 
        If($day == $i || ($i == substr($day,1,1) && (substr($day,0,1) == 0))) { 
                 echo"<option selected> $day\n"; 
                 $i++; 
        }Else{ 
               If($i<10) { 
                  echo "<option> 0$i\n"; 
               }Else { 
                  echo "<option> $i\n"; 
               } 
               $i++; 
        } 
      }Else { 
             If($i == $CurrDay) 
               If($i<10) { 
                  echo "<option selected> 0$i\n"; 
               }Else { 
                  echo"<option selected> $i\n"; 
               } 
             Else { 
               If($i<10) { 
                  echo "<option> 0$i\n"; 
               }Else { 
                  echo "<option> $i\n"; 
               } 
             } 
             $i++; 
      } 
     } 
echo "</select>\n"; 

//MONTH 
echo " / <select name=month>\n"; 
$i=1; 
$CurrMonth=date("m"); 
while ($i <= 12) 
    { 
     If(IsSet($month)) { 
        If($month == $i || ($i == substr($month,1,1) && (substr($month,0,1) == 0))) { 
           echo"<option selected> $month\n"; 
           $i++; 
        }Else{ 
           If($i<10) { 
              echo "<option> 0$i\n"; 
           }Else { 
              echo "<option> $i\n"; 
           } 
           $i++; 
        } 
     }Else { 
           If($i == $CurrMonth) { 
             If($i<10) { 
                echo "<option selected> 0$i\n"; 
             }Else { 
                echo "<option selected> $i\n"; 
             } 
           }Else { 
             If($i<10){ 
                echo "<option> 0$i\n"; 
             }Else { 
                echo "<option> $i\n"; 
             } 
           } 
           $i++; 
     } 
} 
 echo "</select>\n"; 

//YEAR 
 echo " / <select name=year>\n"; 
 $CurrYear=date("Y"); 
 If($YearIntervalType == "Past") { 
     $i=$CurrYear-$year_interval+1; 
     while ($i <= $CurrYear) 
          { 
           If($i == $year) { 
              echo "<option selected> $i\n"; 
           }ElseIf ($i == $CurrYear && !IsSet($year)) { 
              echo "<option selected> $i\n"; 
           }Else { 
              echo "<option> $i\n"; 
           } 
           $i++; 
          } 
      echo "</select>\n"; 
 } 
 If($YearIntervalType == "Future") { 
     $i=$CurrYear+$year_interval; 
     while ($CurrYear < $i) 
          { 
           if ($year == $CurrYear) echo "<option selected> $CurrYear\n"; 
             else echo "<option> $CurrYear\n"; 
           $CurrYear++; 
          } 
      echo "</select>\n"; 
 } 
 If($YearIntervalType == "Both") { 
     $i=$CurrYear-$year_interval+1; 
     while ($i < $CurrYear+$year_interval) 
          { 
           if ($i == $CurrYear) echo "<option selected> $i\n"; 
             else echo "<option> $i\n"; 
           $i++; 
          } 
      echo "</select>\n"; 
 } 
} 

//Ussage Example : 
ShowFromDate(4,"Future"); 
?>

<br>
<br>
   
Description<BR>
<TEXTAREA NAME="description" COLS=40 ROWS=6></TEXTAREA>

<br>
<br>
Address<br>
<input type="text" name="address" size="20" />   
   
<br>
<br>
   
   
Email<br>
<input type="text" name="email" size="20" />

<br>
<br>
<?php
function RandomValue() {

   $chars = "abcdefghijkmnopqrstuvwxyz023456789";
   srand((double)microtime()*1000000);
   $i = 0;
   $pass = '' ;

   while ($i <= 7) {
       $num = rand() % 33;
       $tmp = substr($chars, $num, 1);
       $pass = $pass . $tmp;
       $i++;
   }

   return $pass;

}

// Usage
$ran = RandomValue();

?>

<input name="eventid" type="hidden" value="<?php echo "$ran"; ?>" />
<br>
<br>    
<input type="submit" value="Store in database" />
<input type="reset" value="Reset fields" />
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.