setting up xamp to work with my php and mysql files.

Problems with the Windows version of XAMPP, questions, comments, and anything related.

setting up xamp to work with my php and mysql files.

Postby rhodri88 » 13. March 2010 11:18

Hey,
I'm new to this so go easy. It would also be helpful if you could explain what I should do plainly, and not use too much technical words and phrases please.

My problem is that I have written my MySQL database and have written a php login program but I don't know how to link them together. I also don't know what I need to do with apache to make this all work together, to make the programs run and work either on my localhost or the internet. Any help would be much appreciated, thanks in advance.

Here's my php login code.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

   <title>Aberystwyth Town F.C</title>
   <link rel="stylesheet" type="text/css" href="cs394.css"/>

</head>

<body>

<div id="header">

<a href="file:///C:/Users/Rhodri%20Pritchard/Documents/public_html/cs394/cs394.php"><img src='aberlogo.jpg' alt="aber town logo" align=left width=150 height=150 > </a>

<h1 align="center"> Aberystwyth Town F.C </h1>

   <form name="input" action="html_form_submit.asp" method="get">
   Search the site
   <input type="text" name="user" />
   <input type="submit" value="Go" />
   </form>

</div>


<div id="navmenu">
   <ul>
      
      <li><a href="file:///C:/Users/Rhodri%20Pritchard/Documents/public_html/cs394/cs394.php">Home</a></li>
      <li><a href="file:///C:/Users/Rhodri%20Pritchard/Documents/public_html/cs394/team.php">Team</a></li>
      <li><a href="file:///C:/Users/Rhodri%20Pritchard/Documents/public_html/cs394/history.php">History</a></li>
      <li><a href="file:///C:/Users/Rhodri%20Pritchard/Documents/public_html/cs394/the_club.php">The Club</a></li>
              <li><a href="file:///C:/Users/Rhodri%20Pritchard/Documents/public_html/cs394/match.php">Match</a></li>
      <li><a href="file:///C:/Users/Rhodri%20Pritchard/Documents/public_html/login.php">Emembers</a></li>
   </ul>
</div>

<div id='body'>
   
