PHP Challenge 9 - ISBN Checker

Each published book is given a unique identifier called an International Standard Book Number or ISBN for short.

The ISBN is 13 characters long is assigned from 1 January 2007 and 10 characters long if assigned before that date.

This task has been desiged to test your ability to create a form and process the user input.

ISBN

Image courtesy of user Sakurambo at Wikipedia. Used under Creative Commons license with no amendments to the original image

TASK

Design a HTML form to allow a user to input a 10 digit ISBN.

Send this data to a processing script and then check if it is a valid ISBN number.

Output a valid or invalid message to the user.

Sample Valid ISBN: 1573980137

How to check if an ISBN is valid

  1. Multiply each digit of the ISBN by a weighted value as follows:
    The first digit is multiplied by 1, the second digit by 2, the third digit by 3 etc
  2. Find the total of these multiplied digits
  3. If the total is divisible by 11 with no remainder then the ISBN is valid

Example

Consider the ISBN 0072296542

0 x 1 = 0
0 x 2 = 0
7 x 3 = 21
2 x 4 = 8
2 x 5 = 10
9 x 6 = 54
6 x 7 = 42
5 x 8 = 40
4 x 9 = 36
2 x 10 = 20

0 + 0 + 21 + 8 + 10 + 54 + 42 + 40 + 36 + 20 = 231

231 / 11 = 21 (i.e. no remainder)

Therefore the ISBN is valid.

Would you like the solution to this challenge?

The full video solution together with downloadable code is available in the PHP for Beginners course.

This course is taught by Patrick Morrow, a national award-winning teacher, who is very active in the course and who provides full support.

For more information click here.

Comments

Your email address will not be published.

User Avatar

Interesting coding challenge. Do you have any more?

by Kevin, 27-Feb-2016

User Avatar

Yes. Check the rest of the website for other challenges (option available via the tags) or search for the term challenge. For more challenges enrol in the PHP for Beginners course (link via menu or top right of each page)

by Patrick Morrow, 27-Feb-2016

PHP for Beginners

Enrol in the full course here

PHP, MySQL and PDO

Coming soon, a full course on using PHP, MySQL and PDO. Be notified as soon as the course goes live.