Jump to content

Value in Input Field Show in Source Code but Not on Screen

Recommended Posts

I'm trying to validate a form at submittal. The code for my web page is written in php (i.e. server-side). The php file consists of a body file (i.e., body.php) included in a header file (i.e. tool.php). The included body file contains the html code for the body with form. The following php code is inserted at the top of the body file (i.e., before the html <body> and <form> fields:




//Check the validity of the data entered


$activity01 = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $activity01 = $_REQUEST[activity01]; include($_SERVER['DOCUMENT_ROOT'].'included_filesincPHP1.inc'); $cxn=mysqli_connect($host,$user,$password,$database) or die ("Couldn't connect to the server.");

$result = mysqli_query($cxn, "SELECT counter, Activity_Task FROM jsaheader WHERE Activity_Task = '$activity01'"); $counter = mysqli_num_rows($result); $row = mysqli_fetch_assoc($result); if ($counter == 0) { mysqli_close($cxn); } else { mysqli_close($cxn);?>

<SCRIPT type="text/javascript"> window.alert("The 'Activity / Task' that you have selected is not unique. There is already another JSA with the name '<? echo $activity01 ?>.' As each 'Activity / Task' must be unique, you will now be returned to the previous page so that you can select a unique 'Activity / Task.'");</SCRIPT>

<? } }



The problem input field is a text field located within the included body file. The input field content looks like this:


<INPUT type='text' size=75 id='activity01' name='activity01' value='<? echo $activity01;?>'>


When the form is submitted, the php code shown above queries a SQL database to verify that the activity is unique. I've verified that this is actually working. If it is not unique, the user is informed of this through a popup alert and returned to the form. They actually never leave the form. Because of the code within the value attribute, the previously entered activity is supposed to be shown in the input field as it was originally entered. It doesn't but when I look at the source code it shows up there as "value='Test JSA 1'." Got any ideas why that is? The only thing I can think of is that this is happening because the form (and body) is contained within a php file included in the header file. Any help you can give will be very much appreciated.

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...