<?php
/* Program: Login.php
 * Desc:         Login program for Members Only section of the pet store.
 *       It provides two options: (1) login using an existing Login Name
 *          and (2) enter a new login name. Login Names and passwords are
 *       stored in a MySQL database.
*/
  session_start():
  include("passwords.inc"):   /*change name of file to something less obvious*/
  switch (@$_GET['do'])
  {
     case "login":
         $connection = mysl_connect($localhost, $root, $)
                          or die ("Couldn't connect to server.");
         $db = mysql_select_db($Emembers, $connection)
                          or die (Couldn't select database.");

        $sql = "SELECT loginName FROM Member
                      WHERE loginName='$_POST[fusername]'";
        $result = mysql_query($sql)
                         or die ("Couldn't execute query.");
        $num = mysql_num_rows($result);
        if ($num == 1) // login name was found
        {
           $sql = "SELECT loginName FROM Member
                        WHERE loginName='$_POST[fusername]'
                        AND password=password('$_POST[fpassword]')";
          $result2 = mysql_query($sql)
                           or die("Couldn't execute query 2.");
          $num2 = mysql_num_rows($result2);
          if ($num2 > 0)  // password is correct
          {
               $_SESSION['auth']="yes";
               $logname=$POST['fusername'];
               $_SESSION['logname'] = $logname;
               $today = date("y-m-d h:m:s");
               $sql = "INSERT INTO Login  (loginName , loginTime)
                            VALUES ('$logname' , '$today')";
               mysql_query($sql) or die("Can't execute query. ");
               header("Location: Member_page.php");
            }
            else  //  password is not correct
            {
               unset($do);
               $message="The Login Name, '$_POST[fusername]'
                                     exists, but you have not entered the correct
                                    password! Please try
               again. <br>";
               include("login_form.inc");
            }
     }
     elseif ($num == 0) // login name not found
      {
              unset($do);
              $message = " The Login Name you entered does not
                                       exist! Please try again. <br>";
              include("login_form.inc");
       }
   break;

   case "new";
       foreach($_POST as field => $value)
       {
           if (field != "fax")
           {
               if ($value == "")
               {
                   unset($_GET['do']);
                   $message_new = "Required information is missing.
                            Please try again. ";
                    include("login_form.inc");
                    exit();
                }
             }
             if (ereg("(Name)",$field))
             {
               /*if (!ereg("^[A-Z a-z'  -]{1,50} $",$value))
               {
                  unset($_GET['do']);
                  $message_new = "$field is not a valid name.
                                                    Please try again.";
                  include("login_form.inc");
                  exit();
               }*/
              }
              $$field = strip_tags(trim($value));
           }  // end foreach
           if (!ereg("^[0-9]{5,5}(\ -[0-9]{4,4})?$",$postcode )) #MUST CHECK TO SEE IF THIS IS CORRECT
           {
               unset($_GET['do']);
               $message_new = "$postcode is not a valid postcode.
                                               Please try again.";
               include("login_form.inc");
               exit();
             }   
             if (!ereg("^[0-9) (xX -]{7,20}$",$phone))
               {
                  unset($_GET['do']);
                  $message_new = "phone is not a valid phone number.
                                               Please try again.";
                  include("login_form.inc");
                  exit();
                 }
           if  ($fax != "")
           {
              if (!ereg("^[0-9)(xX -]{7,20}$",$fax))
              {
                 unset($_GET['do']);
                 $message_new = "$fax is not a valid phone number.
                                                   Please try again.";
                 include("login_form.inc");
                 exit();
                }
             }
             if (!ereg("^.+@.+\\..+$".$email))
             {
                 unset($_GET['do']);
                 $message_new = "$email is not valid email address.
                                                 Please try again.";
                 include("login_form.inc");
                 exit():
              }
              /* check to see if login name already exists */
              $connection = mysql_connect($host,$user,$password)
                               or die ("Couldn't connect to server.");
              $db = mysql_select_db($database, $connection)
                                or die ("Couldn't select database.");
              $sql = "SELECT loginName FROM Member
                                WHERE loginName='$newname'";
              $result = mysql_query($sql)
                              or die("Couldn't execute query.");
              $num = mysql_mumrows($result);
              if ($num > 0)
              {
                  unset($_GET['do']);
                  $message_new = "$newname already used. Select another
                                                   Member ID. ";
                  include("login_form.inc");
                  exit();
                }
                else
                {
                    $today = date("Y-m-d");
                    $sql = " INSERT INTO Member (loginName,createDate,
                                       password, firstName, lastName, street, city,
                                       state, zip, phone, fax, email) VALUES
                                    ('$newname', '$today', password('$newpass'),
                                     '$firstName', '$lastName', '$street', '$city',
                                     '$state', '$zip', '$phone', '$fax', '$email')";
                     mysql_query($sql);
                     $_SESSION['auth']="yes";
                     $_SESSION['logname'] = $newname;
                     
                     /* send email to new member */
                     $emess = "A new Member Account has been setup. ";
      $emess .= "Your new Member ID and password are: ";
      $emess .= "\n\n\t$newname\n\t$newpass\n\n";
      $emess .= "We appreciate your interest in Pet Store";
      $emess .= " at PetStore.com. \n\n";
      $emess .= "If you have any questions or problems, ";
      $emess .= " email webmaster@petstores.com";
      $ehead = "From member-desk@petstore.com\r\n";
      $subj    = "Your new Member Account from Pet Store";
      $mailsend =mail ("$email", "$subj", "$emess", "ehead");
      header("Location: New_Member.php");
                   }
                 break;

                 default;
                         include("login_form.inc");
      }
?>
                     




   
</div>


<p>
<a href="http://validator.w3.org/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
<p>
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img src="http://www.w3.org/Icons/valid-css"
alt="Valid CSS!" height="31" width="88" /></a>
</p>

<p> Made by Rhodri Pritchard 2009.<br />Thank you for visiting our site </p>


</body>

</html>

login_form code
Code: Select all
<?php
 /* File: login_form.inc
 *Desc: Displays login page. Page displays two forms -- one
 *           form for entering an existing login name and
 *           password and another form for the information
 *           needed to apply for a new account.
*/
include("functioncounty.inc");
?>
<html>
<head><title> Emembers Only Login</title></head>
<body topmargin="0" leftmargin="0" marginheight="0"
           marginwidth="0">
<table border="0" cellpadding="5" cellspacing="0">
    <tr><td colspan="3" bgcolour="grey" align="center">
           <font color="white" size="+10">
           <b>Emembers Login Only</b></font></td></tr>
    <tr>
           <td width="33%" valign="top">
              <font size="+1"><b>Are you a member?</b></font>
              <p>
              <!-- form for customer login -->
              <form action="Login.php?do=login" method="POST">
              <table border="0">
<?php
                   if (isset($message))
                    echo "<tr><td colspan='2'>$message </td></tr>";
