Welcome, Guest
  • Author Topic: need help on scripting  (Read 5665 times)

    stephan84

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    need help on scripting
    « on: 05/15/07, 19:53 »
    I have a problem with a script I'm using to register variables into a mySQL database.  I got the script from a tutorial, and can get the script to read from the database, but not write to it.

    the actionscript is as follows:

    on (release) {
       Status = "Beginning registration Process... Please Hold";
       loadVariablesNum ("Register.php?RegName="+RegName,0,"post");
    }

    this gets data from a text field, the var name of this text field is RegName.


    the php for login is as follows:

    <?
    foreach($HTTP_GET_VARS as $name => $value) { $$name = $value;}
    foreach($HTTP_POST_VARS as $name => $value) { $$name = $value;}
    foreach($HTTP_COOKIE_VARS as $name => $value) { $$name = $value;}

    ##The login script accesses the database and checks to see whether your Login name exists. If it does it will select your information from the database and Print it out back to Flash.

    ##This first line of Code is to load your database variables - The include File should be ##renamed with your database variables.
    include ('Include.inc');

    ##This line of Code changes the name to all UPPERCASE. This is so that the login Name is not ##case sensitive. You can make it case sensitive by leaving this line out.

    $Name = strtoupper ($Name);

    ##This line takes out everything from the $Name variable that is not a captital or lowercase letter or a interger between 0 and 9.  This line is only for security purposes so that users can not enter anything that could disrupt the database. You can take this line out if you want.  Or you can allow users to enter other symbols by including a \ followed by that character right after.

    $Name = ereg_replace("[^A-Za-z0-9 ]", "", $Name);

    #Connects to the database.
    mysql_connect($DBhost,$DBuser,$DBpass);
    @mysql_select_db("$DBName");

    #The SQL query
    $query = "SELECT * FROM $table WHERE Name = '$Name'";
    $result = mysql_query($query);

    #This just gets the number of rows in the Query - It's just a check to see if the Name exists - If not it prints out an error statement.
    $numR = mysql_num_rows($result);

    #If the number of rows is not equal to one then it prints out an error statement - Name not in Database.   
       if ($numR == 1) {
       print "Status=Success Login Complete&CheckLog=1";
       }
       else {
       print "Status=Failure - Your name was not found - Please register";
       }

    ?>

    this works fine.

    the php for the register is:

    <?

    ##The registration script adds a record to the SQL database with the user's Name. That's about it.

    ###This first line of Code is to load your database variables.
    include ('Include.inc');

    ##This line of Code changes the name to all UPPERCASE. This is so that the login Name is not ##case sensitive. You can make it case sensitive by leaving this line out.

    $RegName = strtoupper ($RegName);

    ##This line takes out everything from the $Name variable that is not a captital or lowercase letter or a interger between 0 and 9.  This line is only for security purposes so that users can not enter anything that could disrupt the database. You can take this line out if you want.  Or you can allow users to enter other symbols by including a \ followed by that character right after.
    $RegName = ereg_replace("[^A-Za-z0-9 ]", "", $RegName);

    #Connects to the Database.
    $Connect = mysql_connect($DBhost, $DBuser, $DBpass);
    @mysql_select_db("$DBName");

    #Preforms the SQL query
    $insert = "INSERT INTO $table (Name,Object1,Object2,Object3,Comment) VALUES ('".$_POST['$RegName']."','','','','Hello - Edit This')";
    $result = mysql_query($insert);

    #Gets the number of rows affected by the query as a check.
    $numR = mysql_affected_rows($Connect)or die("Status=failure, cannot insert");

    if ($numR == 0) {
    print "Status=Failure Please Fill out all Fields - Register Again";
    }
    else if ($numR == 1) {
    print "Status=Success You can Now Login - Login";
    }

    else { print "Status=General Error - UserName already in Use";
    }


    ?>

    this script seems to fail if I place an Or Die at $result = mysql_query($insert);
    So I assume that the problem is either that the scripting is not right to insert it into the database, or the scripting is not right to send the variables from flash.

    This is only the second day that I have been working in this scripting style (flash/php/mySQL)
    ,So just assume I am an idiot, and know nothing.

    thanks for any help.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: need help on scripting
    « Reply #1 on: 05/16/07, 02:16 »
    Hi Stephan and welcome to the boards.

    To understand how flash communicates with scripts, have a look into our tutorials for read and write.
    Ther you will find everything you need, and much more ;)
    happy flashing
    8)
    Ronald

    stephan84

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    Re: need help on scripting
    « Reply #2 on: 05/16/07, 07:13 »
    I've been checking through all the turtorials, and I just can't figure out what I'm doing wrong.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: need help on scripting
    « Reply #3 on: 05/16/07, 12:18 »
    do you have phpMyAdmin installed?

    make php print the sql statement, before it is executed, and try if it works in phpMyAdmin.

    There you will receive the errors helping you find the problem generating the sql statement.
    happy flashing
    8)
    Ronald

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re: need help on scripting
    « Reply #4 on: 05/16/07, 14:18 »
    Hi,

    I would use the die() like this:
    .... or die("scriip $insert results " . mysql_error());

    Musicman

    stephan84

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    Re: need help on scripting
    « Reply #5 on: 05/20/07, 10:13 »
    used PHPmyAdmin to make an sql statement that would add the value into the database.  Then I created a PHP statement from that...and it doesn't work when I use it with my flash program.
    So, I'm back to square-one.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: need help on scripting
    « Reply #6 on: 05/20/07, 16:19 »
    Flash itself has nothing to do with you mySQL or php code.
    All it does - sending values via POST or GET as a HTML-Form would do, and in turn, maybe receiving output of your script (if it puts something flash-readable towards the client).

    So dont blame flash, if your query does not run ;)
    happy flashing
    8)
    Ronald

    stephan84

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    Re: need help on scripting
    « Reply #7 on: 05/23/07, 10:10 »
    Pretty sure that flash is doing what it should.  I'm using the same formatting for both the login, and register section, which should get the job done.  For some reason, the php will no longer communicate with the mysql database when I run it from  outside phpMyAdmin.  I do not know what I am doing wrong.  I've been looking at this for several weeks now, and really need someone to look it over, and tell me what is wrong with the script.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: need help on scripting
    « Reply #8 on: 05/23/07, 15:17 »
    Ok, Stephan,
    what does the script tell you, if you call it?
    Could you give us a link, to have a look?
    happy flashing
    8)
    Ronald

    quadak

    • Server what's that
    • *
    • Posts: 1
      • View Profile
      • Email
    Re: need help on scripting
    « Reply #9 on: 06/15/07, 02:41 »
    I have the same problem, the script work only offline on my pc, when upload swf file to imagehack.us, (*.php on lycos.co.uk)  it doesn't work (waiting for... on status bar). login to my lycos  account, using my php admin, there have no record was  recorded.

    thank for any help.
    sorry for mistakes in my writting, i have just studied English this month !

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: need help on scripting
    « Reply #10 on: 06/15/07, 05:57 »
    did you adapt the config setting for the database?
    lycos usualy has some cryptic database names.
    happy flashing
    8)
    Ronald