Forum Moderators: coopster
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!
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.