Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Richman
New Member
New Member



Joined: Jul 01, 2004
Posts: 10

PostPosted: Fri Jul 02, 2004 3:37 pm Reply with quote

What is the matter with my script, I am getting a parse error on line 4. But I do not see one.
Code:
<?php// Script - join.php

// This script adds a join entry to the database.

$page_title = "Join";
include ('templates/header.php');

if (isset ($_POST['submit'])) { // Handle the form.
   
   if (!strlen ($_POST['game_name']) > 0) {
      echo '<p><b>You forgot your Game Name!</b></p>';
      $_POST['game_name'] = FALSE;
   }

   if (!strlen ($_POST['name']) > 0) {
      echo '<p><b>You forgot your Name!</b></p>';
      $_POST['name'] = FALSE;
   }

   if (!strlen ($_POST['email']) > 0) {
      echo '<p><b>You forgot your E-mail Address!</b></p>';
      $_POST['email'] = FALSE;
   }

   if (!strlen ($_POST['fav_class']) > 0) {
      echo '<p><b>You forgot your Favorite Class!</b></p>';
      $_POST['fav_class'] = FALSE;
   }

   if (!strlen ($_POST['fav_vehicle']) > 0) {
      echo '<p><b>You forgot your Favorite Vehicle!</b></p>';
      $_POST['fav_vehicle'] = FALSE;
   }

   if (!strlen ($_POST['reason_join']) > 0) {
      echo '<p><b>You forgot your Reason To Join!</b></p>';
      $_POST['reason_join'] = FALSE;
   }

   if ($_POST['game_name'] && $_POST['name'] && $_POST['email'] && $_POST['fav_class'] && $_POST['fav_vehicle'] && $_POST['reason_join']) {

      // Connect to MySQL and select a database.
      include ('content/mysqlconnect.php');

      // Define the query.
      $query = "INSERT INTO join_form (join_id, game_name, name, email, aim, fav_class, fav_vehicle, reason_join, date_entered) VALUES (0, '{$_POST['game_name']}', '{$_POST['name']}', '{$_POST['email']}', '{$_POST['aim']}', '{$_POST['fav_class']}', '{$_POST['fav_vehicle']}', '{$_POST['reason_join']}', NOW())";

      // Execute the query.
      if (@mysql_query ($query)) {
         print "<p>Your join request will be processed.</p>";
      } else {
         print "<p>Could not add the join request because: <b>" . mysql_error() . "</b>.</p>";
      }

      mysql_close();

   } else {

   die ('<p><b>Please fill form out again!</b></p>');

   }

} else {

   // Display the form.
?>
<font size="2" face="Arial, Helvetica, sans-serif">
<form action="join.php" method="post">
<p>Game Name: <input type="text" name="game_name" size="20" maxlength="100" /></p>
<p>Real Name: <input type="text" name="name" size="20" maxlength="100" /></p>
<p>E-mail Address: <input type="text" name="email" size="20" maxlength="100" /></p>
<p>AIM Screen Name: <input type="text" name="aim" size="20" maxlength="100" />
<p>Favorite Class:
<select name="fav_class">
<option value="">Pick One</option>
<?php
   $classes = array ('Medic', 'Engineer', 'Anti-Tank', 'Assault', 'Scout');
   foreach ($classes as $v) {
      echo "<option value=\"$v\">$v</option>\n";
   }
?>
</select></p>
<p>Favorite Vehicle:
<select name="fav_vehicle">
<option value="">Pick One</option>
<?php
   $vehicles = array ('Heavy Tank', 'Light Tank', 'Half Track', 'Heavy bomber', 'Light Bomber', 'Jeep', 'Fighter', 'Carrier', 'Destroyer', 'Artillery', 'Cruiser', 'Submarine', 'Landing Craft');
   foreach ($vehicles as $v) {
      echo "<option value=\"$v\">$v</option>\n";
   }
?>
</select>
<p>Reason You Want To Join: <textarea name="reason_join" columns="40" rows="5" maxlength="255"></textarea></p>
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />
</form>
</font>
<?php
}

include ('templates/footer.php');
?>
 
View user's profile Send private message
Richman







PostPosted: Fri Jul 02, 2004 4:17 pm Reply with quote

Never mind, i figured it out... Rolling Eyes
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Fri Jul 02, 2004 4:31 pm Reply with quote

My guess would have been the // after the <?php. Was that it?
 
View user's profile Send private message
Richman







PostPosted: Fri Jul 02, 2004 4:32 pm Reply with quote

Hahaha, yep.
 
Raven







PostPosted: Fri Jul 02, 2004 4:35 pm Reply with quote

For a slight gain in efficiency, you might want to use empty() for your edit check. Use this
if (empty($_POST['game_name']))
instead of
if (!strlen ($_POST['game_name']) > 0)
 
Richman







PostPosted: Fri Jul 02, 2004 5:10 pm Reply with quote

Thanks for the advice
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

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 ©