+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Smart Froms

  1. #1
    lh3vs3 is offline x10Hosting Member lh3vs3 is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    8

    Smart Froms

    Hi,
    I am making a form that inserts people into a database and if values is not correct it returns erros.
    But I am getting this error:
    Parse error: syntax error, unexpected $end in /home/lh3vs3/public_html/insert.php on line 106

    But there is no line 106...
    here is the code:
    form
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!--
    Design by Free CSS Templates
    http://www.freecsstemplates.org
    Released for free under a Creative Commons Attribution 2.5 License
    Name       : Free Port
    Description: A two-column, fixed-width design for 1024x768 screen resolutions.
    Version    : 1.0
    Released   : 20090122
    -->
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Inscription</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <?php
    include("header.php");
    ?>
    <div id="page">
     <div id="content">
      <div class="post">
       <h2 class="title">Joindre le Ligue</h2>
       <p class="date"><?php echo date("Y.m.d"); ?></p>
       <div class="entry">
    <form name="submit_article" method="post" action="insert.php">
            <p>&nbsp;Nom de Famille:<br/>
              <input name="lname" type="text">
            </p>
            <p>&nbsp;Pr&eacute;nom:<br/>
         <input name="fname" type="text">
            </p>
             <p>&nbsp;E-Mail:<br/>
         <input name="email" type="text">
            </p>
            <p>&nbsp;&Acirc;ge:<br/>
                  <select name="age">
              <option value="14">14</option>
              <option value="15">15</option>
              <option value="16">16</option>
              <option value="17">17</option>
              <option value="18">18</option>
              <option value="19">19</option>
        </select>
            </p>
             <p>&nbsp;Quartier:<br/>
                  <select name="quartier">
              <option value="Chomedy">Chomedy</option>
              <option value="St-Doronthe">St-Doronthe</option>
              <option value="Laval-Nord">Laval-Nord6</option>
              <option value="Laval-Des-Rapides">Laval-Des-Rapides</option>
        </select>
            </p>
            <p>
              <input type="submit" name="Submit" value="Joindre">
            </p>
            <p class='links'>
            </p>
    </form></div>
      </div>
     </div>
     <!-- end #content -->
    <?php
    include("sidebar.php");
    ?>
     <!-- end #sidebar -->
     <div style="clear: both;">&nbsp;</div>
    </div>
    <!-- end #page -->
    <?php
    include("copyright.php");
    ?>
    <!-- end #footer -->
    </div>
    </body>
    </html>
    insert.php
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!--
    Design by Free CSS Templates
    http://www.freecsstemplates.org
    Released for free under a Creative Commons Attribution 2.5 License
    Name       : Free Port
    Description: A two-column, fixed-width design for 1024x768 screen resolutions.
    Version    : 1.0
    Released   : 20090122
    -->
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Votre Inscription</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <?php
    include("header.php");
    ?>
    <div id="page">
     <div id="content">
      <div class="post">
       <h2 class="title">Votre Inscription</h2>
       <p class="date"><?php echo date("Y.m.d"); ?></p>
       <div class="entry">
    <?php
    // first, connect to database and select table
    $link = mysql_connect ("localhost", "lh3vs3_ara", "1992arayugi")
    or die("mysql_error()");
    mysql_select_db ("lh3vs3_league", $link);
    $lname = $_POST['lname'];
    $fname = $_POST['fname'];
    $email = $_POST['email'];
    $age = $_POST['age'];
    $quartier = $_POST['quartier'];
    $error = '0';
    $result = mysql_query("SELECT * FROM `players` WHERE lname = '$lname'",$link);
    $retreive = mysql_fetch_array($result);
    $name = "" .$retreive['fname']. "";
    /* check if lname is entered */
      if(!$lname || strlen($lname = trim($lname)) == 0){
      echo "Veuillez entrez votre nom de famille";
      $error = '$error +1';
     }
    /*check if fname is entered */
      if(!$fname || strlen($fname = trim($fname)) == 0){
      echo "Veuillez entrez votre pr&eacute;nom";
      $error = '$error +1';
     }
    /* check if player already entered */
    elseif('$fname' == '$name'){
    echo "Vous &ecirc;tes d&eacute;j&agrave; enregistr&eacute;.";
    $error = '$error +1';
    }
    /*check if email is entered */
      if(!$email|| strlen($email = trim($email)) == 0){
      echo "Veuillez entrez votre email";
      $error = '$error +1';
      }
    else{
    /* check if email is valid */
    $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
    ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
    ."\.([a-z]{2,}){1}$";
    if(!eregi($regex,$subemail)){
    echo "Votre email n'est pas vailde.";
    $error = '$error +1';
     }
    if($error>0){
    echo "Veuillez retourner a la page d'inscription et r&eacute;essaye";
    }
    else{
    $player = "INSERT INTO `players` (`lname`, `fname`, `email`, `age`, `quartier`, `register_time`) VALUES ('$lname', '$fname','$email','$age','$quartier', NOW())";
    mysql_query($player) or die(mysql_error());
    $player_stats = "INSERT INTO `player_stats` (`lname`, `fname`, `goals`, `assists`, `points`, `plus/minus`, `pim`, `ppg`, `shg`, `evg`, `shots`, `shotsp`) VALUES ('$lname', '$fname', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0')";
    mysql_query($player_stats) or die(mysql_error());
    echo "<br/>Votre Inscription a &eacute;t&eacute; enregistr&eacute;<br/>";
    }
    ?>
       </div>
      </div>
     </div>
     <!-- end #content -->
    <?php
    include("sidebar.php");
    ?>
     <!-- end #sidebar -->
     <div style="clear: both;">&nbsp;</div>
    </div>
    <!-- end #page -->
    <?php
    include("copyright.php");
    ?>
    <!-- end #footer -->
    </div>
    </body>
    </html>

    thanks for your help,
    Ara

  2. #2
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,994

    Re: Smart Froms

    Unexpected $end means you're missing a closing bracket somewhere.

    My guess is it's right around here:

    Code:
    else{
    /* check if email is valid */
    $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
    ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
    ."\.([a-z]{2,}){1}$";
    if(!eregi($regex,$subemail)){
    echo "Votre email n'est pas vailde.";
    $error = '$error +1';
     }
    if($error>0){
    echo "Veuillez retourner a la page d'inscription et r&eacute;essaye";
    }
    else{
    $player = "INSERT INTO `players` (`lname`, `fname`, `email`, `age`, `quartier`, `register_time`) VALUES ('$lname', '$fname','$email','$age','$quartier', NOW())";
    mysql_query($player) or die(mysql_error());
    $player_stats = "INSERT INTO `player_stats` (`lname`, `fname`, `goals`, `assists`, `points`, `plus/minus`, `pim`, `ppg`, `shg`, `evg`, `shots`, `shotsp`) VALUES ('$lname', '$fname', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0')";
    mysql_query($player_stats) or die(mysql_error());
    echo "<br/>Votre Inscription a &eacute;t&eacute; enregistr&eacute;<br/>";
    }
    If you count, there's 4 {'s but only 3 }'s - there's a } bracket missing, in particular the one that's closing the very first Else statement.

    Course I'm not sure what the code does, so I'm not entirely sure where that missing } is supposed to go, but that sure looks like whats causing the problem.


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  3. #3
    lh3vs3 is offline x10Hosting Member lh3vs3 is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    8

    Re: Smart Froms

    OK thanks,
    it works now but I have another problem.
    My code is used to check errors from the form. And if it finds error it adds 1 to $error.
    And at the end it supposed to show the errors and tell the user to correct it.
    But now it shows the error, it says email is not valid, but it still gets inserted....

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Smart Froms

    $error = '$error +1';

    $error will always equal the string "$error + 1'. You can use ++$error to increase $error by one.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    lh3vs3 is offline x10Hosting Member lh3vs3 is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    8

    Re: Smart Froms

    Oh thanks alot.
    Ok I have another question with another form...
    this is the error I get:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lh3vs3/public_html/request_confirm.php on line 53

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lh3vs3/public_html/request_confirm.php on line 54

    this is the code:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!--
    Design by Free CSS Templates
    http://www.freecsstemplates.org
    Released for free under a Creative Commons Attribution 2.5 License
    
    Name       : Free Port
    Description: A two-column, fixed-width design for 1024x768 screen resolutions.
    Version    : 1.0
    Released   : 20090122
    
    -->
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>League de Hockey 3vs3</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <?php
    include("header.php");
    ?>
    <div id="page">
    	<div id="content">
    		<div class="post">
    
    			<h2 class='title'>Cr&eacute;er une &eacute;quipe</h2>
    			<p class='date'><?php echo date("Y.m.d"); ?></p>
    			<p class='meta'><em>Posted by Aravinthan </p>
    			<div class='entry'>
    <?php
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $teamname = $_POST['teamname'];
    $receiver = $_POST['receiver'];
    $link = mysql_connect ("localhost", "lh3vs3_ara", "1992arayugi")
    or die("mysql_error()");
    mysql_select_db ("lh3vs3_league", $link);
    /*check if fname is entered */
      if(!$fname|| strlen($fname = trim($fname)) == 0){
      echo "Veuillez entrez votre pr&eacute;nom";
       ++$error ;
     }
     /*check if lname is entered */
       if(!$lname|| strlen($lname = trim($lname)) == 0){
       echo "Veuillez entrez votre nom de famille";
        ++$error ;
     }
    /* check if player in a team*/
    $checkteam = "SELECT teamname FROM players WHERE fname= '$fname' AND lname = '$lname'";
    $retreive_team = mysql_fetch_array($checkteam);
    if(mysql_num_rows($checkteam)) {
      echo "Vous avez d&eacute;ja choisi votre nom d'&eacute;quipe:" .$retreive_team['teamname']. "";
    }
    else {
    $avai_team = mysql_query("SELECT * FROM `available_teams` ORDER BY teamname DESC",$link);
    while($teams = mysql_fetch_array($avai_team))
    {
    echo "<form method='post'>
    <select name='teamname'>";
    echo "<option value='" .$team['teamname']. "'>" .$team['teamname']. "</option>";
    echo "</select>";
    echo " <input type='submit' value='Confirmer'/>";
    }
    }
    if($error>0){
    echo "Veuillez retourner &agrave; la page de demande et r&eacute;essaye";
    }
    else{
    /* enter values into team_maker table */
    $result = mysql_query("SELECT * FROM `players` WHERE fname='$fname' AND  lname='$lname'",$link);
    $retreive = mysql_fetch_array($result);
    $asker = "" .$retreive['playerid']. "";
    mysql_query("INSERT INTO team_maker (asker, receiver, teamname, date)
    VALUES ('$asker', '$receiver','$teamname', NOW())");
    /* delete teamname from availabe_teams table */
    mysql_query("DELETE FROM `available_teams` WHERE teamname='$teamname'")
    or die(mysql_error());
    /* get email adress */
    $result1 = mysql_query("SELECT * FROM `players` WHERE playerid='$receiver'",$link);
    $retreive1 = mysql_fetch_array($result1);
    $email = "" .$retreive1['email']. "";
    /* send email */
    $to = "$email";
    $subject = "Demande de joindre une &eacute;quipe";
    $body = "$fname,$lname veut que vous jouez ensemble pour l'&eacute;quipe $teamname. Veuillez utiliser ce lien pour donner votre r&eacute;ponse: <a href='http://lh3vs3.x10hosting.com/view_request.php?asker=$asker&receiver=$receiver'>http://lh3vs3.x10hosting.com/team_maker.php?asker=$asker&receiver=$receiver</a>";
    if (mail($to, $subject, $body)) {
      echo("<p>Votre demande a &eacute;t&eacute; confirmer, vous receverez un courriel d&egrave;s que le joueur a r&eacute;pondu.</p>");
     } else {
      echo("<p>Il y a une probl&egrave;me pr&eacute;sentement. Veuillez re-&eacute;ssayer plus tard.</p>");
     }
     }
    ?>
    <p class='links'></p></div>
    
    
    		</div>
    	</div>
    	<!-- end #content -->
    <?php include("sidebar.php"); ?>
    	<!-- end #sidebar -->
    	<div style="clear: both;">&nbsp;</div>
    </div>
    <!-- end #page -->
    <?php
    include("copyright.php");
    ?>
    
    <!-- end #footer -->
    </div>
    </body>
    </html>
    Thanks for your help,
    Ara

  6. #6
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Smart Froms

    You have to submit the query before you can view the query results.

    Code:
    $checkteam = ....
    $result = mysql_query($checkteam);
    $retreive_team = mysql_fetch_assoc($result);
    I changed _array to _assoc on purpose. It is a much better practice to use an associative array rather than a numeric. If you add one more field to a table, _array will be messed up but _assoc will be fine.

    Also, I like to put linebreaks in my queries to make them easier to read:
    Code:
    mysql_query("
    SELECT * 
    FROM `available_teams` 
    ORDER BY teamname DESC");
    Not a big deal now, but if you make any more complicated queries, you may not be able to make sense of them later.
    Last edited by garrettroyce; 04-01-2009 at 07:55 PM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  7. #7
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,994

    Re: Smart Froms

    Quick note, difference between assoc and array is this:

    Assoc uses the column name, such as $row['username'].

    Array uses a number, such as $row[0].


    Hence why it gets a bit messy if you add a field to the table; it's fine if it's added at the end, but if you add it somewhere in the middle, the numbers go wonky


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,500

    Re: Smart Froms

    Note also that by default, the result of mysql_fetch_array has both associative and numbered indices. The OP already used associative indices along with mysql_fetch_array.

  9. #9
    lh3vs3 is offline x10Hosting Member lh3vs3 is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    8

    Re: Smart Froms

    THanks again guys,
    but there is another porblem.
    This is one if for a bad coding.
    So what I want the code to do is to make a request for another player.

    The visitor sees players who dont have team, and the choose which one they want in their team.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!--
    Design by Free CSS Templates
    http://www.freecsstemplates.org
    Released for free under a Creative Commons Attribution 2.5 License
    Name       : Free Port
    Description: A two-column, fixed-width design for 1024x768 screen resolutions.
    Version    : 1.0
    Released   : 20090122
    -->
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>League de Hockey 3vs3</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <?php
    include("header.php");
    ?>
    <div id="page">
     <div id="content">
      <div class="post">
    <?php
    $link = mysql_connect ("localhost", "lh3vs3_ara", "1992arayugi")
    or die("mysql_error()");
    mysql_select_db ("lh3vs3_league", $link);
    $result = mysql_query("SELECT * FROM `players` WHERE teamname = 'Not In one'  ORDER BY playerid",$link);
       echo "<h2 class='title'>Les Membres</h2>";
        echo "<p class='date'>"; echo date("Y.m.d");
        echo "</p>";
       echo "<p class='meta'><em>Posted by Aravinthan </p>";
          echo "<div class='entry'>";
     echo "<table border='0'>
       <tr>
        <th align='center'> Pr&eacute;nom </th>
        <th align='center'> Nom de Famille </th>
        <th align='center'> &Acirc;ge </th>
        <th align='center'> Quartier </th>
        <th align='center'> Date d'inscription </th>
        <th align='center'></th>
       </tr>";
    while($row = mysql_fetch_array($result))
    {
     echo "<tr>";
     echo "<td align='center'><a href='players.php?player=" .$row['playerid']. "'>" .$row['fname']. "</a></td>";
     echo "<td align='center'><a href='players.php?player=" .$row['playerid']. "'>" .$row['lname']. "</a></td>";
     echo "<td align='center'>" .$row['age']. "</td>";
     echo "<td align='center'>" .$row['quartier']. "</td>";
     echo "<td align='center'>" .$row['register_time']. "</td>";
     echo "<td align='center'><a href='request.php?playerid=".$row['playerid']. "'>Demander &agrave; ce joueur de se joindre &agrave; votre &eacute;quipe</td></tr>";
    }
    echo " <p class='links'></p></table></div>";
         ?>
      </div>
     </div>
     <!-- end #content -->
    <?php include("sidebar.php"); ?>
     <!-- end #sidebar -->
     <div style="clear: both;">&nbsp;</div>
    </div>
    <!-- end #page -->
    <?php
    include("copyright.php");
    ?>
    <!-- end #footer -->
    </div>
    </body>
    </html>
    Then they come to a form, where it asks their family and first name:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!--
    Design by Free CSS Templates
    http://www.freecsstemplates.org
    Released for free under a Creative Commons Attribution 2.5 License
    Name       : Free Port
    Description: A two-column, fixed-width design for 1024x768 screen resolutions.
    Version    : 1.0
    Released   : 20090122
    -->
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>League de Hockey 3vs3</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <?php
    include("header.php");
    ?>
    <div id="page">
     <div id="content">
      <div class="post">
    <?php $playerid = $GET_['playerid']; ?>
       <h2 class='title'>Cr&eacute;er une &eacute;quipe</h2>
       <p class='date'><?php echo date("Y.m.d"); ?></p>
       <p class='meta'><em>Posted by Aravinthan </p>
       <div class='entry'>
       <form action="request_confirm.php" name="request_teammate" method="post">
        Votre Pr&eacute;nom:
        <br />
        <input name="fname" type="text" size="30"  />
        Votre Nom de Famille:
        <br />
        <input name="lname" type="text" size="30"  />
      <?php echo"<input type='hidden' name='receiver' value='$playerid' />"; ?>
           <input type="submit" value="Confirmer"/>
       </form>
    <p class='links'></p></div>
    
      </div>
     </div>
     <!-- end #content -->
    <?php include("sidebar.php"); ?>
     <!-- end #sidebar -->
     <div style="clear: both;">&nbsp;</div>
    </div>
    <!-- end #page -->
    <?php
    include("copyright.php");
    ?>
    <!-- end #footer -->
    </div>
    </body>
    </html>
    THen it comes to the page show in earlier posts.
    There it checks if the user has inputted their names. Then it checks to see if they have a team, if they do, they keep the team name and sends request,
    if they dont it asks them to choose a teamname then it sends request.


    The problem is that, I get to the part where it asks to choose a teamnmae, but when I choose it, it says:
    pleaser enter lname,fname....

    Why is that?

  10. #10
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Smart Froms

    I don't see where your problem is happening. Can you narrow it down a little? It's also hard because it's not all in english :P I looks like the problem may be in request_confirm.php, which I don't think you posted.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Review Smart Mac V2
    By Jordan C in forum Review My Site
    Replies: 11
    Last Post: 11-02-2008, 11:57 AM
  2. Link exchange with Smart Mac
    By Jordan C in forum Link Exchange
    Replies: 2
    Last Post: 10-03-2008, 01:59 PM
  3. Smart Cars
    By Macaws in forum Off Topic
    Replies: 19
    Last Post: 08-15-2008, 08:08 AM
  4. smart ftp
    By luc0077 in forum Soporte
    Replies: 5
    Last Post: 04-27-2008, 03:45 PM
  5. just how smart can an iframe get?
    By bonzo meier in forum Programming Help
    Replies: 4
    Last Post: 03-05-2008, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers