Greenguy's Board


Go Back   Greenguy's Board > Newbie Questions
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
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
Old 2010-03-03, 10:38 PM   #2
mark6188
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
mark6188's Avatar
 
Join Date: Sep 2009
Posts: 88
Send a message via ICQ to mark6188
I'm really not a php expert, so it's hard for me to look at the code you have and see the problem.

That said, I've written some simple registration type forms. From the way I understand your question, you are trying to put the actual data where you have the xxxxx?

Like $_POST('xxxxx') would be $_POST('mark6188')?

You don't put the data in the $_Post. You put the variable name.

So in your input form you would put the field 'user' and in the database it's called 'username'.

Hence you would set up the form with
<input type="text" name="user" id="user" />
<input type="text" name="pw" id="pw" />

let's say I put in your form where user=mark6188 and pw=abc123

Then do the insert query
$q = "insert into dbUser ('username', 'password') values ($_POST['user'], $_POST['pw'] )";


not sure if I have all the quotes and double quotes right, but the above should insert the correct values into your table.

If I misunderstood your question, please restate it and I'll try again. Hope that helps.
__________________
My Blog: Working The Business
mark6188 is offline   Reply With Quote
Old 2010-03-04, 11:34 AM   #3
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
Thanks for your response Mark...

Quote:
Originally Posted by mark6188 View Post
Like $_POST('xxxxx') would be $_POST('mark6188')?

You don't put the data in the $_Post. You put the variable name.

So in your input form you would put the field 'user' and in the database it's called 'username'.

Hence you would set up the form with
<input type="text" name="user" id="user" />
<input type="text" name="pw" id="pw" />

let's say I put in your form where user=mark6188 and pw=abc123

Then do the insert query
$q = "insert into dbUser ('username', 'password') values ($_POST['user'], $_POST['pw'] )";

Good Morning Mark and thankyou for responding. I was replying to what you said whe you were on line earlier and hit enter to move down a line. And my browser closed right out on me. so I am sorry I missed you.

If I am to understand you correctly. You are inplying that I should be adding a form as you have indicated in the above statement. However this script was written in such a way to only reconize one database user for the time being. so that is what I am trying to get it to do.

The tutorial is here: http://www.trap17.com/index.php/php-...ial_t7887.html

I understand if you don't have time to check this simple formated script out. But I am sure that if you were to check it out it would be esy for you to see what it is that needs to be done. I get what your getting at above though and it makes sense to me. But I just don't know if its necessary to be adding this form outside of what the sites is giving driection to be doing to have it work porperly. Soner or later it will click in my dense head. I am on some heavy meds just now for a herniated disc I am having removed on the 19th of this months. so I am in a fog with my thinking. But it will hit me out of the blue as to what I am doing wrong upto this point.

Thanks again!
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 11:39 AM   #4
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
Also Mark I think the missing element might have to do with what it says here in this part of the script at the bottom:
Quote:
// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>
Perhaps there is something I should be putting in this line???? OR NOT! it really doesnt make sense to me that I should be touching that part of it.
---------------------------------------
Just exactly what the variable is-is something I am not understanding. what is the variable as you were implying???

Last edited by DIVAD3; 2010-03-04 at 11:42 AM..
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 12:22 PM   #5
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
I can see now, that you were not telling me to add anything new! You were reffering to what is already a part of the script. Da Da Di'vad
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 12:24 PM   #6
mark6188
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
mark6188's Avatar
 
Join Date: Sep 2009
Posts: 88
Send a message via ICQ to mark6188
No, you don't need to add a form, basically the form is already in the code.

Code:
//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";
 }
I think all you need to do is change this part of the code and replace the xxxx with the input names in the form above.

Code:
// Fields are clear, add user to database
 //  Setup query
 $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
  .
   "VALUES ('".$_POST["username"]."', "
  ."PASSWORD('".$_POST["password"]."'), "
  .
    "'".$_POST["email"]."')";
The code in the tutorial has it this way, so not sure why you changed the variables to xxxxx in your 1st post.

