View Full Version : PLS HELP: Trying To Add Users to DB through Flash/PHP
madzigian
June 14th, 2005, 07:24 PM
Ok, i created a user login for my site using PHP and a MySQL database. I developed it from Freddythunder's tutorial on this site (http://kirupa.com/developer/actionscript/authentication.htm). It works perfectly now, after tweaking it a bit...but it's currently set up where you have to add users through a php file (usercheck.php). i want to be able to add users from an "admin" page in my Flash site....so i removed all the HTML and form tags from usercheck.php and saved it as adduser.php and set up my flash file exactly as the HTML elements in usercheck.php. I figured that it would work the same way...but for some reason....it doesn't work at all.
INCLUDED FILES IN ATTACHED .ZIP:
addNewUsers.fla (MX2004 format)
adduser.php
usercheck.php
I have NO knowledge of php so i can't really figure out why it doesn't work properly. All the variables are set up correctly in the flash file (i think)....
here is what the addusers.php file looks like in case someone can spot something obviously wrong in it:
<?PHP
$newUser = $_POST['newUser'];
$passOne = $_POST['passOne'];
$passTwo = $_POST['passTwo'];
//these variables are set to 3 corresponding input boxes in flash file
//
if ($passOne == $passTwo) {
$newPass = $passOne;
//
} else {
print "response=Passwords mismatched";
//response is a dynamic text box's variable in flash file
}
//
if (($REQUEST_METHOD=='POST')) {
for(reset($HTTP_POST_VARS);
$key=key($HTTP_POST_VARS);
next($HTTP_POST_VARS)) {
$this = addslashes($HTTP_POST_VARS[$key]);
$this = strtr($this, ">", " ");
$this = strtr($this, "<", " ");
$this = strtr($this, "|", " ");
$$key = $this;
}
//
//I have the values for mysql.host.com, username,
//password, and database_name set up properly in the real file
if ($newUser && $newPass ) {
$query = "insert into auth (userid,username,userpassword) ";
$query .= "VALUES(0000,'$newUser','$newPass')";
mysql_connect("mysql.host.com","username","password")
or die("Unable to connect to SQL server");
mysql_select_db("database_name") or die("Unable to select database");
$result = mysql_query($query) or die("Insert Failed!");
}
}
//
if ( $result ){
print "response=You have successfully entered ".$newUser." with the password of ".$newPass." into the database!!";
}
?>
<?
$queryb="SELECT COUNT(*) FROM auth";
mysql_connect("mysql.host.com","username","password")
or die("Unable to connect to SQL server");
mysql_select_db("database_name") or die("Unable to select database");
$numusers=mysql_query($queryb) or die ("Select Failed - count");
$numuser=mysql_fetch_array($numusers);
//
print "userNumber=There are currently " echo $numuser[0]; "users in the database.";
//userNumber is another dynamic text box's variable in flash file
?>
ANY help would be greatly appreciated!!!
thanks in advance....
Enigmatic
June 15th, 2005, 09:29 AM
<?php
include 'db.php';
$username = $_POST['username'];
$password = $_POST['password'];
$retype_password = $_POST['retype_password'];
$email = $_POST['email'];
$retype_email = $_POST['retype_email'];
$first_name = $_POST['first_name'];
$surname = $_POST['surname'];
$username = stripslashes($username);
$password = stripslashes($password);
$retype_password = stripslashes($retype_password);
$email = stripslashes($email);
$retype_email = stripslashes($retype_email);
$first_name = stripslashes($first_name);
$surname = stripslashes($surname);
if((empty($username)) || (empty($password)) || (empty($retype_password)) || (empty($email)) || (empty($retype_email)) || (empty($first_name)) || (empty($surname))){
echo 'You did not submit the following required information! <br />';
if(empty($username)){
echo "Username is a required field. Please enter it below.<br />";
}
if(empty($password)){
echo "Password is a required field. Please enter it below.<br />";
}
if(empty($retype_password)){
echo "Retype Password is a required field. Please enter it below.<br />";
}
if(empty($email)){
echo "Email is a required field. Please enter it below.<br />";
}
if(empty($retype_email)){
echo "Retype Email is a required field. Please enter it below.<br />";
}
if(empty($first_name)){
echo "First Name is a required field. Please enter it below.<br />";
}
if(empty($surname)){
echo "Last Name is a required field. Please enter it below.<br />";
}
include 'http://www.yourDomain.com/register.php';
exit();
}
$sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($password !== $retype_password) || ($email !== $retype_email) || ($email_check > 0) || ($username_check > 0)){
echo "Please fix the following errors: <br />";
if($password !== $retype_password){
echo "The passwords you have supplied do not match. Please re-enter your password!<br />";
}
if($email !== $retype_email){
echo "The Email addresses you have supplied do not match. Please re-enter your Email address!<br />";
}
if($email_check > 0){
echo "<strong>That Email address is already registered in our Database. Please submit a different Email address!<br />";
}
if($username_check > 0){
echo "The username you have selected is already in use. Please choose a different Username!<br />";
}
include 'http://www.yourDomain.com/register.php';
exit();
}
$db_password = md5($password);
$sql = mysql_query("INSERT INTO users (username, password, email, first_name, surname, gender, signup_date)
VALUES('$username', '$db_password', '$email', '$first_name', '$surname', '$gender', now())") or die (mysql_error());
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
$userid = mysql_insert_id();
$subject = "Your Membership at yourDomain.com!";
$message = "Dear $first_name $last_name,
Thank you for registering at our website, http://www.yourDomain.com!
You are two steps away from logging in and accessing our exclusive members area.
To activate your membership, please click here: http://www.yourDomain.com/activate.php?id=$userid&code=$db_password
Once you activate your memebership, you will be able to login with the following information:
Username: $username
Password: $password
Thanks!
The Webmaster
This is an automated response, please do not reply!";
mail($email, $subject, $message, "From: yourDomain.com Webmaster<webmaster@yourDomain.com>\nX-Mailer: PHP/" . phpversion());
echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
}
?>
Enigmatic
June 15th, 2005, 11:41 AM
If you looking to add a user through a "admin" page, could it not just be in html?php rather than flash. If so you could do something similar to the following :
<?PHP
$dbhost = "localhost";
$dbuser = "username";
$dbpass = "password";
$dbname = "username_dbname";
$connect = mysql_pconnect("$dbhost", "$dbuser", "$dbpass")
or die ("Could not connect : " . mysql_error());
$dbselect = mysql_select_db("$dbname", $connect)
or die ("Could not select db : " . mysql_error());
$username = $_POST['username'];
$usernameCheck = $_POST['usernameCheck'];
$userpass = $_POST['password'];
$userpassCheck = $_POST['passwordCheck'];
$useremail = $_POST['email'];
$useremailCheck = $_POST['emailCheck'];
$username = trim($username);
$usernameCheck = trim($usernameCheck);
$userpass = trim($password);
$userpassCheck = trim($passwordCheck);
$useremail = trim($email);
$useremailCheck = trim($emailCheck);
if((empty($username)) || (empty($usernameCheck)) || (empty($password)) || (empty($passwordCheck)) ||
(empty($email)) || (empty($emailCheck))) {
echo "You did not submit the following information !! <br />";
if(empty($username)) {
echo "Please supply a username !! <br />";
}
if(empty($usernameCheck)) {
echo "Please enter your username in both fields !! <br />";
}
if(empty($password)) {
echo "Please supply a password !! <br />";
}
if(empty($passwordCheck)) {
echo "Please enter your password in both fields !! <br />";
}
if(empty($email)) {
echo "Please supply a valid email address !! <br />";
}
if(empty($emailCheck)) {
echo "Please enter you email address in both fields !! <br />";
}
exit();
}
$sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($username !== $usernameCheck) || ($password !== $passwordCheck) || ($email !== $emailCheck) || ($username_check
> 0) || ($email_check > 0)){
echo "Please correct the following errors ... <br />";
if($username !== $usernameCheck) {
echo "Username fields do not match !! <br />";
}
if($password !== $passwordCheck) {
echo "Password fields do not match !! <br />";
}
if($email !== $emailCheck) {
echo "Email fields do not match !! <br />";
}
if($username_check > 0) {
echo "Username is already in use. Please select another !! <br />";
}
if($email_check > 0) {
echo "Email is already in our database. Please enter a different email !! <br />";
}
exit();
}
$db_password = md5($password);
$sql = mysql_query("INSERT INTO tblName (username, password, email, signup_date)
VALUES('$username', '$db_password', '$email', now())")
or die (mysql_error());
?>
<html>
<head>
<title>Add User Form</title>
<style type="text/css">
.blackText
{
font-family:Verdana, Arial, Helvetica, sans-serif;
color:#000000;
font-size:10px;
}
.inputBox
{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10;
color:#000099;
height:18px;
width:190px;
border-color:#666666;
border-width:1px;
background-color:#FFFFFF;
}
.button
{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10;
color:#000000;
height:18px;
width:70px;
border-color:#666666;
border-width:1px;
background-color:#CCCCCC;
}
</style>
</head>
<body>
<form name="myForm" action"<?PHP $_SERVER['PHP_SELF'] ?>">
<table>
<tr>
<td class="blackText" align="right">Username :</td>
<td><input type="text" name="username" size="30" class="inputBox"></td>
</tr>
<tr>
<td class="blackText" align="right">Username Check :</td>
<td><input type="text" name="usernameCheck" size="30" class="inputBox"></td>
</tr>
<tr>
<td class="blackText" align="right">Password :</td>
<td><input type="text" name="password" size="30" class="inputBox"></td>
</tr>
<tr>
<td class="blackText" align="right">Password Check :</td>
<td><input type="text" name="passwordCheck" size="30" class="inputBox"></td>
</tr>
<tr>
<td class="blackText" align="right">Email :</td>
<td><input type="text" name="email" size="30" class="inputBox"></td>
</tr>
<tr>
<td class="blackText" align="right">Email Check :</td>
<td><input type="emailCheck" size="30" class="inputBox"></td>
</tr>
<tr>
<td> </td>
<td><input type="reset" value="Reset" class="button"> <input type="submit" value="Confirm"
class="button"></td>
</tr>
</table>
</form>
</body>
</html>
madzigian
June 15th, 2005, 01:37 PM
Enigmatic, thanks for the reply and the time you spent writing the code above. i already have an html form that adds usernames and passwords.... I'm trying to switch it over to work in flash. the php that i use is included in the attached .zip. i set up the flash file exactly like the html part of the php file...and my "add user" button is supposed to "POST" the entered info from input boxes to the php/MySQL database..... i want to do this through Flash so i can eventually turn it into a login where new users can register themselves...and i don't have to enter the information for them.
madzigian
June 17th, 2005, 01:38 PM
bump
cholin
June 19th, 2005, 01:06 AM
I don't quite feel like writing it all right now, but this thing is for admin only right, meaning only you can access it? If so, all you gotta do is use a PHP file that checks if the username already exists, then enters the info you POST through flash if it doesnt. It's a simple concept, just use flash instead of your HTML form, it all works the same. If you're THAT desperate, I can write one quickly for you...
madzigian
June 20th, 2005, 01:24 PM
that is what i tried to do...... biut Flash is not communicating with the php file at all....
the php file i am trying to use does exactly what you suggested....but for one reason or another....i get no response from the php file back to flash. which means that the php file is not communicating with the MySQL database. if you take a look at the files i attached...you'll see what i mean.
madzigian
June 26th, 2005, 04:32 PM
bump
prstudio
June 28th, 2005, 05:41 AM
make sure you close your sql queries before that final ") make sure it's ;")
on those 3 queries -
also your problem with adding a user comes inside your .fla - on your "add" button the AS inside there merely loads the variables from the PHP file - it does not send anything from the flash file to the PHP script for processing.
here is what that code is:
on (release, keyPress "<Enter>") {
if (newUser != "" && passOne != "" && passTwo != "") {
response = "Adding new user to database...\nPlease wait...";
this.loadVariables("http://artofficialintel.com/php_uploads/adduser.php", "POST");
}
}
this line:
this.loadVariables("http://artofficialintel.com/php_uploads/adduser.php", "POST");
requests that all the variables from the adduser.php script are loaded into flash.
that is all it does - it doesn't send anything, it doesn't receive anything:
now im not going to give you the precise code, because i want you to understand how it works and like you said you are new to some of this so the practice will do you good :) you will have to adjust this script to fit the needs of both your .fla and your .php script -
--begin code-----------------------------------------------------------
//Declare our "container" to hold our variables for shipping
//to adduser.php
var AddUser = new LoadVars ();
//set variables equal to the text contained in your textboxes
//via instance name
var UserName = yourusertoadd.text;
var Password = yourpasswordtoadd.text;
//UserNameSent and PasswordSent are the variables received by the
//POST method in the PHP file -
AddUser.UserNameSent = Username;
AddUser.PasswordSent = Password;
//make a fake receive container to avoid pop-up
receivecontainer = new LoadVars();
//send our variables to adduser.php for processing
AddUser.sendAndLoad("adduser.php",receivecontainer, "POST");
--end code-------------------------------------------------------------
madzigian
July 7th, 2005, 05:14 PM
i don't5 understand WHERE to put the loadVars into the script.... nor do i understand where to put the "receiver" loadVars. i assume that my problem before was that i was using POST instead of SEND?? and where do i add the ;") ????? i'm completely retarded when it comes to this stuff... and i DO learn more by doing as opposed t5o having it done for me... i just need a bit more guidance and explanation if you would be so kind.
Thanks for your help thus far.... i just need a bit more to go on.
thanks M
make sure you close your sql queries before that final ") make sure it's ;")
on those 3 queries -
also your problem with adding a user comes inside your .fla - on your "add" button the AS inside there merely loads the variables from the PHP file - it does not send anything from the flash file to the PHP script for processing.
here is what that code is:
on (release, keyPress "<Enter>") {
if (newUser != "" && passOne != "" && passTwo != "") {
response = "Adding new user to database...\nPlease wait...";
this.loadVariables("http://artofficialintel.com/php_uploads/adduser.php", "POST");
}
}
this line:
this.loadVariables("http://artofficialintel.com/php_uploads/adduser.php", "POST");
requests that all the variables from the adduser.php script are loaded into flash.
that is all it does - it doesn't send anything, it doesn't receive anything:
now im not going to give you the precise code, because i want you to understand how it works and like you said you are new to some of this so the practice will do you good :) you will have to adjust this script to fit the needs of both your .fla and your .php script -
--begin code-----------------------------------------------------------
//Declare our "container" to hold our variables for shipping
//to adduser.php
var AddUser = new LoadVars ();
//set variables equal to the text contained in your textboxes
//via instance name
var UserName = yourusertoadd.text;
var Password = yourpasswordtoadd.text;
//UserNameSent and PasswordSent are the variables received by the
//POST method in the PHP file -
AddUser.UserNameSent = Username;
AddUser.PasswordSent = Password;
//make a fake receive container to avoid pop-up
receivecontainer = new LoadVars();
//send our variables to adduser.php for processing
AddUser.sendAndLoad("adduser.php",receivecontainer, "POST");
--end code-------------------------------------------------------------
madzigian
July 11th, 2005, 01:48 PM
bump
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.