mtvaran Posted November 4, 2010 Share Posted November 4, 2010 could anyone please help me with the code which is i have already displayed data from two table as a drop-down list and a multi select list but now i need to select one from drop-down list and one or more from multi select list the insert into another database table. here is the coding. it shows no error message( blank page after submit) and nothing inserted on the take able <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } error_reporting(E_ALL); ini_set('display_errors', 1); mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]" multiple="multiple" size="10">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">' . $row['CourseName'] . '</option>'; } echo '</select>'; // ---------------- $result = mysql_query("SELECT * FROM student") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name="sid">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['StudentID'] . '">' . $row['StudentName'] . '</option>'; } echo '</select>'; mysql_close($con); ?> <form id="form1" name="form1" method="post" action="update_result.php"> <label> <input type="submit" name="Submit" value="Submit" /> </label> </form> </body> </html> update_result.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); if (!empty($_POST['sid']) && !empty($_POST['cid'])) { foreach ($_POST['cid'] as $key => $course) { $courses .= $course."-"; } $courses = rtrim($courses,"-"); $student = $_POST['sid']; $sql = "INSERT INTO test (StudentID, CourseID) VALUES('".mysql_real_escape_string($student)."','".mysql_real_escape_string($courses)."')"; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_affected_rows() > 0) { echo mysql_affected_rows() . ' rows added.'; } } mysql_close($con); ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
mtvaran Posted November 5, 2010 Author Share Posted November 5, 2010 can anyone check this code for me plsss? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 5, 2010 Share Posted November 5, 2010 i'm not sure by what you mean "check this code" I would move these lines to the top of each file: error_reporting(E_ALL); ini_set('display_errors', 1) if you still aren't seeing errors, i would check php.ini to turn on error_reporting there, then restart apache. Quote Link to comment Share on other sites More sharing options...
mtvaran Posted November 5, 2010 Author Share Posted November 5, 2010 still same dear, no error message and no data inserted. wat can i do with this? pls help me with code. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 5, 2010 Share Posted November 5, 2010 so you turned on error_reporting in php.ini and restarted apache? then, let's check to make sure error_reporting is on. in a new file called phpinfo.php, place this code, then open the page in your browser: <?php phpinfo(); ?> what do you see when you execute that page via browser? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 5, 2010 Share Posted November 5, 2010 ah, the problem probably is that you open your form tag AFTER you echo the select controls. when you load the form page, VIEW SOURCE and look at the HTML. you may find that you have your select form controls before you open the form <form> Quote Link to comment Share on other sites More sharing options...
mtvaran Posted November 5, 2010 Author Share Posted November 5, 2010 wow... u were correct... excellent now data is inserted. but it says small error ..... foreach ($_POST['cid'] as $key => $course) { $courses .= $course."-"; //............ this line error } can you find out it for me plsss Quote Link to comment Share on other sites More sharing options...
mtvaran Posted November 5, 2010 Author Share Posted November 5, 2010 its ok dear. i have done that. thank you very much for your help 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.