Honestly, I'm still not sure what your question is. When I click on your link, I see a "Error Connecting to Database" message. Is this what you need help with?

If so, you don't want to touch any of the code with the form in it. You need to modify the dbConfig.php file and put your username and password for the mysql database you setup.

Code:
<?
// Replace the variable values below
// with your specific database information.
$host = "localhost";
$user = "UserName";
$pass = "Password";
$db   = "dbName";
Change it to something like
Code:
<?
// Replace the variable values below
// with your specific database information.
$host = "localhost";
$user = "hostname_dvad3";
$pass = "abc123";
$db   = "hostname_dbName";
__________________
My Blog: Working The Business

Last edited by mark6188; 2010-03-04 at 12:27 PM..
mark6188 is offline   Reply With Quote
Old 2010-03-04, 12:30 PM   #7
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
3 scripts Unscathed!

Here is the entire 3 scripts unscathed by me Mark. If you could just quote them and put in the XXX's or indicate by any terms, where I am to insert what is neccessary. I think I might crasp things a little bit better. I can't promise that however! At least that way I can just make the comparison

Quote:
The Database Configuration:
<?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["username"]."', "
."PASSWORD('".$_POST["password"]."'), "
."'".$_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 REGISTRATION:
<?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["username"]."', "
."PASSWORD('".$_POST["password"]."'), "
."'".$_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:

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

if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
{
die("You need to provide a username and password.");
}

// Create query
$q = "SELECT * FROM `dbUsers` "
."WHERE `username`='".$_POST["username"]."' "
."AND `password`=PASSWORD('".$_POST["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>";
}
?>
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 12:35 PM   #8
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
Quote:
Originally Posted by mark6188 View Post
The code in the tutorial has it this way, so not sure why you changed the variables to xxxxx in your 1st post.

Honestly, I'm still not sure what your question is. When I click on your link, I see a "Error Connecting to Database" message. Is this what you need help with?

If so, you don't want to touch any of the code with the form in it. You need to modify the dbConfig.php file and put your username and password for the mysql database you setup.
Thats a big yes! As to what I am troulbe with as well as uncertain to just where I insert my info in certain places.

And I was just putting the xxx's as to fill it in with something.
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 12:40 PM   #9
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
Mark here is what I have on line right now. This might help you understand completel what I have wrong.

Quote:
dbconfig:

<?
// Replace the variable values below
// with your specific database information.
$host = "admblogdetailzus.db.3474803.hostedresource.com";
$user = "admblogdetailzus";
$pass = "OLIVIAlynn616";
$db = "dbuser";

// 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);
?>

-----------------------------------------------------------
register.php:

<?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["admblogdetailzus"]."', "
."PASSWORD('".$_POST["OLIVIAlynn616"]."'), "
."'".$_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
?>
----------------------------------------------------------
login.php:

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

if ($_GET["op"] == "login")
{
if (!$_POST["admblogdetailzus"] || !$_POST["OLIVIAlynn616"])
{
die("You need to provide a username and password.");
}

// Create query
$q = "SELECT * FROM `dbUsers` "
."WHERE `username`='".$_POST["admblogdetailzus"]."' "
."AND `password`=PASSWORD('".$_POST["OLIVIAlynn616"]."') "
."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>";
}
?>
-------------------------------------------------------------
members.php:

<?php
session_start();

if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: login.php");
}

// Member only content
// ...
// ...
// ...

// Display Member information
echo "<p>User ID: " . $_SESSION["valid_id"];
echo "<p>Username: " . $_SESSION["valid_user"];
echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);

// Display logout link
echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";
?>
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 12:50 PM   #10
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
Quote:
Originally Posted by mark6188 View Post
<?
// Replace the variable values below
// with your specific database information.
$host = "localhost";
$user = "hostname_dvad3";
$pass = "abc123";
$db = "hostname_dbName";
Here I see where I should have it as = local host and not my entire server host name. so thats one area corrected now.
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 01:00 PM   #11
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
Ok after reading ALL that you are indicating. I believe I understand completely what I have done wrong. so here is what I have done for changes.

