Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'implode'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. Hello, I've googled this thing to death, but still having problems. I'm trying to insert multiple rows into Mysql with one INSERT INTO query (line 39) using an array and the implode(). The user can select multiple qualifications for one employee. I have the multiple select listing all the qualifications from the quals table on the db. Another select table is listing all the employee names from the employee table. Each employee can have multiple qualifications. I would like the qual_id, employee_id, issue_date, and expiration_date inserted into emp-quals table. The following error keeps appearing: Array ( [qual_id] => 3 [employee_id] => 13 [issue_date] => [expiration_date] => [Submit] => Submit [/] => ) An error occurred in script 'C:\wamp\www\****\set_qual.php' on line 36: Uninitialized string offset: 0 And Column count doesn't match value count at row 1 Query: INSERT INTO emp_quals(qual_id, employee_id, issue_date, expiration_date) VALUES ('("3", 3, 3, 3")', '("1", 1, 1, 1")', '("", , , ")', '("", , , ")', '("S", S, S, S")', '("", , , ")') It seems to be close to working, but I'm not sure how to tweak it. Here is the entire code: <?php #Ny Kvalifikasjon for Ansatte. require('includes/config.inc.php'); $page_title = 'Ny Kvalifikasjon for ansatte!'; include ('includes/header.html'); // Create the submission conditional and initialize the $errors array. if ($_SERVER['REQUEST_METHOD'] == 'POST'){ // Add the MySQL connection include(MYSQL); $errors = array(); $qual_id = mysqli_real_escape_string($dbc, trim($_POST['qual_id'])); $employee_id = mysqli_real_escape_string($dbc, trim($_POST['employee_id'])); $issue_date = mysqli_real_escape_string($dbc, trim($_POST['issue_date'])); $expiration_date = mysqli_real_escape_string($dbc, trim($_POST['expiration_date'])); if (empty($_POST['qual_id'])) { $errors[] = 'Kvalifikasjonen mangler!'; } else { $qual_id = mysqli_real_escape_string($dbc, trim($_POST['qual_id'])); } if (empty($_POST['employee_id'])) { $errors[] = 'Ansatte mangler!'; } else { $employee_id = mysqli_real_escape_string($dbc, trim($_POST['employee_id'])); } if (empty($errors)) { print_r($_POST); //Added print_r tip from margaux at L.U.forum post: http://www.larryullman.com/forums/index.php?/topic/2131-103-edit-user-script-modification/ $values = array(); foreach($_POST as $row ) { $values[] = '("'.mysql_real_escape_string($row['qual_id']).'", '.$row['employee_id'].', '.$row['issue_date'].', '.$row['expiration_date'].'")'; } $q = "INSERT INTO emp_quals(qual_id, employee_id, issue_date, expiration_date)"; $q .= " VALUES ('".implode("', '", $values)."')"; $r = @mysqli_query ($dbc, $q); if ($r) { //See pg 276 echo '<h1>Success!</h1> <p>En ny kvalifikasjon er lagret.</p> <p><a href="qualification.php">Gå til kvalifikasjons oversikt.</a><br /></p>'; } else { echo '<h1>System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); include ('includes/footer.html'); exit (); }else { // Report the errors echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error messages echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. }// End of main submit conditional. //DISPLAY THE FORM ?> <h1>Ny Kvalifikasjon for Ansatte</h1> <form action="set_qual.php" method="post"> <fieldset> <legend>Ny Kvalifikasjon for Ansatte</legend> <label>Qualification:</label><select multiple name="qual_id">'; <?php include(MYSQL); $q = "SELECT qual_id, qual_name FROM quals ORDER BY qual_id ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<option value="'.$menu_row[0].'">'.$menu_row[0].' - ' . $menu_row[1] . '</option>\n'; } } mysqli_free_result($r); echo '</select><br /><small>Bruk Ctrl knappen for å velge flere.</small><br />'; ?> <label>Employee Name:</label><select name="employee_id">'; <?php $q = "SELECT employee_id, ansattnumber, last_name, first_name FROM employee ORDER BY ansattnumber ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<option value="'.$menu_row[0].'">' . $menu_row[1] . ' - ' .$menu_row[2] .', '. $menu_row[3]. '</option>\n'; } } mysqli_free_result($r); echo '</select><br />'; ?> <br /> <label>Start dato yyyy-mm-dd:</label><input type="text" name="issue_date" size="15" maxlength="15" value="<?php if(isset($_POST['issue_date'])) echo $_POST['issue_date']; ?>" /><br /><br /> <label>Utløpsdato yyyy-mm-dd:</label><input type="text" name="expiration_date" size="15" maxlength="15" value="<?php if(isset($_POST['expiration_date'])) echo $_POST['expiration_date']; ?>" /><br /><br /> <p><input type="submit" name="Submit" value="Submit" class="button" /></p> <input type="hidden" name= /> </fieldset> </form> <?php include ('includes/footer.html'); ?> Any assistance would be appreciated.
×
×
  • Create New...