;

PDA

Click to See Complete Forum and Search --> : PHP Survay


william_tropico
08-29-2003, 05:37 PM
I am trying to make a flash movie which will consit of Radiobuttons,
textboxes(inputfields) and Check boxes. I would like to be able to have a email sent to me with all the details. If this cannot be done then have the survay results uploaded to mySQL. Does anyone know any tutorials on how this can be done.

Thanks in advance, William :)

Musicman
08-29-2003, 05:50 PM
Hi,

both sending to an email or to a mysql are pretty standard... May I suggest to use mysql - it is probably better at adding up values than your email program.
There is one thing to watch out for, however: textboxes just send their contents without extra help, while (at least the macromedia) checkboxes and radiobuttons require that you get their values and store them into some variables before sending

Musicman

william_tropico
08-29-2003, 05:57 PM
Ok if i would use sql, what would i put in the php file, or to get the flash file to use the php file.

Originally posted by william_tropico
Does anyone know any tutorials on how this can be done.[/B]

I dont really know on how to go about this, so i really need a tutorial.

Thanks again, William:)

the sherrif
08-29-2003, 06:34 PM
oh look, ive found a tutorial (http://www.phpbuilder.com/columns/hill20011214.php3)

Musicman
08-29-2003, 06:41 PM
Hi,

suppose your survey sends just two radiobox choices c1, c2 with possible values a, b, c
You would need a database table with those fields
create table summary (
name varchar(3), -- would be c1 or c2 here
a int default 0,
b int default 0,
c int default 0
);
The php code would be
-- db.php --
<?
@mysql_connect("localhost", "somename", "somepass") or die("connect fail, error " . mysql_error());
@mysql_select_db("mydatabase") or die("cannot select database, error " . mysql_error());
?>
where all the names have to match your database
--- main script, e.g. addresult.php ---
<?
include "db.php";
$c1 = $_POST["c1"];
$c2 = $_POST["c2"];
if(!blank($c1))
mysql_query("UPDATE summary SET $c1 = $c1 + 1 where name = 'c1'");
if(!blank($c2))
mysql_query("UPDATE summary SET $c2 = $c2 + 1 where name = 'c2'");
print "status=ok";
?>

Now, suppose your survey includes the submitter's email AND you want to keep individual results, you would need another table
create table survey (
email varchar(50),
c1 varchar(2),
c2 varchar(2),
unique (email)
);
and could add this line to your php
@mysql_query("INSERT INTO survey values ('$email', '$c1', '$c2')") or die("status=fail");

Note: the "unique" part along with the die() would prevent duplicate submission [if you could check the validity of the email :) ]

Musicman