This is probably really dirty and messy code, so any input on that would be helpful as well, but my main issue is that I can’t get the “ISBN” input to process if the string is the correct number of characters (10 or 13). I’m not sure where it is going wrong. It’s on line 64.
Please help! Thank you.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Link Generator</title>
</head>
<body>
<?php
function showForm() {
if (empty($_POST['title'])) {
$title = "Book Title";
} else {
$title = $_POST['title'];
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
Search by ISBN<br />
<input type="text" maxlength="13" name="ISBN" size="30" value="ISBN" onblur="if(this.value == '') { this.value='ISBN'}" onfocus="if (this.value == 'ISBN') {this.value=''}" /><br />
<br />OR<br /><br />
Search by Title <strong>and</strong> Author<br />
<input type="text" maxlength="13" name="title" size="30" value="<?php echo $title; ?>" onblur="if(this.value == '') { this.value='Book Title'}" onfocus="if (this.value == 'Book Title') {this.value=''}" /><br />
<input type="text" maxlength="13" name="aname" size="30" value="Author Name" onblur="if(this.value == '') { this.value='Author Name'}" onfocus="if (this.value == 'Author Name') {this.value=''}" /><br />
<br /><input type="submit" name="submit" value="Generate Link" />
</form>
<?php
}
function generateLink_ISBN() {
echo "Your link has been generated:<br />";
echo "http://xxx.com/uhtbin/cgisirsi.exe/x/0/0/5?search_type=search&searchdata1=" . $_POST['ISBN'] . "&library=ALL&sort_by=PBYR";
}
function generateLink_title() {
echo "Your link has been generated:<br />";
echo "http://xxx.com/uhtbin/cgisirsi.exe/x/0/0/5?search_type=search&searchdata1=" . $_POST['title'] . "+" . $_POST['aname'] . "&library=ALL&sort_by=PBYR";
}
if(isset($_POST['submit'])) {
if (isset($_POST['ISBN']) && isset($_POST['title']) && isset($_POST['aname']) && ($_POST['ISBN'] == 'ISBN') && ($_POST['aname'] == 'Author Name') && ($_POST['title'] == 'Book Title')) {
echo "<h1>You did not input any information</h1>";
showForm();
} elseif (isset($_POST['ISBN']) && ($_POST['ISBN'] != 'ISBN')) {
if (isset($_POST['ISBN']) && ($_POST['ISBN'] != 'ISBN') && (!is_numeric ($_POST['ISBN']))) {
echo "<h1>The ISBN you entered did not contain all numerics</h1>";
showForm();
} elseif (isset($_POST['ISBN']) && ($_POST['ISBN'] != 'ISBN') && ((mb_strlen($_POST['ISBN'], 'utf-8') != 13) | (mb_strlen($_POST['ISBN'], 'utf-8') != 10))) {
echo "<h1>The ISBN you entered was too long or too short. ISBN's are 10 or 13 numbers in length.</h1>";
showForm();
} else {
generateLink_ISBN();
}
} elseif (isset($_POST['title']) && isset($_POST['aname']) && ($_POST['aname'] != 'Author Name') | ($_POST['title'] != 'Book Title')) {
if (isset($_POST['title']) && isset($_POST['aname']) && ($_POST['title'] == 'Book Title') && ($_POST['aname'] != 'Author Name')) {
echo "<h1>To search by author's name, you must also include the book title.</h1>";
showForm();
} elseif (isset($_POST['title']) && isset($_POST['aname']) && ($_POST['aname'] == 'Author Name') && ($_POST['title'] != 'Book Title')) {
echo "<h1>To search by book title, you must also include the author's name.</h1>";
showForm();
} else {
generateLink_title();
}
} else {
showForm();
}
} else {
showForm();
}
?>
</body>
This always evaluates to true:
You’re saying “if ISBN isn’t 13 characters long or ISBN isn’t 10 characters long, then true”. But no string can be both 13 characters and 10 characters.
Try this instead:
Which would be “if it is not the case that either ISBN is 13 characters or ISBN is 10 characters, then true”.