?>
           <tr><td align=right><b>Username</b></td>
             <td><input type="text" name="fusername"
                             size="20" maxsize="20">
             </td></tr>
           <tr><td width="120" align="right"><b>Password</b>
              </td>
              <td><input type="password" name="fpassword"
                                 size="20" maxsize="20"></td></tr>
           <tr><td align="center" colspan="2">
                     <br><input type="submit" name="log"
                                        value="Enter">
                  </td></tr>
      </table>
      </form>
    </td>
    <td width="1" bgcolor="gray"></td>
    <td width+"67%">
       <p><font size="+1"><b>Not a Emember yet?</b></font>
                Get extra information about the team, exclusive videos and interviews and
               much more. Fill in the information below and join.</b>
     <!-- form for a new emember to fill in -->
     <form action="Login.php?do=new" method "POST">
     <p>
       <table border="0" width="100%">
<?php
            if (isset($message_new))
               echo "<tr><td colspan='2'><b>$message_new</b>
                                 </td></tr>";
?>
      <tr<td align="right"><b>Member ID</b></td>
           <td><input type="text" name="newname"
                    value="<?php echo @$newname ?>"
                    size="20" maxlength="20"></td></tr>
      <tr><td align="right"><b>Password</b></td>
             <td><input type="password" name="newpass"
                                value="<?php echo @$newpass ?>"
                                size="10" maxlength="8"></td></tr>
      <tr><td align="right"><b>First Name</b></td>
             <td><input type="text" name="firstName"
                                 value="<?php echo @$firstname ?>"
                                 size="40" maxlength="40"></td></tr>
      <tr><td align="right"><b>Last Name</b></td>
             <td><input type="text" name="lastName"
                                value="<?php echo @$lastName ?>"
                                size="40" maxlength="40"></td></tr>
      <tr><td align="right"><b>Street</b></td>
             <td><input type="text" name="street"
                                value="<?php echo @$street ?>"
                                size="55" maxlength="50"></td></tr>
      <tr><td align="right"><b>City/Town</b></td>
             <td><input type="text" name="cityTown"
                                value="<?php echo @$cityTown ?>"
                                size="40" maxlength="40"></td></tr>   
      <tr><td align="right"><b>County</b></td>
             <td><select name="county">
<?php         
    /* figure out which parts of code below belong to CountyCode
     * remove them and leave just CountyName
                  /*
    $countyName=getCountyName();
         $countyCode=getCountyCode(); 
                   for ($n=1;$n<=;$n++)
                   {
                        $county=$countyName[$n];
         $ccode=$countyCode[$n];
                        echo "<option value='$ccode'";
                        if   ($ccode== "AL")
                               echo " selected";
                       echo ">$state\n";
                     }
?>
   </select>
                  &nbsp;&nbsp;&nsbp;&nbsp;<b>Postcode</b>
     <input type="text" name="postcode"
                 value="<?php echo @$postcode ?>"
                             size="8" maxsize="8">
               </td></tr>
           <tr><td align="right"><b>Phone</b></td>
                   <td><input type="text" name="phone"
                                value="<?php echo @$phone ?>"
                                size="15" maxlength="20"></td></tr>
                 &nbsp;&nbsp;&nsbp;<b>Fax</b>
                        <td><input type="text" name="fax"
                                value="<?php echo @$fax ?>"
                                size="15" maxlength="20"></td></tr> 
                 <tr><td align="right"><b>Email</b></td>
                         <td><input type="test" name="email"
                                value="<?php echo @$email ?>"
                                size="55" maxlength="67"></td></tr>
   <tr><td>&nbsp;</td>
          <td align="center">
                               <input type="submit"
                                          value="Become a Emember"></td>
   </tr>
               </table>
              </form>
            </td>
        </tr>
        <tr><td colspan="3" bgcolor="gray">&nbsp;</td></tr>
 </table>
<div align="center"><font size="-1">
       All comments and suggestions are appreciated. Please
       send comments to <a href="mailto:rjp7@aber.ac.uk">
       rjp7@aber.ac.uk</A> </font></div>
</body></html>
rhodri88
 
Posts: 1
Joined: 13. March 2010 11:02

Re: setting up xamp to work with my php and mysql files.

Postby wkelvinf » 14. March 2010 12:52

Why don't you first start with a simple php tutorial? I guess there are many tutorials online.

You could try out this one: http://php.net/manual/en/tutorial.php
wkelvinf
 
Posts: 8
Joined: 13. March 2010 14:16


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 56 guests