simplyrichard Posted October 31, 2008 Share Posted October 31, 2008 I have the following code: foreach( $_SESSION['jobs'] as $job => $value){ $result = mysql_query("SELECT * FROM culvercareers.positions WHERE position_id='$value'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $job_title = $row['position_name']; echo "$job_title<br>"; echo "<textarea cols='45' rows='5' name='job_xp[]'></textarea>"; [b]echo "<input type='hidden' name='job_code' value'$value'>";[/b] echo "<p>"; } What I am trying to ask is ... now that I hae job_xp[] in an array... how do I get the job_code included into the same array so that when I do this: $_SESSION['job_xp_info'] = $_POST['job_xp']; foreach( $_SESSION['job_xp_info'] as $job => $value){ mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, [b]job_code[/b]) VALUES ('$app_id','$userid','$value','[b]$job_code'[/b])") or die (mysql_error()); I get the job_xp and the job_code in the array? Richard Link to comment https://forums.phpfreaks.com/topic/130908-solved-array-containing-two-fields/ Share on other sites More sharing options...
wildteen88 Posted October 31, 2008 Share Posted October 31, 2008 Change foreach( $_SESSION['jobs'] as $job => $value){ $result = mysql_query("SELECT * FROM culvercareers.positions WHERE position_id='$value'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $job_title = $row['position_name']; echo "$job_title<br>"; echo "<textarea cols='45' rows='5' name='job_xp'></textarea>"; [b]echo "<input type='hidden' name='job_code' value'$value'>";[/b] echo "<p>"; } to $i = 0; foreach( $_SESSION['jobs'] as $job => $value) { $result = mysql_query("SELECT * FROM culvercareers.positions WHERE position_id='$value'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $job_title = $row['position_name']; echo "$job_title<br>"; echo "<textarea cols='45' rows='5' name='job[$i][xp]'></textarea>"; echo "<input type='hidden' name='job[$i][code]' value'$value'>"; echo "<p>"; $i++; } Now change $_SESSION['job_xp_info'] = $_POST['job_xp']; foreach( $_SESSION['job_xp_info'] as $job => $value){ mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, [b]job_code[/b]) VALUES ('$app_id','$userid','$value','[b]$job_code'[/b])") or die (mysql_error()); to: $_SESSION['job_info'] = $_POST['job']; foreach( $_SESSION['job_info'] as $job) { mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, job_code) VALUES ('$app_id','$userid','{$job['xp']}','{$job['code']}'") or die (mysql_error()); } [/code] Link to comment https://forums.phpfreaks.com/topic/130908-solved-array-containing-two-fields/#findComment-679535 Share on other sites More sharing options...
simplyrichard Posted October 31, 2008 Author Share Posted October 31, 2008 This makes gives a mysql error foreach( $_SESSION['job_info'] as $job) { mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, job_code) VALUES ('$app_id','$userid','{$job['xp']}','{$job['code']}'") or die (mysql_error()); } You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Any suggestions? Richard Link to comment https://forums.phpfreaks.com/topic/130908-solved-array-containing-two-fields/#findComment-679595 Share on other sites More sharing options...
Barand Posted October 31, 2008 Share Posted October 31, 2008 missing ")" mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, job_code) VALUES ('$app_id','$userid','{$job['xp']}','{$job['code']}')") or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/130908-solved-array-containing-two-fields/#findComment-679612 Share on other sites More sharing options...
simplyrichard Posted November 4, 2008 Author Share Posted November 4, 2008 Thanks so much! All your guys help as been a life saver! Richard Link to comment https://forums.phpfreaks.com/topic/130908-solved-array-containing-two-fields/#findComment-682076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.