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 Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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()); Quote Link to comment 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 Quote Link to comment 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.