I have php page with two forms. One for searching and the other one for updating the searched data. When I updated data it wont show the search form. How can I show the search form after I summited the data. Please help me. My script is below

    <meta name="description" content="Php Code Search & Display Record" />
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    // Find out which form/action we need to load. I have created some
    // hidden input fields to help identifying the forms.
   // echo '<p>The following data has been submitted:</p><pre>'; print_r($_POST); echo '</pre>';

        //* No search query has been submitted yet. Display the search form.
        <form name="search" method="post" action="search.php">
            <input type="hidden" name="form_name" value="search">
            <table style=" border:1px solid silver" cellpadding="5px" cellspacing="0px" align="center" border="0">
                    <td colspan="3" style="background:#0066FF; color:#FFFFFF; fontsize: 20px">
                    <td width="140">Enter Search Keyword</td>
                    <td width="240"><input type="text" name="search" size="40" /></td>
                    <td width="665"><input type="submit" value="Search" /></td>
                <tr bgcolor="#666666" style="color:#FFFFFF">
                    <td>Record ID</td>
                    <td> </td>
    elseif($_POST['form_name'] == 'search' && $_POST['search'])
        //* The search form has been submitted. Display the update form(s).
        $search = $_POST["search"];
        $result = mysql_query("SELECT * FROM saudi_journal WHERE SO like '%$search%'")or die(mysql_error());
        while($row = mysql_fetch_array($result))
            <form  action="search.php" method="post">
                <input type="hidden" name="form_name" value="update">
                <input type="text" name="RID" value="<?php echo $row['RID'];?>" size=6>
                <input type="text" name="AU" value="<?php echo $row['AU'];?>" size=15>
                <input type=text name="TI" value="<?php echo $row['TI']; ?>" size=30>
                <input type=text name="SO" value="<?php echo $row['SO']; ?>" size=40>
                Fulltext Link
                <input type=text name="FULTEXT" value="<?php echo $row['FULTEXT']; ?>" size=40> 
                <input type=submit name="submit" value="submit"></p><br>
    elseif($_POST['form_name'] == 'update')
    //* The update form has been submitted. Update the database.
    // Let's see if we actually arrive at this part:
    $RID = $_POST['RID'];
    $AU = $_POST['AU'];
    $TI = $_POST['TI'];
    $SO = $_POST['SO'];
// In your query, $FULTEXT is probably null, or does it get defined somewhere else?
$query = "UPDATE saudi_journal SET AU ='$AU' , SO='$SO', FULTEXT='$FULTEXT' WHERE RID = '$RID'";

//echo '<p>The query that was executed, is as follows:<br>' . $query . '</p>';
$error = mysql_error();
    echo $error;

    echo "<center>Successfully Updated in DATABASE</center>";

// I need the search form back after this messege



Recommended Answers

All 3 Replies

The search form should use the GET method, because it's a reading instance, the update form a POST method because it writes to the database. So you can do:

# read
    # execute search
        # code and populated form

        # blank form

# write
        # execute update query & redirect to referer page

The redirect after a POST request is important, otherwise, by refreshing the page it will be submitted another time. Check header():

Thank you Sir. I will try and see it. can you please edit in my script and repost it. I am not an expert to do this.

I put my form after the php query. then it work. Any way thanks for replying

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.