blue-genie Posted August 13, 2009 Share Posted August 13, 2009 Here's my predicament. I have a flash form that pull data via php and displays some data. The user then selects various items and it populates a datagrid component (in flash), now I need to be able to save that selection back to the database. I was told PHP can't accept an array from flash. So here's my question. I can format the results any which way , i.e. string/array etc to send to the PHP.I need to know on the php side. 1. what format is best for large amount of data from a datagrid. 2. how to take that data and do an insert into in using a loop or whatever. total noob so keep it to 1st grader terminology if you can assist please. thanks :-) Quote Link to comment https://forums.phpfreaks.com/topic/170127-solved-need-help-with-a-loop-of-sorts-to-do-an-insert-into-mysql/ Share on other sites More sharing options...
will35010 Posted August 13, 2009 Share Posted August 13, 2009 I don't know anything about flash. How does flash send the data to php. Can it use POST? If so, you could receive the variables using $_POST['variablename']. Quote Link to comment https://forums.phpfreaks.com/topic/170127-solved-need-help-with-a-loop-of-sorts-to-do-an-insert-into-mysql/#findComment-897439 Share on other sites More sharing options...
blue-genie Posted August 13, 2009 Author Share Posted August 13, 2009 Hi Will. Yes the flash sends the data through via a post. i can get the variable back to php, i'm thinking in this format i1=Symbol=Oyster,Odds=1,Prize=test1&i2=Symbol=Sardine,Odds=2,Prize=test2&i3=Symbol=Lobster,Odds=4,Prize=test4&i4=Symbol=skeleton,Odds=5,Prize=test5 but what I need help with is that php then takes that and does an INSERT into db with that data. So i'm assuming it needs to be converted to an array or somethign that PHP can loop through. I don' t know how to do that. PHP will get it as a string. Quote Link to comment https://forums.phpfreaks.com/topic/170127-solved-need-help-with-a-loop-of-sorts-to-do-an-insert-into-mysql/#findComment-897539 Share on other sites More sharing options...
mikesta707 Posted August 13, 2009 Share Posted August 13, 2009 here is a tutorial on php and post variables http://www.tizag.com/phpT/postget.php Quote Link to comment https://forums.phpfreaks.com/topic/170127-solved-need-help-with-a-loop-of-sorts-to-do-an-insert-into-mysql/#findComment-897553 Share on other sites More sharing options...
blue-genie Posted August 13, 2009 Author Share Posted August 13, 2009 mikesta707, thanks for the pointer but I can get the variables from flash into php. I'm struggling with spliting the string I Post to PHP for PHP to insert it. I've been fiddling a bit, and testing in my browser with the following URL. http://localhost/fishing/fishing/savePrizes.php?i1=Symbol=Oyster,Odds=1,Prize=test1&i2=Symbol=Sardine,Odds=2,Prize=test2&i3=Symbol=Lobster,Odds=4,Prize=test4&i4=Symbol=skeleton,Odds=5,Prize=test5 my resulting echos: Array ( [i1] => Array ( [symbol] => Oyster [Odds] => 1 [Prize] => test1 ) [i2] => Array ( [symbol] => Sardine [Odds] => 2 [Prize] => test2 ) [i3] => Array ( [symbol] => Lobster [Odds] => 4 [Prize] => test4 ) [i4] => Array ( [symbol] => skeleton [Odds] => 5 [Prize] => test5 ) ) Array size with count: 4inside for loopinside not empty should insert Oysterinside for loopinside not empty should insert Sardineinside for loopinside not empty should insert Lobster so it's getting the values but the insert is not happening, and it's not giving me any errors either. here's my PHP thus far: <?php session_start(); include 'config.php'; include 'opendb.php'; $gameID = $_REQUEST['gameID']; $data = array(); foreach($_GET as $key => $value){ $raw[$key] = explode(',' ,$_GET[$key]); foreach($raw[$key] as $value){ $info = explode('=', $value); $data[$key][$info['0']] = $info['1']; } } print_r($data); if ( is_array( $data ) ){ // Find the number of keys in the array // echo "Array size with count: ".count($data); $n = count($data); for ( $i = 1; $i < $n; $i++ ){ echo "inside for loop"; $key = 'i'.$i; // Read the various keys, you should know what to expect! // if( !empty($data[$key]['Symbol'])){ echo "inside not empty should insert ".$data[$key]['Symbol']; $sql = 'INSERT INTO gamePrizes(name, prize, odds, gameID) VALUES("'.$data[$key]['Symbol'].'","'.$data[$key]['Odds'].'", "'.$data[$key]['Prize'].'",, "'.$gameID.'",)'; }else{ $errorMsg = "Error inserting into db ".sql.error(); echo $errorMsg; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170127-solved-need-help-with-a-loop-of-sorts-to-do-an-insert-into-mysql/#findComment-897561 Share on other sites More sharing options...
mikesta707 Posted August 13, 2009 Share Posted August 13, 2009 you never do a query... You just build a query statement, but never execute it. echo the $sql variable and see if it is what it should be, than execute the query Quote Link to comment https://forums.phpfreaks.com/topic/170127-solved-need-help-with-a-loop-of-sorts-to-do-an-insert-into-mysql/#findComment-897564 Share on other sites More sharing options...
blue-genie Posted August 13, 2009 Author Share Posted August 13, 2009 hey after pasting the code I saw the error of my ways, apart from what you said, also had a syntax error which I only managed to catch with some proper error checking. thanks, it's working now :-) Quote Link to comment https://forums.phpfreaks.com/topic/170127-solved-need-help-with-a-loop-of-sorts-to-do-an-insert-into-mysql/#findComment-897573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.