Jump to content

[SOLVED] what are the options for clearing text fields?


Recommended Posts

I am new to php and html.  I'm modifying a journal article database application.

 

Text field input (title, authors, journal, etc.) and associated pdf file are uploaded.

 

Successful completion prints a sentence at the top but the text fields are not

cleared.  Headers have already been sent so I can't use header (right?).  I

want the text fields empty so the user can enter data for the next pdf to upload.

 

I tried include to reload the page but the text fields remained filled.  If I click on

a button on the page to upload a pdf, it does load a blank page.

 

How do I get the page reload functionality within an if statement?  I don't mind

reading and learning but my search of this forum and google gave limited answers.

 


if (move_uploaded_file ($_FILES['filename']['tmp_name'], "$library_path$file")) {

    $query = "INSERT INTO library (file,authors,title,journal,date1,date2,abstract)
    VALUES ('$file','".mysql_real_escape_string($authors)."','".mysql_real_escape_string($title)."',
	    '$journal','$_POST[date1]','$date2',
            '".mysql_real_escape_string($abstract)."')";
    $result = mysql_query ($query) OR die(mysql_error());

    if (!$result) {
    die ("Could not upload into database: <br />" . mysql_error());
    }
    
include("index.php?action=upload");

print '<H3 STYLE="color: red">The article was recorded successfully.</H3>';

}

} else {
print '<H3 STYLE="color: red">Error! The article is already in the library.</H3>';
}

    @mysql_close($link);

} else {
print '<H3 STYLE="color: red">The limit of 255 characters exceeded in categories.</H3>';
}

} elseif (isset($_POST["form_sent"])) {
echo '<H3 STYLE="color: red">Error! All fields in the form are mandatory.</H3>';
}
?>

Here is the code for the text fields from upload.php  The user has the option of using

a public database (Pubmed) to fill in the fields rather than typing them in manually.  This

is done by fetch.php 

 

Below the text field code is how the upload.php page is called from index.php- I imagine this

is standard.  What I don't understand is that if I click on the "upload pdf" button on the page

the text fields are cleared, but if I put in the include upload.php within the if statement, nothing

happens.

 


<A HREF="index.php?action=download">Online data download from PubMed.</A>
<FORM enctype="multipart/form-data" ACTION="index.php?action=upload" METHOD="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="25000000">
<INPUT TYPE="hidden" NAME="form_sent">
<INPUT TYPE="hidden" NAME="file" VALUE= "<? echo $_POST["file"]; ?>">
<B>Important!</B> Before submission, <A HREF="index.php?action=search&select=all" TARGET="_blank">check</A>
whether the article is already in the library.
<TABLE CELLPADDING="2" CELLSPACING="1" BORDER=0>
<TR>
<TD VALIGN="top">
Add PDF:
</TD>
<TD VALIGN="top">
<INPUT TYPE="file" NAME="filename">
</TD>
</TR>
<TR>
<TD VALIGN="top">
Authors:
</TD>
<TD VALIGN="top">
<TEXTAREA COLS="40" ROWS="3" NAME="authors">
<? echo isset($_POST["authors"]) ? stripslashes($_POST["authors"]) : ''; ?>
</TEXTAREA> (lastname, first inital)
</TD>
</TR>
<TR>
<TD VALIGN="top">
Title:
</TD>
<TD VALIGN="top">
<TEXTAREA NAME="title" COLS=40 ROWS=3 WRAP="SOFT">
<? echo isset($_POST["title"]) ? stripslashes($_POST["title"]) : '' ?>
</TEXTAREA>
</TD>
</TR>
<TR>
<TD VALIGN="top">
Journal:
</TD>
<TD VALIGN="top">
<TEXTAREA NAME="journal" COLS=40 ROWS=1 WRAP="SOFT">
<? echo isset($_POST["journal"]) ? stripslashes($_POST["journal"]) : '' ?>
</TEXTAREA>
</TD>
</TR>
<TR>
<TD VALIGN="top">
Publication date:
</TD>
<TD VALIGN="top">
<INPUT TYPE="text" SIZE="4" MAXLENGTH="4" NAME="date1" VALUE="<? echo isset($_POST["date1"]) ? $_POST["date1"] : '' ?>">
</TD>
</TR>
<TR>
<TD VALIGN="top">
Abstract:
</TD>
<TD>
<TEXTAREA NAME="abstract" COLS=40 ROWS=10 WRAP="SOFT">
<? echo isset($_POST["abstract"]) ? stripslashes($_POST["abstract"]) : '' ?>
</TEXTAREA>
</TD>
</TR>
<TR>
<TD VALIGN="top">
Filename for database uses format:<BR>
JournalAbbreviationVolumePages.pdf
</TD>
<TD VALIGN="top">
<TEXTAREA NAME="file" COLS=40 ROWS=1 WRAP="SOFT">
<? echo isset($_POST["file"]) ? stripslashes($_POST["file"]) : '' ?>
</TEXTAREA>
</TD>
</TR>
<TR>
<TD VALIGN="top">
<INPUT TYPE="submit" VALUE="Upload">
<INPUT TYPE="reset" VALUE=" Reset ">
</TD>

 


//////////////////start upload//////////////////////

if (isset($_GET["action"]) && $_GET["action"] == 'upload' && isset($_SESSION["auth"])) {

@include "upload.php";

Success!  Thanks for your help.  I'm using the Welling & Thompson PHP and MySQL Development

book but there are some things that can only be answered on a forum.

 


if (move_uploaded_file ($_FILES['filename']['tmp_name'], "$library_path$file")) {

    $query = "INSERT INTO library (file_id,file,authors,title,journal,date1,date2,abstract)
    VALUES (NULL,'$file','".mysql_real_escape_string($authors)."','$title','$journal','$_POST[date1]','$date2',
            '$abstract')";
    $result = mysql_query ($query) OR die(mysql_error());

    if (!$result) {
    die ("Could not upload into database: <br />" . mysql_error());
    }
    
    $_POST["file"] = "";
    $_POST["authors"] = "";
    $_POST["title"] = ""; 
    $_POST["journal"] = "";
    $_POST["date1"] = "";
    $_POST["date2"] = "";
    $_POST["abstract"] = "";
    
print '<H3 STYLE="color: red">The article was recorded successfully.</H3>';


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.