theo Posted April 9, 2015 Share Posted April 9, 2015 having problem with my form: created checkbox using array; then I want to save the value of the array to the database Link to comment Share on other sites More sharing options...
theo Posted April 9, 2015 Author Share Posted April 9, 2015 <?php # submit_docs.php # insert submitted documents of ESA $page_title = 'Submit ESA Documents'; include ('includes/header.html'); //Page header: echo '<h1>Submit ESA Documents</h1>'; require ('includes/mysqli_connect.php'); //connect to db //check form: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors[] = array(); if (empty($_POST['municipality'])) { $errors[] = 'You forgot to select municipality'; } else { $muni = mysqli_real_escape_string($dbc, trim($_POST['municipality'])); } if (empty($_POST['remarks'])) { $errors[] = 'You forgot to enter remarks'; } else { $rema = mysqli_real_escape_string($dbc, trim($_POST['remarks'])); } if (isset($_POST['submitted'])) { $submitted = implode(',', $_POST['submitted']); $subm = mysqli_real_escape_string($dbc, trim($submitted)); } //if no errors: if (empty($errors)) { //register data of submitted docs //make query: $q = "INSERT INTO subdocs (lgu_id, sub_docs, remarks, registration_date) VALUES ('$id', '$subm', '$rema', NOW())"; $r = @mysqli_query($dbc, $q); //run the query if ($r) { //if it ran ok //print message: echo '<h1>Thank You for submitting ESA Documents</h1>'; } else { //public message: echo '<h1>System Error</h1>'; //debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query:' . $q . '</p>'; } //end of if mysqli_close($dbc); //close the database include('includes/footer.html'); exit(); } else { //report errors echo '<h1>ERROR</h1> <p class="error">The following errors occurred'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '<p>Please Try Again</p>'; } mysqli_close($dbc); } //make the query: $q = "SELECT lgu_id, municipality FROM lgu ORDER BY municipality ASC"; $r = @mysqli_query ($dbc, $q); //run the query if ($r) { //if OK //fetch and print record echo '<form action="submit_docs.php" method="post">'; echo '<p><b>Municipality:</b> <select name="municipality">'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo "<option value=\"$row[municipality]\">$row[municipality]</option>\n"; } echo '</select></p>'; echo '<p>Submitted Documents:</p> <p><input type="checkbox" name="submitted[]" value="Project Proposal">Project Proposal <input type="checkbox" name="submitted[]" value="MOA">Memorandum Of Agreement <input type="checkbox" name="submitted[]" value="Certificate of Eligibility">Certificate of Eligibility <input type="checkbox" name="submitted[]" value="Masterlist">Masterlist <input type="checkbox" name="submitted[]" value="Rehabilitaion Plan">Rehabilitation Plan </p>'; echo '<p>Remarks:</p> <p><textarea rows="12" cols="50" name="remarks"></textarea></p> <p><input type="submit" name="submit" value="register" /></p> <input type="hidden" name="lgu_id" value="' . $row['lgu_id'] . '"'; echo '</form>'; } ?> the error is array Link to comment Share on other sites More sharing options...
Larry Posted April 10, 2015 Share Posted April 10, 2015 I don't know what you mean by "the error is array". Link to comment Share on other sites More sharing options...
theo Posted April 10, 2015 Author Share Posted April 10, 2015 when I save the data this is the only error message: the following errors occurred - Array Link to comment Share on other sites More sharing options...
Larry Posted April 11, 2015 Share Posted April 11, 2015 You have a problem here: $errors[] = array() Change that to: $errors = array() Link to comment Share on other sites More sharing options...
theo Posted April 12, 2015 Author Share Posted April 12, 2015 sir thank you. Link to comment Share on other sites More sharing options...
Recommended Posts