register.php

Quote:
<?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["username"]."', "
."PASSWORD('".$_POST["password"]."'), "
."'".$_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
?>
As for the login:
PHP Code:
<?php
session_start
();
// dBase file
include "dbConfig.php";

if (
$_GET["op"] == "login")
 {
 if (!
$_POST["admblogdetailzus"] || !$_POST["OLIVIAlynn616"])
  {
  die(
"You need to provide a username and password.");
  }
 
 
// Create query
 
$q "SELECT * FROM `dbUsers` "
  
."WHERE `username`='".$_POST["admblogdetailzus"]."' "
  
."AND `password`=PASSWORD('".$_POST["OLIVIAlynn616"]."') "
  
."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>";
 }
?>
As for the dbcong.php:

PHP Code:
<?
// Replace the variable values below
// with your specific database information.
$host "localhost";
$user "admblogdetailzus";
$pass "OLIVIAlynn616";
$db   "dbuser";

// 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);
?>

Last edited by DIVAD3; 2010-03-04 at 01:04 PM..
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 01:07 PM   #12
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
Thankyou EXTREAMLY for taking the time to help me understand all this! I wil lfigure out a clever idea to help promote what you got going on

So now I'll upload that to the server. Or in my case drag and drop into the ftphost browser window.

Last edited by DIVAD3; 2010-03-04 at 01:09 PM..
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 01:18 PM   #13
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
AGGREVATING...

AGGREVATING: Login No such luck. What the Fuk do I have wrong???
I should be able to log in using the username of:admblogdetailzus
And the password of:OLIVIAlynn616

And Mark! I am not sure why I see the: (Error connecting to database) on the login page. That too is a mystry to me.

Anyone is welcome to try this login: http://www.detailzusedcars.com/us-auto-deal4/login.php Good lord. This means money in my pocket when I get this figured out for the purpose of this site I have built.

http://www.detailzusedcars.com/us-au...l/register.php

Just as it is put in the script:
Quote:
<?php
session_start();
// dBase file
include "dbConfig.php";

if ($_GET["op"] == "login")
{
if (!$_POST["admblogdetailzus"] || !$_POST["OLIVIAlynn616"])
{
die("You need to provide a username and password.");
}

// Create query
$q = "SELECT * FROM `dbUsers` "
."WHERE `username`='".$_POST["admblogdetailzus"]."' "
."AND `password`=PASSWORD('".$_POST["OLIVIAlynn616"]."') "
."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>";
}
?>

Last edited by DIVAD3; 2010-03-04 at 01:32 PM..
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 01:28 PM   #14
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
Did I create the query correctly???
Quote:
// Create query
$q = "SELECT * FROM `dbUsers` "
."WHERE `username`='".$_POST["username"]."' "
."AND `password`=PASSWORD('".$_POST["password"]."') "
."LIMIT 1";
// Run query
$r = mysql_query($q);
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 01:59 PM   #15
mark6188
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
mark6188's Avatar
 
Join Date: Sep 2009
Posts: 88
Send a message via ICQ to mark6188
I'm at my day job, so I can only look at this in brief spurts. Right now I see this is wrong:

if (!$_POST["admblogdetailzus"] || !$_POST["OLIVIAlynn616"])

should be:

if (!$_POST["username"] || !$_POST["password"])
__________________
My Blog: Working The Business
mark6188 is offline   Reply With Quote
Old 2010-03-04, 02:14 PM   #16
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
Ok - I do appreciate ur help Mark...

Quote:
Originally Posted by mark6188 View Post
I'm at my day job, so I can only look at this in brief spurts. Right now I see this is wrong:

if (!$_POST["admblogdetailzus"] || !$_POST["OLIVIAlynn616"])

should be:

if (!$_POST["username"] || !$_POST["password"])
Ok So I'll change that. And I also changed this part:
PHP Code:
<?
// Replace the variable values below
// with your specific database information.
$host "localhost";
$user "admblogdetailzus";
$pass "OLIVIAlynn616";
$db "dbuser";
The db = "dbuser" DBUSER is the name of the table I called it as in the directions. It's not the name of my database. So I changed that to the actual name of the database which is: admblogdetailzus The same as the username. I should or could just name the user name to anything.

Last edited by DIVAD3; 2010-03-04 at 02:27 PM..
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 02:32 PM   #17
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
I am questioning this part of things as well. Because I don't understand why I have nothing stated as far as a email would be concerned if I am having the values and password indicating something. The actual Register php page has a place for an entry of a email.
http://www.detailzusedcars.com/us-au...4/register.php and this page also indicated a failure to connect to database as the login page does.

This is from the register.php:

Quote:
// Fields are clear, add user to database
// Setup query
$q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
."VALUES ('".$_POST["admblogdetailzus"]."', "
."PASSWORD('".$_POST["OLIVIAlynn616"]."'), "
."'".$_POST["email"]."')";
// Run query
$r = mysql_query($q);

Last edited by DIVAD3; 2010-03-04 at 02:49 PM..
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 04:57 PM   #18
mark6188
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
mark6188's Avatar
 
Join Date: Sep 2009
Posts: 88
Send a message via ICQ to mark6188
the username and database name almost always have a prefix that I'm not seeing in your code.

Usually it's the sign in ID to create a mysql database. So if I sign into my host with 'malexander'

then my username would be 'malexander_admblogdetailzus'.

The database name would be 'malexander_dbuser'.

Hence you would write $user="malexander_admblogdetailzus";
$db="malexander_dbuser";
__________________
My Blog: Working The Business
mark6188 is offline   Reply With Quote
Old 2010-03-04, 05:14 PM   #19
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
UM....

Quote:
Originally Posted by mark6188 View Post
the username and database name almost always have a prefix that I'm not seeing in your code.
Usually it's the sign in ID to create a mysql database. So if I sign into my host with 'malexander' then my username would be 'malexander_admblogdetailzus'. The database name would be 'malexander_dbuser'. Hence you would write $user="malexander_admblogdetailzus";
$db="malexander_dbuser";
----------------
Um - This has me baffled by what your saying. I am addressing this matter to you in a PM. Plz C Ur Mail Mark. After you read ur mail you might begin to see that I just might be confusing the whole database system. I don't know for sure. But I am thinking this due to how I named things in setting up the script. And pehpas the simple solution would be to just rename things in the script as for username and password are concernd.

In Looking at my notes of how I set things up. I cannot find anything similiar to how you are discribing things. However I am probably overlooking the simplicity of what your saying. When I set up the database in mysql. I gave it a hostname of: mysqldb2.ehost-services.com / Also noted here is:
Protocal version: 10
MYSQL charset:UTF-8 unicode
USER: divad3@69.156.200 (i assume its a IP Address) But it isnt mine on my pc. blah blah blah ..webserver info and phpmyadmin - version information 3.1.5..

Originally when I first got involved with learning to create a table. I had created a table called divad3_admin. But that table was unsuccessful because when I went to save it. I had gotten logged off from the host for having one window to many open at the same time I was working in the database. So it wasn't saved.

And the database of admblogdetailzus was a suggested name. Due to the ones I was trying to have wasnt being accepted.

Last edited by DIVAD3; 2010-03-04 at 06:00 PM..
DIVAD3 is offline   Reply With Quote
Old 2010-03-04, 09:10 PM   #20
mark6188
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
mark6188's Avatar
 
Join Date: Sep 2009
Posts: 88
Send a message via ICQ to mark6188
Just got home, I'll take a quick look.
__________________
My Blog: Working The Business
mark6188 is offline   Reply With Quote
Old 2010-03-04, 11:04 PM   #21
mark6188
I'm going to the backseat of my car with the woman I love, and I won't be back for TEN MINUTES
 
mark6188's Avatar
 
