Results 1 to 5 of 5

Thread: account

  1. #1
    Join Date
    May 2004
    Location
    South Wales | UK
    Posts
    43

    Exclamation Unanswered: account

    I am have created two php pages one is a form where the user enters information and the other page has this code in it

    PHP Code:
    <?php

    @$username=$HTTP_POST_VARS['username']; 
    @
    $password=$HTTP_POST_VARS['password']; 
    @
    $email=$HTTP_POST_VARS['email']; 

    include_once(
    "functions.php");

    register($username$email$password);

    ?>
    I was wondering if i could have all this on one page as the second page has no real purpose orther than assigning the variables and putting them into the function.

    any ideas.
    Last edited by InfoSystems; 02-24-05 at 17:58. Reason: inproper syntax

  2. #2
    Join Date
    Dec 2004
    Posts
    27
    yep you sure can, although i'd add a little checking to make sure there is nobody trying to screw your system up.

    PHP Code:
    <?php

    if($_POST) {
     @
    $username htmlspecialchars(stripslashes(trim($HTTP_POST_VARS['username'])));
     @
    $password htmlspecialchars(stripslashes(trim($HTTP_POST_VARS['password'])));
     @
    $email htmlspecialchars(stripslashes(trim($HTTP_POST_VARS['email'])));

     include_once(
    "functions.php");

     
    register($username$email$password); 
    }else{
    // place all HTML code here and replace "post='page your using'" in the form tag with "post=''"
    // use the open and close php tags to exit and enter php if needed
    }
    ?>
    that should do it. also might be a good idea to use PHP_SELF rather then a blank post tag but either way should work.
    Last edited by wardly; 02-25-05 at 23:51.

  3. #3
    Join Date
    May 2004
    Location
    South Wales | UK
    Posts
    43

    Not working

    PHP Code:
    <?php
    if($_POST) {
    @
    $username htmlspecialchars(stripslashes(trim($HTTP_POST_VARS  ['username'])));
    @
    $password htmlspecialchars(stripslashes(trim($HTTP_POST_VARS  ['password'])));
    @
    $email htmlspecialchars(stripslashes(trim($HTTP_POST_VARS  ['email'])));

    include_once(
    "functions.php");

    register($username$email$password); 

    }else{
    ?>
    <html>
    <head>
    <title>.:: Kingmonitors ::. All your monitor needs</title>
    <link rel=stylesheet href="layout.css" type="text/css">
    </head>
    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

    <table width="760" border="0" align="center" cellpadding="0" cellspacing="0" id="main">
      <tr>
        <td height="125" colspan="2" rowspan="4"> <img src="images/logo.gif" alt="Kingmonitors - All your monitor needs" width="454" height="125" border="0" usemap="#Map"></td>
        <td width="306" height="9" colspan="5">&nbsp;</td>
      </tr>
      <tr>
        <td width="96" height="21"> <img src="images/my_account.gif" width="96" height="21" alt=""></td>
        <td colspan="3"> <a href="cart.php"> <img src="images/cart.gif" width="137" height="21" border="0" alt=""></a></td>
        <td width="73"> <img src="images/Help.gif" width="73" height="21" alt=""></td>
      </tr>
      <tr>
        <td width="306" height="60" colspan="5">&nbsp;</td>
      </tr>
      <tr>
        <td width="101" height="29" colspan="2"> <a href="index.html"><img src="images/home.gif" alt="" width="102" height="29" border="0"></a></td>
        <td width="102"> <a href="search.htm"><img src="images/search.gif" alt="" width="102" height="29" border="0"></a></td>
        <td width="102" colspan="2"><a href="monitors.php"><img src="images/produc_active.gif" alt="" width="102" height="29" border="0"></a></td>
      </tr>
      <tr >
        <td height="18" colspan="7" background="images/bg_bar.gif"></td>
      </tr>
      <tr valign="top">
        <td width="760" height="200" colspan="7">
          <table width="759" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="10"></td>
            </tr>
          </table>
          <p>&nbsp;</p>
          <form action="PHP_SELF" method="post" name="register" id="register">
            <table class="maintext" width="449" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td width="160" height="24">
    <div align="right">Username:</div></td>
                <td width="14">&nbsp;</td>
                <td width="275"><input name="username" type="text" id="username"></td>
              </tr>
              <tr>
                <td width="160"><div align="right">Firstname:</div></td>
                <td width="14">&nbsp;</td>
                <td width="275"><input name="f_name" type="text" id="f_name"></td>
              </tr>
              <tr>
                <td width="160"><div align="right">Lastname:</div></td>
                <td width="14">&nbsp;</td>
                <td width="275"><input name="l_name" type="text" id="l_name"></td>
              </tr>
              <tr>
                <td height="10"></td>
                <td height="10"></td>
                <td height="10"></td>
              </tr>
              <tr>
                <td><div align="right">Email:</div></td>
                <td>&nbsp;</td>
                <td><input name="email" type="text" id="email" size="40"></td>
              </tr>
              <tr>
                <td height="10"></td>
                <td height="10"></td>
                <td height="10"></td>
              </tr>
              <tr>
                <td><div align="right">Password:</div></td>
                <td>&nbsp;</td>
                <td><input name="password" type="password" id="password"></td>
              </tr>
              <tr>
                <td><div align="right">Confirm Password:</div></td>
                <td>&nbsp;</td>
                <td><input name="conpas" type="password" id="conpas"></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr align="center">
                <td colspan="3"> <input type="submit" name="Submit" value="Register"></td>
              </tr>
            </table>
          </form>
          <p>&nbsp;</p></td>
      </tr>
        <tr>
        <td width="9" height="1"> <img src="/images/spacer.gif" width="9" height="1" alt=""></td>
        <td width="445" height="1"> <img src="/images/spacer.gif" width="445" height="1" alt=""></td>
        <td width="96" height="1"> <img src="/images/spacer.gif" width="96" height="1" alt=""></td>
        <td width="6" height="1"> <img src="/images/spacer.gif" width="6" height="1" alt=""></td>
        <td width="102" height="1"> <img src="/images/spacer.gif" width="102" height="1" alt=""></td>
        <td width="29" height="1"> <img src="/images/spacer.gif" width="29" height="1" alt=""></td>
        <td width="73" height="1"> <img src="/images/spacer.gif" width="73" height="1" alt=""></td>
      </tr>

    </table>
    </body>
    </html>
    <?php
    }
    ?>
    This is what i got and nothing is happening any ideas

  4. #4
    Join Date
    Dec 2004
    Posts
    27
    You didn't use php_self correctly. I think that might be the problem. Try this,

    PHP Code:
    <?php
    if($_POST) {
     @
    $username htmlspecialchars(stripslashes(trim($HTTP_POST_VARS['username'])));
     @
    $password htmlspecialchars(stripslashes(trim($HTTP_POST_VARS['password'])));
     @
    $email htmlspecialchars(stripslashes(trim($HTTP_POST_VARS['email'])));

    include_once(
    "functions.php");

    register($username$email$password);

    }else{
    ?>
    <html>
    <head>
    <title>.:: Kingmonitors ::. All your monitor needs</title>
    <link rel=stylesheet href="layout.css" type="text/css">
    </head>
    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

    <table width="760" border="0" align="center" cellpadding="0" cellspacing="0" id="main">
      <tr>
        <td height="125" colspan="2" rowspan="4"> <img src="images/logo.gif" alt="Kingmonitors - All your monitor needs" width="454" height="125" border="0" usemap="#Map"></td>
        <td width="306" height="9" colspan="5">&nbsp;</td>
      </tr>
      <tr>
        <td width="96" height="21"> <img src="images/my_account.gif" width="96" height="21" alt=""></td>
        <td colspan="3"> <a href="cart.php"> <img src="images/cart.gif" width="137" height="21" border="0" alt=""></a></td>
        <td width="73"> <img src="images/Help.gif" width="73" height="21" alt=""></td>
      </tr>
      <tr>
        <td width="306" height="60" colspan="5">&nbsp;</td>
      </tr>
      <tr>
        <td width="101" height="29" colspan="2"> <a href="index.html"><img src="images/home.gif" alt="" width="102" height="29" border="0"></a></td>
        <td width="102"> <a href="search.htm"><img src="images/search.gif" alt="" width="102" height="29" border="0"></a></td>
        <td width="102" colspan="2"><a href="monitors.php"><img src="images/produc_active.gif" alt="" width="102" height="29" border="0"></a></td>
      </tr>
      <tr >
        <td height="18" colspan="7" background="images/bg_bar.gif"></td>
      </tr>
      <tr valign="top">
        <td width="760" height="200" colspan="7">
          <table width="759" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="10"></td>
            </tr>
          </table>
          <p>&nbsp;</p>
          <form action="<?PHP echo $_SERVER['PHP_SELF'?>" method="post" name="register" id="register">
            <table class="maintext" width="449" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td width="160" height="24">
    <div align="right">Username:</div></td>
                <td width="14">&nbsp;</td>
                <td width="275"><input name="username" type="text" id="username"></td>
              </tr>
              <tr>
                <td width="160"><div align="right">Firstname:</div></td>
                <td width="14">&nbsp;</td>
                <td width="275"><input name="f_name" type="text" id="f_name"></td>
              </tr>
              <tr>
                <td width="160"><div align="right">Lastname:</div></td>
                <td width="14">&nbsp;</td>
                <td width="275"><input name="l_name" type="text" id="l_name"></td>
              </tr>
              <tr>
                <td height="10"></td>
                <td height="10"></td>
                <td height="10"></td>
              </tr>
              <tr>
                <td><div align="right">Email:</div></td>
                <td>&nbsp;</td>
                <td><input name="email" type="text" id="email" size="40"></td>
              </tr>
              <tr>
                <td height="10"></td>
                <td height="10"></td>
                <td height="10"></td>
              </tr>
              <tr>
                <td><div align="right">Password:</div></td>
                <td>&nbsp;</td>
                <td><input name="password" type="password" id="password"></td>
              </tr>
              <tr>
                <td><div align="right">Confirm Password:</div></td>
                <td>&nbsp;</td>
                <td><input name="conpas" type="password" id="conpas"></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr align="center">
                <td colspan="3"> <input type="submit" name="Submit" value="Register"></td>
              </tr>
            </table>
          </form>
          <p>&nbsp;</p></td>
      </tr>
        <tr>
        <td width="9" height="1"> <img src="/images/spacer.gif" width="9" height="1" alt=""></td>
        <td width="445" height="1"> <img src="/images/spacer.gif" width="445" height="1" alt=""></td>
        <td width="96" height="1"> <img src="/images/spacer.gif" width="96" height="1" alt=""></td>
        <td width="6" height="1"> <img src="/images/spacer.gif" width="6" height="1" alt=""></td>
        <td width="102" height="1"> <img src="/images/spacer.gif" width="102" height="1" alt=""></td>
        <td width="29" height="1"> <img src="/images/spacer.gif" width="29" height="1" alt=""></td>
        <td width="73" height="1"> <img src="/images/spacer.gif" width="73" height="1" alt=""></td>
      </tr>

    </table>
    </body>
    </html>
    <?php
    }
    ?>
    You should be able to cutt and paste but te only thing i changed was the post statement from post="PHP_SELF" to post="<?php echo $_SERVER['PHP_SELF']; ?>"

    But try it out and see what you get. Let me know if this don't work.

  5. #5
    Join Date
    May 2004
    Location
    South Wales | UK
    Posts
    43

    Still no

    Hi thanks for the reply, no didnt work. I enter information in and click on the button but it does not work. no information is being sent to the database.

    This time i have included the function i am using as well.

    PHP Code:
    function register($username$email$password)
    // register new person with db
    // return true or error message
    {
     
    // connect to db
      
    $conn db_connect();
      
    //Is this needed as db_connect has own error reporting.
      
    if (!$conn)
       return 
    'Could not connect to database server - please try later.';

      
    // check if username is unique 
      
    $result mysql_query("select * from user where username='$username'"); 
      if (!
    $result)
         return 
    'Could not execute query';
      if (
    mysql_num_rows($result)>0
         return 
    'That username is taken - go back and choose another one.';

      
    // if ok, put in db
      
    $result mysql_query("insert into user values 
                             ('
    $username',  password('$password'), '$email')");
      if (!
    $result)
        return 
    'Could not register you  in database - please try again later.';

      return 
    true;


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •