Jump to content

Recommended Posts

HI,

 

I am a beginner at programing and I have to do this project where it is asking me to valid ISBN 10 and 13 using MySQL database to store the information. I checked my php code to validate ISBN 10 and 13 and it works, but when I try to store the data to MySQL it is not working. What  I mean is that when I click ShowISBN link it doesn't show this information:

  1. ISBN Number
  2. ISBN Type
  3. Date Entered using timestamp
  4. Valid or Invalid

This is the codes I have for input page of ISBN page:

<?php
//this is the isset function which allows us to submit back
//to the same form.  If there isn't anything in the ISBN, it will
//show the bottom part of the form
if(isset($_POST["ISBN"])|| empty($_POST['isbn_type']) 
	|| empty($_POST['Valid_Invalid']))
{
	$ISBN = $_POST["ISBN"];;
	$IsbnType = $_POST["isbn_type"];;
	$VaorIn = $_POST["Valid_Invalid"];;

	$ISBN_Arr = str_split($ISBN);
	$not10 =0;
	$notNum=0;
	$notX=0;
	//entering error checking for the code
	//check for 10 first, if clear do additional checking
	if(strlen($ISBN) == 10)
		{//start further error checking	
		//check to make sure first 9 are numeric
		for($i=0;$i<=8;$i++)
			{
			if(!is_numeric($ISBN_Arr[$i]))
				$notNum = 1;
			}//end for loop check
		//check to see if there is a X or a x
		if($ISBN_Arr[9]=='x' || $ISBN_Arr[9]=='X')
			{
				$ISBN_Arr[9] = 10;
			}
			//if not an x, is it at least numeric?
			else if (!is_numeric($ISBN_Arr[9]) )
			{
				$notX=1;
			}
		}//end additional error checking 
		else {
			$not10=1;	
			}//end not 10 check
	//start of error messages if prereqs are not met			
	if($notNum ==1 || $notX ==1 || $not10)
		{
		Print "<h2>Input error</h2><br/>";
		Print "Here is the error(s) discovered:<br/>";
		if($notNum ==1)
			print"Your ISBN contains non-numeric data.<br/>";
		if($notX ==1)
			print"The last digit is not a number or a X.<br/>";
		if($not10 ==1)
			print"ISBN 10 number should contain 10 characters.<br/>";
				
		include"ISBN_not_val_include.html";
		}
	//end error checking
	else{
		$chk_sum_num=10;
		$chk_sum =0;
		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
		$is_valid_ISBN= $chk_sum%11;
		//print"chk_sum: $chk_sum </br> is_valid_ISBN: $is_valid_ISBN</br>";
		if($is_valid_ISBN==0)
			{
			print"<h3>VALID</h3><br/>";
			print"$ISBN is a VALID 10 digit ISBN number.<br/>";
			include"ISBN_val_include.html";
			}
			else{
			print"<h3>INVALID</h3><br/>";
			print"$ISBN is an INVALID 10 number ISBN.<br/>";
			include"ISBN_not_val_include.html";
			}//end is_valid if
		}//end
	}//end is set if
	else{
	include"ISBN_val_include.html";
}//end isset else
?>


</form>
<p><a href="_ShowISBN10and13DBProject.php">Show ISBN 
</a></p> 


</body>
</html>

This is the second part of the code that incorporates php and MySQL:

<?php

if (empty($_POST['ISBN'])|| empty($_POST['isbn_type']) 
	|| empty($_POST['Valid_Invalid']))
	
	echo "<p>You must enter a Valid ISBN 10 to Continue! 
		 Please Click your browser's Back Button to return 
		 to the input page of ISBN 10 with Database.</p>\n";
		 
else {
	$DBConnect = @mysql_connect("xxx.xxx.xx.xxx", "xxxxxxxx", "xxxxxxxx");
	if($DBConnect === false)
		echo"<p>Unable to conenct to the database server.</p>"
		. "<p>Error code " . mysql_errno()
		. ": " . mysql_error() . "</p>";
	else{
	$DBName = "xxxxxxxx";
	if (!@mysql_select_db($DBName, $DBConnect)) {
		$SQLstring = "CREATE DATABASE $DBName";
		$QueryResult = @mysql_query($SQLstring,
		$DBConnect);
		
		if ($QueryResult === FALSE)
		echo "<p>Unable to execute the query.</p>"
		. "<p>Error code " . mysql_errno($DBConnect)
		. ": " . mysql_error($DBConnect) . "</p>";
	else 
		echo "<p>You are the first visitor!</p>";
	}
	mysql_select_db($DBName, $DBConnect);
	
	$TableName = "isbn";
	$SQLstring = "SHOW TABLES LIKE '$TableName'";
	$QueryResult = @mysql_query($SQLstring, $DBConnect);
	
	
	
	if ($QueryResult === FALSE) 
		echo "<p>Unable to create the table.</p>"
		. "<p>Error code " . mysql_errno($DBConnect)
		. ": " . mysql_error($DBConnect) . "</p>";
		
	$ISBNum = stripslashes($_POST['ISBN']);
	$ISBNType = stripslashes($_POST['isbn_type']);
	$VaORIn = stripslashes($_POST['Valid_Invalid']);
	$SQLstring = "INSERT INTO $TableName 
	VALUES(NULL, '$ISBNum', '$ISBNType', 
	'$VaORIn')";
	$QueryResult = @mysql_query($SQLstring, $DBConnect);
		
		if($QueryResult === false)
			echo"<p>Unable to execute the query.</p>"
			. "<p>Error code " . mysql_errno($DBConnect)
			. ": " . mysql_error($DBConnect) . "</p>";
		else
			echo"<h1>Thank you for trying our ISBN 10 program!</h1>";	
	
	
	mysql_close($DBConnect);
	}
}
	
	


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

This is the page where it is not working!

<?php

	$DBConnect = @mysql_connect("xxx.xxx.xx.xxx", "xxxxxxx", "xxxxx");
	if($DBConnect === false)
		echo"<p>Unable to conenct to the database server.</p>"
		. "<p>Error code " . mysql_errno()
		. ": " . mysql_error() . "</p>";
	else{
		$DBName = "xxxxxx";
	if (!@mysql_select_db($DBName, $DBConnect))
		echo"<p>There are no entries in the guest book!</p>";
	else {
	$TableName = "isbn";
	$SQLstring = "SELECT * FROM $TableName";
	$QueryResult = @mysql_query($SQLstring, $DBConnect);
	
	if (mysql_num_rows($QueryResult) == 0) 
		echo"<p>There are no entries in the ISBN 10 Database!</p>";
	else{
		echo"<p>The following ISBN have 
		been recorded:</p>";
		echo"<table width='100%' border='1'>";
		echo"<tr><th>ISBN Number</th><th>ISBN Type</th><th>
			Date Entred</th><th>
			Valid OR Invalid</th></tr>";
		while (($Row = mysql_fetch_assoc($QueryResult)) !==FALSE) {
			echo "<tr><td>{$Row['ISBN']}</td>";
			echo "<tr><td>{$Row['isbn_type']}</td>";
			echo "<tr><td>{$Row['TIMESTAMP']}</td>";
			echo "<td>{$Row['Valid_Invalid']}</td></tr>";
			
			}
			
		}
		mysql_free_result($QueryResult);
	}
	mysql_close($DBConnect);
}
	
		

When I click show ISBN nothing happens and I am not shore why!

 

This is how  I have my table setup in MySQL Manually by clicking table and create table:

 

Columns:

count                 int(11) Al PK

ISBN                   varchar(45)

isbn_type            varchar(45)

TIMESTMP         datetime PK

Valid_Invalid       varchar(45)  

 

 

Can someone please tell me why when I click Show ISBN in the input page the first code pasted  I get nothing! How do  I fix the issue because my validation works, but it's not storing it or showing up when  click Show ISBN!

 

Any help will be appreciate it!

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.