PHP catching flash variables

  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

hi all!
I know how to get my flash file to send variables to a php files using the GET function.

Now i want PHP to take these variables and post them into a Mysql database.

the flash form posts these variables...

name, password, email, location, age, gender, favteam , team, comments.

right

now, I have been using this code, and it doesn't work, it consists of a few tutorials mixed together :roll:

PHP Code: [ Select ]
 
<?
 
$host = 'localhost';
 
   $dbuser = '****';
 
   $dbpass = '*****';
 
   $dbname = '*****';
 
   $table = 'users';
 
 
 
mysql_connect("localhost","*****","*****") or die ("Unable to connect to MySQL server.");
 
$db = mysql_select_db("nucleo_cmc") or die ("Unable to select requested database.");
 
 
 
function register($name,$password,$email,$location,$age,$gender,$favteam,$team,$comments)
 
{
 
   $query = @mysql_query("INSERT INTO $table (name,password,email,location,age,gender,favteam,team,comments) VALUES "
 
   ."('$name','$password','$email','$location','$age','$gender','$favteam','$team','$comments')");
 
   if(!$query)
 
   {
 
      return "error=" . mysql_error();
 
   } else {
 
      return "user=ok";
 
   }
 
}
 
?>
 
 
  1.  
  2. <?
  3.  
  4. $host = 'localhost';
  5.  
  6.    $dbuser = '****';
  7.  
  8.    $dbpass = '*****';
  9.  
  10.    $dbname = '*****';
  11.  
  12.    $table = 'users';
  13.  
  14.  
  15.  
  16. mysql_connect("localhost","*****","*****") or die ("Unable to connect to MySQL server.");
  17.  
  18. $db = mysql_select_db("nucleo_cmc") or die ("Unable to select requested database.");
  19.  
  20.  
  21.  
  22. function register($name,$password,$email,$location,$age,$gender,$favteam,$team,$comments)
  23.  
  24. {
  25.  
  26.    $query = @mysql_query("INSERT INTO $table (name,password,email,location,age,gender,favteam,team,comments) VALUES "
  27.  
  28.    ."('$name','$password','$email','$location','$age','$gender','$favteam','$team','$comments')");
  29.  
  30.    if(!$query)
  31.  
  32.    {
  33.  
  34.       return "error=" . mysql_error();
  35.  
  36.    } else {
  37.  
  38.       return "user=ok";
  39.  
  40.    }
  41.  
  42. }
  43.  
  44. ?>
  45.  
  46.  


now then, i know it is bodged beyond repair lol

would any of you wiz dudes be able to write me a quick php script for this, its not complex

thanks for taking interest.

Nucleo
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Here you go Nucleo, Might get a better response here in Programing/scripting :wink:
  • dbzl
  • Born
  • Born
  • User avatar
  • Posts: 3

Post 3+ Months Ago

since your using the GET method maybe you should try this before you send the data:
PHP Code: [ Select ]
 
$name = $_GET['name'];
 
$password = $_GET['password'];
 
$email = $_GET['email'];
 
$location = $_GET['location'];
 
$age = $_GET['age'];
 
$gender = $_GET['gender'];
 
$favteam = $_GET['favteam'];
 
$team = $_GET['team'];
 
$comments = $_GET['comments'];
 
 
  1.  
  2. $name = $_GET['name'];
  3.  
  4. $password = $_GET['password'];
  5.  
  6. $email = $_GET['email'];
  7.  
  8. $location = $_GET['location'];
  9.  
  10. $age = $_GET['age'];
  11.  
  12. $gender = $_GET['gender'];
  13.  
  14. $favteam = $_GET['favteam'];
  15.  
  16. $team = $_GET['team'];
  17.  
  18. $comments = $_GET['comments'];
  19.  
  20.  

eh, u know what i mean.
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

nucleo, try this

PHP Code: [ Select ]
 
<?
 
$host = 'localhost';
 
   $dbuser = '****';
 
   $dbpass = '*****';
 
   $dbname = '*****';
 
   $table = 'users';
 
 
 
$link = mysql_connect("localhost","nucleo_cmc","reserved") or die ("Unable to connect to MySQL server.");
 
mysql_select_db("nucleo_cmc") or die ("Unable to select requested database.");
 
 
 
