PDA

View Full Version : I hope some of you guru's out there can help me with this...



jasonhardwick
August 28th, 2006, 11:05 AM
I hope some of you guru's out there can help me with this... Let me start by saying "I have no idea what I am doing" now my question I need to create a form in flash and send the data to mysql database...I can get the flash form set up and link it to a php page without any problems, my problem is the php page I am very very new to php and am starting to grasp the basics. but all of the tutorials i have found are above my level. can someone help me...or show me how to write a php page that can pass my flash form data to mysql.

jason

bwh2
August 28th, 2006, 11:18 AM
/* this is the text you get from flash. make sure you use method POST in flash */
$myText = $_POST['theText'];

/* connect to DB */
$link = mysql_connect( 'localhost', 'db_username', 'db_password' ) or die( mysql_error() );
mysql_select_db( 'db_name', $link ) or die( mysql_error() );


/* run the INSERT query */
$result = mysql_query( "INSERT INTO tbl_name (text_column_name) VALUES ( '$myText' )" ) or die( mysql_error() );

jasonhardwick
August 28th, 2006, 11:51 AM
Ok... like i said I have no idea what I am doing here...I think i get where this is going... so I have many different text fields so di i do something like this...

<?php

$myText = $_POST['theText'];
$myText1 = $_POST['theText1'];
$myText2 = $_POST['theText2'];
$myText 3= $_POST['theText3'];

$link = mysql_connect( 'localhost', 'db_username', 'db_password' ) or die( mysql_error() );
mysql_select_db( 'db_name', $link ) or die( mysql_error() );


$result = mysql_query( "INSERT INTO tbl_name (text_column_name) VALUES ( '$myText2' )" ) or die( mysql_error() );

$result = mysql_query( "INSERT INTO tbl_name (text_column_name1) VALUES ( '$myText1' )" ) or die( mysql_error() );

$result = mysql_query( "INSERT INTO tbl_name (text_column_name2) VALUES ( '$myText2' )" ) or die( mysql_error() );

$result = mysql_query( "INSERT INTO tbl_name (text_column_name3) VALUES ( '$myText3' )" ) or die( mysql_error() );

<?php ?>



???

bwh2
August 28th, 2006, 01:22 PM
close, but you have a few errors that need to be fixed:


<?php

$myText = $_POST['theText'];
$myText1 = $_POST['theText1'];
$myText2 = $_POST['theText2'];
$myText3 = $_POST['theText3'];

/*
1. localhost is your host name, you can probably keep this
2. db_username is the username for your db. you must change this.
3. db_password is the username's password for the db. you must change this.
4. db_name is the name of your db. you must change this.
*/
$link = mysql_connect( 'localhost', 'db_username', 'db_password' ) or die( mysql_error() );
mysql_select_db( 'db_name', $link ) or die( mysql_error() );

/*
1. tbl_name is the name for your table. you must change this
2. text_column_name (all of them) represent the different columns. you must change these.

i prettied the query up a little as well
*/
$result = mysql_query( "
INSERT INTO tbl_name (
text_column_name,
text_column_name_2,
text_column_name_3,
text_column_name_4 )
VALUES (
'$myText',
'$myText2',
'$myText3',
'$myText4')" )
or die( mysql_error() );

/* end php like this... */
?>
as you can see, there are some things you need to change. if you have not yet setup a mysql db, you will need to do that before any of this will work.

also, if you're going to use php code, put it in the
code goes here tags.