Join Date: Sep 2009
Posts: 88
Send a message via ICQ to mark6188
Okay, fixed the database error and was able to add a new user.

You had several syntax errors - particularly quotes and double quotes- just too many to mention. (note: when you copy code from a website - watch the single and double quotes - you often have to replace them with the correct quote - difficult to explain but look at the quotes around this variable - `username` -need to change the quotes to 'username'.

You also selected the wrong table - dbUser instead of dbuser.

The table itself had errors in how you named the fields. You put a single quote around each one like 'username' when you should just put in username.

The php server was not on the same host as your database, so you have to point to the correct host and not "localhost" in the dbConfig.php file.

Another not so obvious fix was the password itself - I had to run a simple password query to make the password work. SETPASSWORD = OLD_PASSWORD('OLIVIAlynn616');

There are still some problems with the "Input vaildation" section of code as it doesn't detect when I leave a field blank.

I added some code and rewrote some of the other stuff to be clearer on what's going on and what's passing around. I also added the mysql_error() function to help diagnose some of the problems. you should use this everywhere - it's helps a lot.

That's about all I can do tonight, really tired. But you are up and running more or less. If you still have trouble, I'll try and help you out tomorrow.
__________________
My Blog: Working The Business

Last edited by mark6188; 2010-03-04 at 11:10 PM..
mark6188 is offline   Reply With Quote
Old 2010-03-04, 11:43 PM   #22
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
Quote:
Originally Posted by mark6188 View Post
That's about all I can do tonight, really tired. But you are up and running more or less. If you still have trouble, I'll try and help you out tomorrow.
Wow ! Thats alot I had wrong. Thanks so very much Mark. I am going to read what you wrote several times so that it sinks in and I retain what you have explained here. Yes it is late and I just got in. My Black Lab Minuit needs a walk and I need the pillow as well,. So i'll check out things when I return from Minuits walk. I am silly - I always spell it right out about having a Black Lab instead of just saying the dog. I am so proud of the fact that she is a Black Lab, that I always find myself stating the fact as if I am bragiing about her. lol

Good night Mark and thanks again! ttyl
DIVAD3 is offline   Reply With Quote
Old 2010-03-05, 12:40 AM   #23
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
Hi Mark! I went to the register php url and registered a user name of agnew95 gave it a password of oliver and my email of davidsabode@yahoo.com / It worked and brought up a page THANKS FOR REGISTERING. Then I went to the login php. using the same info that was just registered and the result was a page saying: Sorry, could not log you in. Wrong login information.

Ok so now I am just looking inside your work at the configuration php And I see that I did need to use this: host = 'admblogdetailzus.db.3474803.hostedresource.com / including the dot com.

After checking the login php I have trryed to log in with the username and password as indicated in the php file. The result was the same: Wrong login information. Hey I am happy to see at least the register php file is working. I am elated indeed.

Thank you Mark ! I must call it a night. Its after midnight here in NY 12:45 to be exact. TTYL Have a good nights rest Mark!

Di' Vad

Last edited by DIVAD3; 2010-03-05 at 12:43 AM..
DIVAD3 is offline   Reply With Quote
Old 2010-03-05, 12:27 PM   #24
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
So if I am to understand this correctly, things like the following are double quotations:

Quote:
$sql_insert = "INSERT into `users`
(`full_name`,`user_email`,`pwd`,`address`,`tel`,`fax`,`website`,`date`,`users_ip`,`activation_code`,`state`,`user_name`
Is that correct? And they need to look like this:
Quote:
$sql_insert = "INSERT into `users`
("full_name","user_email","pwd","address","tel","fax","website","date","users_ip","activation_code","state","user_name"
Or should they look like this: ('full_name','user_email',....

-------------------------
Time Lapse: Ok I think this site is giving me a handle on those matters...http://stackoverflow.com/questions/2...ome-so-popular

Last edited by DIVAD3; 2010-03-05 at 12:43 PM..
DIVAD3 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:59 AM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc