-
Communication with SQL database
Hello,
I want to add email address to an SQL database that I have created on my webhost space.
On my site I have created an input text box with the variable name MailingEmail.
There is a button next to it. I need to know what code to put on the button so that it will add the MailingEmail to my SQL database.
The database is called MailingList.
Thanks for any help you can give me,
Graeme
-
Flashmatics
hi have a look at the tutorial PHP, MySQL, and Flash at www.gotoandlearn.com
it will put you on the right track
-
Thanks for that. Its an excellent page with some great tutorials.
I already take data out of Flash with my email form. I can basically use that script to get the variable out. What is the mysql entry to add a row in the database (in PHP code)?
Thanks
Graeme
-
Ok, I still cant get it to work. Can someone give me a pointer as to where I may be going wrong please?
I have a text input box on my page with MailingEmail as the variable name. There is a submit button next to it and the following actionscript is on the button:
Code:
on(release){
var receiver = new LoadVars();
var sender = new LoadVars()
sender.emailadd = MailingEmail;
sender.sendAndLoad("emailadd.php",receiver,"POST");
gotoAndStop(135);
}
I then have a php file on the server called emailadd.php and here is the code from that (I have starred out the username password)
MailingList is the name of the database I have created on my webhost, EmailAddresses is the name of the table, and Email is one of the fields in that table (there are two, one is the identifier - primary key)
Code:
<?php
$user="******";
$password="******";
$database="MailingList";
$connection = mysql_connect('localhost',$user,$password);
mysql_select_db($database)
$emailadd = $_POST['emailadd'];
if($emailadd != ""){
$query="INSERT INTO 'EmailAddresses'('Email') VALUES ($emailadd);
}
mysql_close($connection);
?>
Thanks for any help you can provide.
Graeme
-
OOP is one letter from OOPS
assuming everything else is correct, you are missing closing quote on:
$query="INSERT INTO 'EmailAddresses'('Email') VALUES ($emailadd)";
-
Good spot. I've going to have to start using something like Notepad++ to edit so I spot things like this.
I've corrected that and tried again but its still not adding anything to the database. I don't know how I can test to see what part is falling down.
Flash says the actionscript is ok and the way it reads makes sense to me. Any ideas?
Thanks
Graeme
-
OOP is one letter from OOPS
Well it wold seem that once again I need to read the post more carefully. You are never actually running the query, you are only opening and closing a connection.
Try:
Code:
<?php
$user="******";
$password="******";
$database="MailingList";
$connection = mysql_connect('localhost',$user,$password);
mysql_select_db($database)
$emailadd = $_POST['emailadd'];
if($emailadd != ""){
$query="INSERT INTO 'EmailAddresses'('Email') VALUES ($emailadd);
$result = mysql_query($query);
if($result){
//if the query succeeds, do whatever here, most people echo out some data back into flash such as:
echo 'result=true';
}else{
//if the query failed do this
echo 'result=false';
}
}
mysql_close($connection);
?>
-
Hello,
Yes, I've managed to sort it this afternoon. I spen a while looking at it when I realised I wasn't actually doing the sql entry, just setting the variable. When I put that in, it still didn't work. I had missed a ; on the end of mysql_select_db($database).
There was a few other errors but I have managed to get it to work. I created an HTML form so that I was getting the SQL error returned to me. This helped me work out that it was the php and not the flash giving me the error. Once I got the php working then the Flash worked straight away.
Thanks again for all you help, yourself and everyone involved with this site have been a saviour to me on so many occasions.
All the best,
Graeme
Here's the final code if anyone wishes to use it (if you haven't done anything like this before, ai really do recommend giving it a try):
Flash code is as before,
Code:
<?php
$user="******";
$password="******";
$database="MailingList";
$connection = mysql_connect('localhost',$user,$password);
if (!$connection)
{
die('Could not connect: ' . mysql_error());
};
mysql_select_db($database);
$emailadd = $_POST['emailadd'];
if ($emailadd != ""){
$query = "INSERT INTO EmailAddresses(Email) VALUES ('$emailadd')";
mysql_query($query) or die("Query failed: " . mysql_error());
};
mysql_close($connection);
?>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|