Jump to content

Recommended Posts

This is the project I need to finish. I am fairly new to php and this project has got me confused. Any help would be greatly appreciated

The project ask for to validate ISBN 10 Number. There would be 10 digits with 1-9 being Numbers, but Number 10 is an x.

This is What I have so far:

This is the input page or html page:

<form method="POST" action="Process10ISBN.php">

<p>Enter ISBN 10: <input type="text" name="isbn10"
/></p>

<input type="submit" name="Submit" value="Submit" />

</form>


This is what I have so far for the Procssing page to validate ISBN 10:

<?php
if (empty($_POST['isbn10']))
	
	echo "<p>Please Fill in the input fields. 
	     Please use the back button to re-enter the data!</p>\n";		 
else {
	$ISBN10 = addslashes($_POST['isbn10']);
	
		echo "<p>Thank you for your input!</p>\n";	
 	} 	
//this are the code that should go in the project

$chk_sum_num=10;

for($i=0;$i<=9;$i++
	{
	$chk_sum+=$ISBN_Arr[$i] * $chk_sum_num;
	print"$ISBN_Arr[$i] | $chk_sum_num<br/>";
	
	$chk_sum_num--;
	}//end for loop
	
//this goes at top, then the loop goes inside it

If $ISBNARR[9]!=is numeric{{!= 'X'!!='x'
	print"Not ISBN 10 Number<br/>";
	
	Else If $ISBNARR[9]=='x' or "X" $ISBNARR[9] = 10

?><!--End PHP Script-->

// I don't know how to set up the processing page. All I know is that this code has to be included in the processing page: I know my processing code is set up wrong. I couldn't figure out how I would put the codes in and what else I needed to add!

//this are the code that should go in the project

$chk_sum_num=10;

for($i=0;$i<=9;$i++
	{
	$chk_sum+=$ISBN_Arr[$i] * $chk_sum_num;
	print"$ISBN_Arr[$i] | $chk_sum_num<br/>";
	
	$chk_sum_num--;
	}//end for loop
	
//this goes at top, then the loop goes inside it

If $ISBNARR[9]!=is numeric{{!= 'X'!!='x'
	print"Not ISBN 10 Number<br/>";
	
	Else If $ISBNARR[9]=='x' or "X" $ISBNARR[9] = 10

?><!--End PHP Script-->

Can Someone show me how I am suppose to do the processing page for my ISBN 10 validation!
Thank You!

You have 3 vars defined that don't connect to anything

$ISBN10

$ISBN_Arr

$ISBNARR

 

Perhaps that is your problem, or at least the beginning.

 

If you turned on php error checking/display you would probably see some error messages that would help you clean up your code.

 

 

 error_reporting(E_ALL | E_STRICT | E_NOTICE);
 ini_set('display_errors', '1');

 

Put this at the top of your script. Be sure to turn off display_errors once you put this into production.

Hi,

 

I assume the “code” you've shown us is just pseudo-code? Because obviously this isn't valid PHP syntax.

 

I think you're approaching this the wrong way. Instead of writing down a bunch of code and then stop and wonder how on earth you need to assemble this, you should first get clear about what you want to do. Don't write a single line of PHP until you have a very good idea of how your program should look like.

 

It also helps to leave out unimportant stuff at first. Do the error checking later. It's more important to get the ISBN check itself right.

 

My suggestion would be to forget about the form, the error checking and whatnot and just write down the check. A function is perfect for this:

<?php

function isValidISBN10($isbn)
{
    $sum = 0;
    for ($i = 0; $i < 10; $i++)
    {
        if ($isbn[$i] === 'X')
        {
            $value = 10;
        }
        else
        {
            $value = $isbn[$i];
        }

        $sum += ($i + 1) * $value;
    }

    // now the final check
}

When you got this running, then you add all the other special functionalities.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.