$name = $_GET['name'];
 
$password = $_GET['password'];
 
$email = $_GET['email'];
 
$location = $_GET['location'];
 
$age = $_GET['age'];
 
$gender = $_GET['gender'];
 
$favteam = $_GET['favteam'];
 
$team = $_GET['team'];
 
$comments = $_GET['comments'];
 
 
 
   $query = @mysql_query("INSERT INTO $table (name,password,email,location,age,gender,favteam,team,comments) VALUES "
 
   ."('$name','$password','$email','$location','$age','$gender','$favteam','$team','$comments')");
 
   if(!$query)
 
   {
 
      echo "error=" . mysql_error();
 
   } else {
 
      echo "user=ok";
 
   }
 
 
 
mysql_close($link);
 
 
 
?>
 
 
  1.  
  2. <?
  3.  
  4. $host = 'localhost';
  5.  
  6.    $dbuser = '****';
  7.  
  8.    $dbpass = '*****';
  9.  
  10.    $dbname = '*****';
  11.  
  12.    $table = 'users';
  13.  
  14.  
  15.  
  16. $link = mysql_connect("localhost","nucleo_cmc","reserved") or die ("Unable to connect to MySQL server.");
  17.  
  18. mysql_select_db("nucleo_cmc") or die ("Unable to select requested database.");
  19.  
  20.  
  21.  
  22. $name = $_GET['name'];
  23.  
  24. $password = $_GET['password'];
  25.  
  26. $email = $_GET['email'];
  27.  
  28. $location = $_GET['location'];
  29.  
  30. $age = $_GET['age'];
  31.  
  32. $gender = $_GET['gender'];
  33.  
  34. $favteam = $_GET['favteam'];
  35.  
  36. $team = $_GET['team'];
  37.  
  38. $comments = $_GET['comments'];
  39.  
  40.  
  41.  
  42.    $query = @mysql_query("INSERT INTO $table (name,password,email,location,age,gender,favteam,team,comments) VALUES "
  43.  
  44.    ."('$name','$password','$email','$location','$age','$gender','$favteam','$team','$comments')");
  45.  
  46.    if(!$query)
  47.  
  48.    {
  49.  
  50.       echo "error=" . mysql_error();
  51.  
  52.    } else {
  53.  
  54.       echo "user=ok";
  55.  
  56.    }
  57.  
  58.  
  59.  
  60. mysql_close($link);
  61.  
  62.  
  63.  
  64. ?>
  65.  
  66.  


there are some minor security issues with this but it should do the job.
  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

thanks a bunch rjstephens i will try it inabit.

please

erm, you or a mod edit the post and remove the username/password....please

i forgot about that
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

done.
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

oh, I see you want all of them removed. Done.
  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

hehe, im sorry lol
i said i used the GET function, i actually used the POST function, just switched it.
my registration form works sweet now :)

thanks rjstephens

now then...

how can i stop duplicate information from being posted?

this is what i have now
PHP Code: [ Select ]
<?
 
$host = 'localhost';
 
   $dbuser = '*******';
 
   $dbpass = '********';
 
   $dbname = '*******';
 
   $table = 'users';
 
 
 
$link = mysql_connect("localhost","******","********") or die ("Unable to connect to MySQL server.");
 
mysql_select_db("***") or die ("Unable to select requested database.");
 
 
 
$name = $_POST['name'];
 
$password = $_POST['password'];
 
$email = $_POST['email'];
 
$location = $_POST['location'];
 
$age = $_POST['age'];
 
$gender = $_POST['gender'];
 
$favteam = $_POST['favteam'];
 
$team = $_POST['team'];
 
$comments = $_POST['comments'];
 
 
 
   $query = @mysql_query("INSERT INTO $table (name,password,email,location,age,gender,favteam,team,comments) VALUES "
 
   ."('$name','$password','$email','$location','$age','$gender','$favteam','$team','$comments')");
 
   if(!$query)
 
   {
 
      echo "error=" . mysql_error();
 
   } else {
 
      echo "user=ok";
 
   }
 
 
 
mysql_close($link);
 
 
 
