I am having a problem with my input line for ISBN numbers

I want the user to input an ISBN number into the blank and after submit is hit and the page refreshes I would like the ISBN entered to still be listed inside of the textbox

can someone please help me? I have searched the internet and the examples i have found did not work for me?

<?
if($_POST['submit']){
	$ISBN = $_POST['ISBN'];
	$EFFECT = $_POST['effect'];
	$SIZE = $_POST['size'];
	echo "<img src='http://images.amazon.com/images/P/$ISBN.01._$EFFECT\ _$SIZE\ _.jpg'>";
}
?>


<html>
<head>
<title>Book Cover Viewer</title>
</head>

<body>
<form method="POST" action="amazon.php">
ISBN (10 digits with no spaces): 
<input type="text" name="ISBN" size="20" value=""></input>(ex: 0672326973)<br><br><br>
Would you like a shadow or a border on your book cover?<br>


Shadow (right) <input type="radio" name="effect" value="PA10,15,15,10"><br>
Shadow (left) <input type="radio" name="effect" value="PB10,15,15,10"><br>
Border (thin and blue)<input type="radio" name="effect" value="BO1,0,0,255"><br>
Border (medium and green)<input type="radio" name="effect" value="BO5,0,255,0"><br>
Border (thick and red)<input type="radio" name="effect" value="BO10,255,0,0"><br>
No effects<input type="radio" name="effect" value="oooo"><br><br><br>

How big would you like the image to be?<br>
Small<input type="radio" name="size" value="SCTZZZZZZZ"><br>
Medium<input type="radio" name="size" value="SCMZZZZZZZ"><br>
Large<input type="radio" name="size" value="SCLZZZZZZZ"><br><br><br>

<input type="submit" name="submit" value="submit"><br>
</form>
</body>

</html>

Dani AI

Generated

Short answer: make the form “sticky” on the server and escape user data. The simplest, most reliable fix is to repopulate the input value from the processed data (POST, session, or cookie) and always run it through htmlspecialchars before printing. Two likely reasons your current page looks empty after submit are (a) PHP short tags (<?) can be disabled on some hosts so your PHP never runs, and (b) the string/quote handling in your echo makes the HTML invalid. is correct that the value should be echoed back; 's cookie idea is useful for longer persistence; 's JS helps focus but does not persist data through a refresh.

Practical pattern (safe and avoids accidental resubmit): validate/save the POST, store the cleaned values in session, then redirect (Post‑Redirect‑Get). After redirect, fill the inputs from session and escape them.

Example (conceptual):

<?php
session_start();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $isbn = trim($_POST['ISBN'] ?? '');
    // basic validation:
    if (preg_match('/^\d{10}$/', $isbn)) {
        $_SESSION['old']['ISBN'] = $isbn;
    } else {
        $_SESSION['old']['ISBN'] = $isbn; // keep for redisplay + show an error
    }
    header('Location: ' . $_SERVER['PHP_SELF']); // PRG
    exit;
}

function old($key) {
    return isset($_SESSION['old'][$key]) ? htmlspecialchars($_SESSION['old'][$key], ENT_QUOTES, 'UTF-8') : '';
}
?>

Then in the form use value="<?php echo old('ISBN'); ?>" and for radios check old('effect') and add checked when it matches. Build image URLs using urlencode() for components and htmlspecialchars() for the final attribute.

Quick troubleshooting checklist: use full PHP tags (<?php), view-source to see the raw value="...", check server error logs/display_errors, ensure form name= values match your PHP keys, and avoid output before header() when using PRG.

Recommended Answers

All 3 Replies

well for one you shouldn't be doing <input></input> but rather <input /> or <input> for XHTML and HTML respectively (you can do the former in HTML also; and it's considered good practice)

I would recommend using cookies, and then if a cookie is already stored then display it in the text box (done by using the value attribute)

That approach may require JavaScript though;

Hope I've helped, Craig` :)

similarly to the way the $_post data is already accessed
ISBN is already defined in the php scrap above, so you can access it

ISBN (10 digits with no spaces): 
<input type="text" name="ISBN" size="20" value="<?php if($ISBN) { echo $ISBN; } ?>" />

You can typically focus an textarea using:

<script type='text/javscript'>setTimeout("document.getElementById('focus').focus();",5);/*Set input focus, timeout as a faux document.ready*/</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.