View Single Post
Old 2010-03-03, 09:27 PM   #1
DIVAD3
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
DIVAD3's Avatar
 
Join Date: Aug 2009
Location: Up-Sate NY !
Posts: 79
Send a message via ICQ to DIVAD3
PHP Scripting question?

For weeks now I have been reading tutorials on PHPmysql and inserting tables into the database. I have almost become obsessed with wanting to understand the concepts of php. I am determined to get this mastered to some degree. So here below I have a simple register/loging script that I am just trying to understand the basics of getting this functional for now. I have inserted the following simple table ino my database and I am having trouble getting the register.php and login.php to be reconized in the database. Below I have put XXXXX's to where I presume I am to be insert my info.

Can someone plz help me by indicating wither or not I have this correct as to where I have put the X's ??? If anyone is interested in the actual link, it is as follows: http://www.detailzusedcars.com/us-au...4/register.php

PHP Code:
SIMPLE TABLE CREATED FROM A TUTORIAL:
Name the table "dbUsers." It will need 4 fields:

[i]Name             Type                 Addition[/i]

"id"                  int(10)              Primary Key, AUTO_INCREMENT
"username"            varchar(16)          Unique
"password"            char(16)           
"email"               varchar(25)
------------------------------------------------------------------------
REGISTER PHP SCRIPT IS IS AS FOLLOWS:

<?php

// dbConfig.php is a file that contains your
// database connection information. This
// tutorial assumes a connection is made from
// this existing file.
include ("dbConfig.php");


//Input vaildation and the dbase code
if ( $_GET["op"] == "reg" )
 {
 
$bInputFlag false;
 foreach ( 
$_POST as $field )
  {
  if (
$field == "")
   {
   
$bInputFlag false;
   }
  else
   {
   
$bInputFlag true;
   }
  }
 
// If we had problems with the input, exit with error
 
if ($bInputFlag == false)
  {
  die( 
"Problem with your registration info. "
   
."Please go back and try again.");
  }

 
// Fields are clear, add user to database
 //  Setup query
 
$q "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
  
.
   
"VALUES ('".$_POST["XXXXXXXXXX"]."', "
  
."PASSWORD('".$_POST["XXXXXXXXX"]."'), "
  
.
    
"'".$_POST["email"]."')";
 
//  Run query
 
$r mysql_query($q);
 
 
// Make sure query inserted user successfully
 
if ( !mysql_insert_id() )
  {
  die(
"Error: User not added to database.");
  }
 else
  {
  
// Redirect to thank you page.
  
Header("Location: register.php?op=thanks");
  }
 } 
// end if


//The thank you page
elseif ( $_GET["op"] == "thanks" )
 {
 echo 
"<h2>Thanks for registering!</h2>";
 }
 
//The web form for input ability
else
 {
 echo 
"<form action=\"?op=reg\" method=\"POST\">\n";
 echo 
"Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n";
 echo 
"Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br 

/>\n"
;
 echo 
"Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n";
 echo 
"<input type=\"submit\">\n";
 echo 
"</form>\n";
 }
// EOF
?>
---------------------------------------------------------
THE LOGIN SCRIPT IS AS FOLLOWS:

<?php
session_start
();
// dBase file
include "dbConfig.php";

if (
$_GET["op"] == "login")
 {
 if (!
$_POST["XXX=username"] || !$_POST["XXX=password"])
  {
  die(
"You need to provide a username and password.");
  }
 
 
// Create query
 
$q "SELECT * FROM `dbUsers` "
  
."WHERE `username`='".$_POST["XXX=username"]."' "
  
."AND `password`=PASSWORD('"XXX=password"]."') "
  ."LIMIT 1";
 // Run query
 $r = mysql_query($q);

 if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, create session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["username"];
  $_SESSION["valid_time"] = time();

  // Redirect to member page
  Header("Location: members.php");
  }
 else
  {
  // Login not successful
  die("Sorry, could not log you in. Wrong login information.");
  }
 }
else
 {
//If all went right the Web form appears and users can log in
 echo "<form action=\"?op=login\" method=\"POST\">";
 echo "Username: <input name=\"username\" size=\"15\"><br />";
 echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
 echo "<input type=\"submit\" value=\"Login\">";
 echo "</form>";
 }
?>
---------------------------------------------------------------------
THE DBCONFIG.PHP IS AS FOLLOWS:

<?
// Replace the variable values below
// with your specific database information.
$host = "XXXXXXXX";
$user = "XXXXXXXX";
$pass = "XXXXXXXX";
$db   = "dbusers";

// This part sets up the connection to the 
// database (so you don'
t need to reopen the connection
// again on the same page).
$ms mysql_pconnect($host$user$pass);
if ( !
$ms )
{
echo 
"Error connecting to database.\n";
}

// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>
Thankyou sincerely for your help!

Di' Vad
DIVAD3 is offline   Reply With Quote