?>
  1. <?
  2.  
  3. $host = 'localhost';
  4.  
  5.    $dbuser = '*******';
  6.  
  7.    $dbpass = '********';
  8.  
  9.    $dbname = '*******';
  10.  
  11.    $table = 'users';
  12.  
  13.  
  14.  
  15. $link = mysql_connect("localhost","******","********") or die ("Unable to connect to MySQL server.");
  16.  
  17. mysql_select_db("***") or die ("Unable to select requested database.");
  18.  
  19.  
  20.  
  21. $name = $_POST['name'];
  22.  
  23. $password = $_POST['password'];
  24.  
  25. $email = $_POST['email'];
  26.  
  27. $location = $_POST['location'];
  28.  
  29. $age = $_POST['age'];
  30.  
  31. $gender = $_POST['gender'];
  32.  
  33. $favteam = $_POST['favteam'];
  34.  
  35. $team = $_POST['team'];
  36.  
  37. $comments = $_POST['comments'];
  38.  
  39.  
  40.  
  41.    $query = @mysql_query("INSERT INTO $table (name,password,email,location,age,gender,favteam,team,comments) VALUES "
  42.  
  43.    ."('$name','$password','$email','$location','$age','$gender','$favteam','$team','$comments')");
  44.  
  45.    if(!$query)
  46.  
  47.    {
  48.  
  49.       echo "error=" . mysql_error();
  50.  
  51.    } else {
  52.  
  53.       echo "user=ok";
  54.  
  55.    }
  56.  
  57.  
  58.  
  59. mysql_close($link);
  60.  
  61.  
  62.  
  63. ?>


i hate to keep asking for help, but how can i alter this to make it do
[/code]print "_root.Status=Error, *** already in use&_root.CheckLog=1";[/code]

so it then prints "*** already in use" if a:
Username is in use
Email address is in use
Team Name already in use.

just tell me what to add and where to add it, i will do the rest.

i really appreciate this.

Nucleo
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

Nucleo, what you are asking for is not trivial.

I'll have a go. I'm not sure wether or not this will work.

PHP Code: [ Select ]
 
<?php
 
$host = 'localhost';
 
   $dbuser = '*******';
 
   $dbpass = '********';
 
   $dbname = '*******';
 
   $table = 'users';
 
 
 
$link = mysql_connect("localhost","******","********") or die ("Unable to connect to MySQL server.");
 
mysql_select_db("***") or die ("Unable to select requested database.");
 
 
 
$name = $_POST['name'];
 
$password = $_POST['password'];
 
$email = $_POST['email'];
 
$location = $_POST['location'];
 
$age = $_POST['age'];
 
$gender = $_POST['gender'];
 
$favteam = $_POST['favteam'];
 
$team = $_POST['team'];
 
$comments = $_POST['comments'];
 
 
 
//check the database for duplicate entries
 
$result = mysql_query("select name, email, team from $table where name = '$name' or email = '$email' or team = '$team' limit 1");
 
 
 
$line = mysql_fetch_row($result);
 
 
 
if ($line[0] === $name)
 
{
 
    echo "Username is in use";
 
    exit();
 
}
 
elseif ($line[1] === $email)
 
{
 
    echo "Email address in use";
 
    exit();
 
}
 
elseif ($line[2] === $email)
 
{
 
    echo "Team Name already in use";
 
    exit();
 
}
 
 
 
mysql_free_result($result);
 
 
 
 
 
 
 
//at this point, we know that the data is not a duplicate.  So we can insert it.
 
   $query = @mysql_query("INSERT INTO $table (name,password,email,location,age,gender,favteam,team,comments) VALUES "
 
   ."('$name','$password','$email','$location','$age','$gender','$favteam','$team','$comments')");
 
   if(!$query)
 
   {
 
      echo "error=" . mysql_error();
 
   } else {
 
      echo "user=ok";
 
   }
 
 
 
mysql_close($link);
 
 
 
