PHP Challenge 9 - ISBN Checker

phplogo.jpg

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 designed to test your ability to create a form and process the user input.

isbn.jpg

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.

To enrol in the course click here.