Forum Moderators: coopster

Message Too Old, No Replies

PHP & DB storing info in cache

php and cache

         

rodriguez1804

2:51 pm on Jan 6, 2009 (gmt 0)

10+ Year Member



Hey guys,

I am having trouble getting a php script to store data in mySQL DB.

I have a simple html form that asks the user to register for a username and password.

It was working fine a few weeks ago, but now, it's gone berserk and it's storing the previous username entered. For example, when I try to register with username test2, it will register me as test1, from the previous registration attempt.

I have the following for the cache:
header("Cache-control: private, no-cache");
header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
header("Pragma: no-cache");

Any advice as to what may be causing the problem and how to fix it?
Thanks!

eelixduppy

3:23 pm on Jan 6, 2009 (gmt 0)



Does make much sense to me and I'm pretty sure it has nothing to do with your cache. You wouldn't by any chance be storing the username to a session variable and then adding it to the database that way would you? Can't really know what is going wrong without the code that you are using. If you can strip all the code except for that that puts the username into the database that would be helpful in finding any issues with it.

rodriguez1804

6:56 pm on Jan 6, 2009 (gmt 0)

10+ Year Member



Hi eelixduppy, here is the code that I have: it's only a working draft, so disregard the state it's in.

After hitting the submit button on the registration form, the following code does a check on the user input, strips the user input , and then registers the user.


<?php
header("Cache-control: private, no-cache");
header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
header("Pragma: no-cache");
?>
<?php
error_reporting(E_ALL);
ob_start();
include_once "../../../../cuentameDocs/includes/db/dbInfo.php";

//check for form submission
if(isset($_POST['Submit'])){

//Connect to server and select database
$con; //predefined elsewhere to connect to DB
mysql_select_db("$db_name", $con) or die ("cannot select DB");

//Define the username and password
$myusername=stripslashes(mysql_real_escape_string($_POST['myusername']));
$mypassword=stripslashes(mysql_real_escape_string(md5($_POST['mypassword'])));

$myemail=stripslashes(mysql_real_escape_string($_POST['myemail']));
$mycity=stripslashes(mysql_real_escape_string($_POST['mycity']));
$mystate=stripslashes(mysql_real_escape_string($_POST['mystate']));
$myname=stripslashes(mysql_real_escape_string($_POST['myname']));
$mylastname=stripslashes(mysql_real_escape_string($_POST['mylastname']));

//get the first character of the username
$usernameFirstChar = substr($myusername,0,1);

//check to see if username already exists!
$count = mysql_num_rows(mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername'"));

if(($count) != 0)
{
echo "<div align='center' style='color:blue; font-weight:bold;'>That username is already taken, please choose another.</div><br />";
require_once("newUserFillOutTable.php"); die();
}

//perform additional data checks
else if(empty($myusername)){
echo "<div align='center' style='color:blue; font-weight:bold;'>You did not enter a username!</div><br />";
require_once("newUserFillOutTable.php"); die();
}

else if(empty($myname)){
echo "<div align='center' style='color:blue; font-weight:bold;'>You did not enter your name!</div><br />";
require_once("newUserFillOutTable.php"); die();
}

else if(empty($mylastname)){
echo "<div align='center' style='color:blue; font-weight:bold'>You did not enter your last name!</div><br />";
require_once("newUserFillOutTable.php"); die();
}

else if(empty($mycity)){
echo "<div align='center' style='color:blue; font-weight:bold'>You did not enter your hometown!</div><br />";
require_once("newUserFillOutTable.php"); die();
}

else if(empty($mystate)){
echo "<div align='center' style='color:blue; font-weight:bold'>You did not enter your state!</div><br />";
require_once("newUserFillOutTable.php"); die();
}

//email address check
include_once("../../../../cuentameDocs/includes/functions.php");
$emailCheck= validateEmail($myemail, true, true);
if($emailCheck==false){
echo "<div align='center' style='color:blue; font-weight:bold'>The email you have entered is an invalid email!</div><br />";
require_once("newUserFillOutTable.php"); die();
}

//imageVerification
session_start();
$errors = 0;
$number = md5($_POST['number']);
if(($number) != $_SESSION['image_value']){
echo"<div align='center' style='color:blue; font-weight:bold'>The letters and numbers you entered do not match! Please try again.</div><br />";
require_once("newUserFillOutTable.php"); die();
}

else{
//add user data to database
echo "Inserting the following name: ";
echo $myusername;
$sql="INSERT INTO $tbl_name (id, username, password, email, city, state, myname, mylastname, firstLetter) VALUES (NULL,'$myusername','$mypassword', '$myemail', '$mycity', '$mystate', '$myname', '$mylastname', '$usernameFirstChar')";

if(!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}

////////CREATE FOLDER UNDER USERNAME//////////////////////
//if($usernameFirstChar != (regEx([a-z][a-z][0-9])){execute the underneath};
directoryListingCheck('../../cuentame/_users_');

//place picture into user's folder
//picture verification
include_once("../imageVerification/imageUploadTest.php");

//copy index.php file to user's newly created folder
include_once("../../cuentameIncludes/copyFunctions/fileCopy.php");
$file1 = "../../cuentameIncludes/templates/userIndex/index.tpl";
$file2 = "../_users_/$usernameFirstChar/$myusername/index.html";
copyFiles($file1,$file2);

//copy userProfile page
$filea = "../../cuentameIncludes/templates/userIndex/myProfile.tpl";
$fileb = "../_users_/$usernameFirstChar/$myusername/myProfile.html";
copyFiles($filea, $fileb);

//Create user's public directory
makeUsersPublicDir('../../cuentame/_users_');

//copy user's public index into their public folder
$fileS = "../../cuentameIncludes/templates/userPublicIndex/userPublicIndex.tpl";
$fileD = "../_users_/$usernameFirstChar/$myusername/public/index.html";
copyFiles($fileS,$fileD);
/////////////////////END OF MATCHING CODE////////////////////////////////
}
echo "
<div align=\"center\" style=\"margin-top:40px; font-type:bold; font-size:20px;\">You have been registered!
<br />
<br />
You can now login with your new username and password.
</div>";
mysql_close($con);
header('Refresh:3; url="../../userLogin.html');
}
else{
if(!isset($_POST['myusername'])){
header("location:../../userLogin.html");
}
}
?>

Thanks for any help.

henry0

8:42 pm on Jan 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



not sure about it, but your id is autoincremented, correct?
If so you do not need to insert id (unless updating and asking MySQL to insert a new ID)
plus NULL does not really help
as such you will not enter any id then the query will always pick up the top one, problably the only one
NULL in MySQL will enter NULL
' ' will enter an empty str

rodriguez1804

11:08 pm on Jan 6, 2009 (gmt 0)

10+ Year Member



Ok, so my script seems to be working fine now. I've tested it in IE and FF and it's working. I ve been making updates and changes to the site, but nothing in particular to the actual script. So for now, this will do