?>
  1.  
  2. <?php
  3.  
  4. $host = 'localhost';
  5.  
  6.    $dbuser = '*******';
  7.  
  8.    $dbpass = '********';
  9.  
  10.    $dbname = '*******';
  11.  
  12.    $table = 'users';
  13.  
  14.  
  15.  
  16. $link = mysql_connect("localhost","******","********") or die ("Unable to connect to MySQL server.");
  17.  
  18. mysql_select_db("***") or die ("Unable to select requested database.");
  19.  
  20.  
  21.  
  22. $name = $_POST['name'];
  23.  
  24. $password = $_POST['password'];
  25.  
  26. $email = $_POST['email'];
  27.  
  28. $location = $_POST['location'];
  29.  
  30. $age = $_POST['age'];
  31.  
  32. $gender = $_POST['gender'];
  33.  
  34. $favteam = $_POST['favteam'];
  35.  
  36. $team = $_POST['team'];
  37.  
  38. $comments = $_POST['comments'];
  39.  
  40.  
  41.  
  42. //check the database for duplicate entries
  43.  
  44. $result = mysql_query("select name, email, team from $table where name = '$name' or email = '$email' or team = '$team' limit 1");
  45.  
  46.  
  47.  
  48. $line = mysql_fetch_row($result);
  49.  
  50.  
  51.  
  52. if ($line[0] === $name)
  53.  
  54. {
  55.  
  56.     echo "Username is in use";
  57.  
  58.     exit();
  59.  
  60. }
  61.  
  62. elseif ($line[1] === $email)
  63.  
  64. {
  65.  
  66.     echo "Email address in use";
  67.  
  68.     exit();
  69.  
  70. }
  71.  
  72. elseif ($line[2] === $email)
  73.  
  74. {
  75.  
  76.     echo "Team Name already in use";
  77.  
  78.     exit();
  79.  
  80. }
  81.  
  82.  
  83.  
  84. mysql_free_result($result);
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. //at this point, we know that the data is not a duplicate.  So we can insert it.
  93.  
  94.    $query = @mysql_query("INSERT INTO $table (name,password,email,location,age,gender,favteam,team,comments) VALUES "
  95.  
  96.    ."('$name','$password','$email','$location','$age','$gender','$favteam','$team','$comments')");
  97.  
  98.    if(!$query)
  99.  
  100.    {
  101.  
  102.       echo "error=" . mysql_error();
  103.  
  104.    } else {
  105.  
  106.       echo "user=ok";
  107.  
  108.    }
  109.  
  110.  
  111.  
  112. mysql_close($link);
  113.  
  114.  
  115.  
  116. ?>


it is worthwile mentioning that you really shoud use mysql_escape_string() before you send data to mysql, but PHP's mysql implementaion limits the damage that can be done without a detailed understanding of how the script in question works.
  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

i will give this a go, thanks so much rjstephens
if you wanted to know all this is for an online football management me and some friends are making.

i can do the flash part, well most of it, i just suck at php lol

thanks again

no doubt i will keep asking for help on this lol

cus after this i got to sort out querying mysql for certain data, then presenting it in flash lol
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

Nucleo, I am eagerly awaiting how it goes.

It is worth mentioning that I compared the values returned from mysql using the '===' operator, rather than the '==' operator which is normally used.

The reason? '===' is up to 2 times faster depending on the situation.

Sometimes you have to use '==' but in this case either would be fine.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

You could also set your email, team name and any other field you wanted to a unique key. This will cut out the additional select statement and you won't have to write any PHP code to deal with checking for duplication.

Effectively all you would do is the insert statement, if the DB returns an error saying duplicate value for key x, then watch the key number up the row name and that will give you the error message to be displayed.

I try to let the DBMS manage the DB rather than writing external PHP code to deal with it - like transactions - bless their little socks.
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

rabid the only problem with that method is if the error messages change when you upgrade your DBMS. It's unlikely, but it is entirely possible. I prefer the extra select statement method because a dbms upgrade won't break it.

It is also more resistant to a change in DBMS.

Maybe implement both systems?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

This is also true.

The only thing is that alot of our PHP code is going to have to change anyways for portablity to PHP 5 - which is on it's release candidate.

I would implement both systems and have the error checking set to something easily configurable, like a master include file or something.
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

Rabid, I have had a brief look at PHP 5 and I don't think that there is too much that will need changing. most of the existing code will still run.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

I also thought that but then I installed PHP 5 and tried to run some of my simple apps. Needless to say they didn't work (maybe it is the developer here and not the langauge!) :wink:

Post Information

  • Total Posts in this topic: 16 posts
  • Users browsing this forum: No registered users and 70 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.