PDA

View Full Version : problem with php/MySql.....I think!


vosgien
01-23-2003, 03:43 PM
Hi,
I am having a few probs with some php/MySql, I am making a user management system using Flash as front end with a MySql db and php.
However when testing, nothing is happenning. My user panel tells me there are no entries in the db so I guess it is failing at the first line of code.
I have checked and double checked my pathing, and unless I am missing something obvious that seems all OK
I have posted my pph file and included are notes about the flash file and the db - if anyone has the time to take a look - it would be very helpful as this is driving me a little crazy!

Cheers

Vosgien

jimburton
01-24-2003, 01:42 PM
I haven't checked your files but here's something I usually do:

to debug calls from flash to php, use loadVars.send(url,"_blank") or xml.send(url,"_blank") or getURL with a POST|GET, rather than any of the silent methods - then your php will open in a new window and you will be able to echo or display the input - then you'll know whether your problem is in actionscript or if it occurs after that...

If your method depends on POST, remember that test mode in the authoring env can only send GET, & I think the same goes for the player - so publish it and preview in a browser. (Flash should have this written on the tin, I once wasted DAYS on it!:rolleyes:)

good luck,

vosgien
01-24-2003, 05:22 PM
Hi,
Thanks for those encouraging comments Jim, basically the php I posted the other day was never going to work, as I was cobbling it together from a serious of tutes and what have you ?
I decided to go back and have a look at some basic php tute and have a go at building my own.
The code below shows how far I have got, but I still cannot seem to open my database- i've double checked the syntax and I cannot see why it will not work - any ideas please !!

Cheers

Vosgien

phpscript is:
<?php
//
username = $username
password = $password
email = $email
count = $count
//declares vars in php and flash//////////

require 'include.php';
//include php has passwords, username and path for MySql///////

// This connects to the database./////////////////
mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName");

$query =" SELECT username FROM users WHERE username = $username";
$result=mysql_query($query);
$user=mysql_fetch_array($result);
if ($user[username] == $username) {
$count = 1
print "count = $count";
//this increments the var count in the flash movie which will then display
//a try again message
} else {
$query = INSERT INTO users (usersname, password, email, ipaddress, time, user_id) VALUES ($username,$password,$email, $ipaddress, NOW, NULL)
$result = mysql_query($query);
$count = 2;
print "count = $count";
//this tells flash to display a success message
}

?>

ps although working in MX I am using loadVariablesNum

jimburton
01-25-2003, 02:10 PM
here are some changes:


<?php
//
username = $username
password = $password
email = $email
count = $count
//declares vars in php and flash//////////

require 'include.php';
//include php has passwords, username and path for MySql///////

// This connects to the database./////////////////
mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName");

$query =" SELECT username FROM users WHERE username =".$username;
$result=mysql_query($query);
$user=mysql_fetch_array($result);
if ($user["username"] == $username) { ????
$count = 1
print "count = $count";
//this increments the var count in the flash movie which will then display
//a try again message
} else {
$query = "INSERT INTO users (usersname, password, email, ipaddress, time, user_id) VALUES (".$username.",".$password.",".$email.",". $ipaddress.",".time().",null)";
$result = mysql_query($query);
$count = 2;
print "count = $count";
//this tells flash to display a success message
}

?>

[...in last bit of sql I put in the time() method which returns current unix time, don't know if that's what you need for that column in the db...]

but there is some unnecessary code - you check against the username once in the first sql, then again at if statement - I think you could just say:
if(mysql_fetch_array($result)) {
//..etc
} else {

}


and you output the same thing to page whether they should try again or not - count=$count - shouldn't that be something different if they have been successfully added? Also check whether the insert went ok before outputting with

if(mysql_affected_rows()) {
//...
}

vosgien
01-25-2003, 03:21 PM
Hi Jim,
Thanks for taking the time, some of the changes you made I had already got to ( just a few), I have been taking the code apart line by line,the syntax always gets me !
$count is set to one or two depending on the if else argument, once it is set the line print"count = $count"; - should send the var at the correct value back to Flash - once I am happy that the php and mySql are responding I can move on to testing the flash part.
Thanks again.

Vosgien

jimburton
01-25-2003, 03:25 PM
I see :)

vosgien
01-31-2003, 06:51 AM
Hi,
Not sure if you are still following this thread Jim or if you (or anyone else) has the time etc to help further
I am still experiencing a few problems here - specifically with debugging - I am learnig php on the hoof so debugging is a bit of a mystery.

What the php is supposed to do is :
user enters a desired username and password, clicks submit,
php opens db and checks to see if pw already in use, if yes, sends a try again message back to Flash, if no, inserts pw and un into the db and sends a success message back to flash.

Now for debuggin I have used : getURL ("index.php", "_new", "POST" ) - this tells me that a specific command:

($user=mysql_fetch_array($result);

isn't reponding and that I have a parsing error.
Next, I tried inserting into my php code the following line:

print "SELECT username FROM $table WHERE username = $username<br>";
- but it is not giving me any feedback, ditto if I use the same line as a MySql query.

So any help would be very much appreciated. My Flash code is OK, my php is nearly there, however, I need some help with debugging - or if there is any kindly soul out there who is able to take a look at my scripts I would be very delighted.

Cheers

Vosgien

freddycodes
02-01-2003, 09:22 PM
Why don't you post an updated zip file of what you have so far.

vosgien
02-02-2003, 07:01 AM
Hi freddycodes,
Attached is a zip file with a textfile outlining all the code used and explanations, so it should be pretty clear - here (http://www.test.bcats.com) is a test site which will open a index.php in a browser.
I feel sure that this is a small syntax error, problem is that having built ( succesfully ) a couple of conact and mailforward apps, I have not learnt the basics, which is something that I am correcting, but as I have said before, I need to solve this prob now.
Many Thanks for your time

Cheers

Vosgien

freddycodes
02-02-2003, 07:10 AM
First off your php script should look more like this.

<?php
//
//require 'include.php';
//include php has passwords, username tablename and path for MySql///////
$RegName = strtoupper ($RegName);
$RegName = ereg_replace("[^A-Za-z0-9 ]", "", $RegName);
// This connects to the database./////////////////
mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName");

$query = "SELECT username FROM $table WHERE username = '$username'";
$result=mysql_query($query);
//$user=mysql_fetch_array($result);
if (mysql_num_rows($result)) {
Print "&status=try again";
}
else {
$query = "INSERT INTO $table (usersname, password, email, ipaddress, time) VALUES ('$username','$password','$email','$ipaddress',NOW ())";
$result = mysql_query($query);
Print "&status=success!!!"
//this tells flash to display a success message
}

?>


Second why is a new browser opening up? Is this Flash MX or Flash 5?

vosgien
02-02-2003, 11:04 AM
Hi,
Thanks for that, I will test it a little later and get back. A new browser opens as under the loadVariablesNum action I have a getURL ("index.php", "_new","POST") for debugging purposes. I left it there for anyone to see the errors that php was throwing up.
It was pretty useless really, as once I got the errors I had no idea what to with them (lol!!) As I said previously, I need to go back to beginning on php instead of jumping in at the middle - could save myself ( and others ) a lot of time.
Although working in MX the original project was started in 5, I decided to get the back end scripts working before changing the as to LoadVars - the as side of the app is not a prob for me.
Thank you again - will post result a bit later

Cheers

Vosgien