Paul_Blackpool Posted October 7, 2014 Share Posted October 7, 2014 Just got a little stuck. Iv'e created a form but I cant get the items from my multi select items list into the database. Everything else works fine could just do with a little help. PHP <?php # script 8.5 - register.php # 2 $page_title = 'Register'; include ('../Includes/header.html'); // Check if the form has been submitted: if (isset($_POST['submitted'])) { require_once ('../conn/mysqli_connect.php'); // connect to the database. $errors = array(); // Initialise error array // Check for a first name: if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = mysqli_real_escape_string($dbc,trim($_POST['first_name'])); } // Check for last name: if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = mysqli_real_escape_string($dbc,trim($_POST['last_name'])); } // Check for an email address: if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = mysqli_real_escape_string($dbc,trim($_POST['email'])); } // Check for a password and match against the confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match your confirm password.'; } else { $p = mysqli_real_escape_string($dbc,trim($_POST['pass1'])); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // If everythings OK: // Register the user into the database. // Make the query: $q = "INSERT INTO users (first_name, last_name, email, pass, items_list, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )"; $r = mysqli_query ($dbc, $q); // Run the query: if ($r) { // if it ran OK. // Print the message echo '<h1>Thank You</h1> <p>You are now registered. In chapter 11 you will actually be able to login!</p><p><br /></p>'; } else { // If it did not run OK // message echo '<h1>System Error</h1> <p class ="error">You could not be registered due to a system error. Please try in a little while. We appologise for any inconvenience,</p>'; // Debug message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // end of the if ($r) IF mysqli_close($dbc); // Close the database connection. // include the footer and quit the script. include ('../Includes/3.4_3.4_footer.html'); exit(); } else { // Report the errors. echo '<h1>Error!</h1> <p class="error">The following error(s) occured:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF myli_close($dbc); // Close the database. } // End of mail submitt. ?> HTML Form <style type="text/css"> #apDiv1 { position:absolute; width:200px; height:115px; z-index:1; left: 107px; top: 229px; } </style> <h1>Register</h1> <form action="register_2.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlengh="20" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last name: <input type="text" name="last_name" size="15" maxlengh="24" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlengh="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Password: <input type="password" name="pass1" size="10" maxlengh="20" /></p> <div id="apDiv1"></div> <p>Confirm Password: <input type="password" name="pass2" size="10" maxlengh="20" /></p> <P> List: <select name="items_list[]" multiple size="1" > <option>Item 1</option> <option>Item 2</option> <option>Item 3</option> </select> <p><input type="submit" name="submit" value="register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('../Includes/3.4_3.4_footer.html'); ?> Link to comment Share on other sites More sharing options...
Larry Posted October 14, 2014 Share Posted October 14, 2014 Are the items list items being stored as a string in a single column? Link to comment Share on other sites More sharing options...
Recommended Posts