Just tried to make something of your code. But there are a few things you really need to take a look at:

  1. You are missing some closing tags in your html, for example you are missing a </div> & </form> tag.
  2. You can put all your php code at the top of your page. It's a best practice to seperate your logic from your view.
  3. Proper php opening and closing tags looks like the following : <?php ... ?> not <= or <?
  4. A proper PDO connection looks like this

    <?php try { $db = new PDO("pgsql:dbname=pdo;host=localhost", "username", "password" ); echo "PDO connection object created"; } catch(PDOException $e){ echo $e->getMessage(); } ?>

  5. If you want to concatenate a ul to output your errors you will have to do that the as follow:

    <?php str .= '<li></li>'; str .= '</ul>'; ?>

The foundation of the errors you are getting are caused by points like the above. Goodluck and ask if you have any more questions.

Answer from Frank W. on Stack Overflow
Top answer
1 of 2
2

Just tried to make something of your code. But there are a few things you really need to take a look at:

  1. You are missing some closing tags in your html, for example you are missing a </div> & </form> tag.
  2. You can put all your php code at the top of your page. It's a best practice to seperate your logic from your view.
  3. Proper php opening and closing tags looks like the following : <?php ... ?> not <= or <?
  4. A proper PDO connection looks like this

    <?php try { $db = new PDO("pgsql:dbname=pdo;host=localhost", "username", "password" ); echo "PDO connection object created"; } catch(PDOException $e){ echo $e->getMessage(); } ?>

  5. If you want to concatenate a ul to output your errors you will have to do that the as follow:

    <?php str .= '<li></li>'; str .= '</ul>'; ?>

The foundation of the errors you are getting are caused by points like the above. Goodluck and ask if you have any more questions.

2 of 2
1

What about closing the form tag:

<div id="slide4">
  <div class="slidetitle">Contact Me</div>
  <div class="content">
    <form action="index.php#slide4" method="POST" id="contactform">
      <input type="hidden" name="postid" value="<?=$postid?>">
      <table>
        <tr>
          <td><b>First Name:</b>
          </td>
          <td>
            <input type="text" name="firstName" size="45" value="<?=$firstName?>">
          </td>
        </tr>
        <tr>
          <td><b>Last Name:</b>
          </td>
          <td>
            <input type="text" name="lastName" size="45" value="<?$lastName?>">
          </td>
        </tr>
        <tr>
          <td><b>Email:</b>
          </td>
          <td>
            <input type="email" name="email" size="45" value="<?$email?>">
          </td>
        </tr>
        <tr>
          <td><b>Phone:</b>
          </td>
          <td>
            <input type="number" name="phone" size="45" value="<?$phone?>">
          </td>
        </tr>
        <tr>
          <td><b>Content:</b>
          </td>
          <td>
            <textarea name="content" form="contactform" rows="10" cols="100">
              <?php echo $content; if (empty($content)){ echo "Enter text here...";} ?>
            </textarea>
          </td>
        </tr>
        <tr>
          <td colspan=2 style="text-align: center">
            <input type=submit name="submit1" value="Leave me a message">
          </td>
        </tr>
      </table>
    </form>  <!-- MISSING !! -->
  </div>
</div>

🌐
InformIT
informit.com › articles › article.aspx
Combining HTML and PHP Code on a Single Page | Working with Forms in PHP | InformIT
In Listing 9.9, we begin to build up the PHP element of the page. First, we need to define the number that the user will guess. In a fully working version, we would probably randomly generate this, but for now we will keep it simple. We assign '42' to the $num_to_guess variable on line 2. Next, we need to decide whether the form has been submitted; otherwise, we will attempt to assess variables that have not yet been made available.
🌐
YouTube
youtube.com › manju explains
PHP Single Page Form Validation - YouTube
Simple html/php script to validate a login forms, registration forms etc in the same page.
Published   July 3, 2014
Views   8K
🌐
Stack Overflow
stackoverflow.com › questions › 49451040 › single-page-application-form
php - Single Page Application Form - Stack Overflow
March 23, 2018 - <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> h1{ text-align: center; } </style> <title> CRUD</title> </head> <body> <h1> CRUD Management</h1> <!--Create Row--> <h2> Create new Entry </h2> <form> <p> <label for="ID">ID:</label> <input type="text" name="id" id="id"> </p> <p> <label for="creator">Creator:</label> <input type="text" name="creator" id="creator"> </p> <p> <label for="title">Title:</label> <input type="text" name="title" id="title"> </p> <p> <label for="type">Type:</label> <input type="text" name="type" id="type"> </p> <p> <label for="identifier">Identifier:
🌐
PHP
pear.php.net › manual › en › package.html.html-quickform2.controller-overview.php
Manual :: Easy building of multipage forms
Class representing a single page of the form. Contains an instance of HTML_QuickForm2. ... Action handlers implement this interface. HTML_QuickForm2_Controller is a rewrite of PHP4 HTML_QuickForm_Controller, so if you are already using the latter you can go to migration guide which contains ...
Top answer
1 of 6
14

You can tell the form to submit to the PHP's self, then check the $_POST variables for form processing. This method is very good for error checking as you can set an error and then have the form reload with any information the user's previously submitted still in tact (i.e. they don't lose their submission).

When the "submit" button is clicked, it will POST the information to the same page, running the PHP code at the top. If an error occurs (based on your checks), the form will reload for the user with the errors displayed and any information the user supplied still in the fields. If an error doesn't occur, you will display a confirmation page instead of the form.

<?php
//Form submitted
if(isset($_POST['submit'])) {
  //Error checking
  if(!$_POST['yourname']) {
    $error['yourname'] = "<p>Please supply your name.</p>\n";
  }
  if(!$_POST['address']) {
    $error['address'] = "<p>Please supply your address.</p>\n";
  }

  //No errors, process
  if(!is_array($error)) {
    //Process your form

    //Display confirmation page
    echo "<p>Thank you for your submission.</p>\n";

    //Require or include any page footer you might have
    //here as well so the style of your page isn't broken.
    //Then exit the script.
    exit;
  }
}
?>

<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
  <?=$error['yourname']?>
  <p><label for="yourname">Your Name:</label><input type="text" id="yourname" name="yourname" value="<?=($_POST['yourname'] ? htmlentities($_POST['yourname']) : '')?>" /></p>
  <?=$error['address']?>
  <p><label for="address">Your Address:</label><input type="text" id="address" name="address" value="<?=($_POST['address'] ? htmlentities($_POST['address']) : '')?>" /></p>
  <p><input type="submit" name="submit" value="Submit" /></p>
</form>
2 of 6
7

The easiest construction is to detect whether the $_POST array is not empty

if(isset($_POST['myVarInTheForm'])) {
  // Process the form
}

// do the regular job
🌐
DEV Community
dev.to › generatecodedev › how-to-create-a-php-registration-form-as-a-single-page-application-56p
How to Create a PHP Registration Form as a Single Page Application? - DEV Community
May 5, 2025 - For instance, before navigating to the next page, save the input values to local storage and retrieve them when needed. Yes, modern browsers support JavaScript and AJAX, enabling the SPA dynamic loading method. However, always test across different browsers to ensure compatibility. Transitioning your PHP registration form to a Single Page Application can significantly enhance speed and user experience.
🌐
California State University, Northridge
csun.edu › ~akaplan › index_php.txt
A simple single-page PHP form
2 || $pageNum < 1) { echo("Error...this page does not exist!"); die(); } echo ("This is page# $pageNum"); if($pageNum == 1) { ?>
Find elsewhere
🌐
PHP
php.net › manual › en › tutorial.forms.php
PHP: Dealing with Forms - Manual
If we used the method GET then our form information would live in the $_GET superglobal instead. You may also use the $_REQUEST superglobal, if you do not care about the source of your request data. It contains the merged information of GET, POST and COOKIE data. Learn How To Improve This Page • ...
🌐
Stack Overflow
stackoverflow.com › questions › 10936359 › more-than-one-form-on-a-single-page
php - More than one form on a single page - Stack Overflow
You cannot nest forms. ... Just as an aside, you can definitely write cleaner code, and it will make your life much easier. You don't need to be echoing html wholesale: just close your php and write it, so it's readable to you, and then open ...
🌐
Quora
quora.com › How-do-you-display-submitted-data-on-the-same-page-as-the-form-in-PHP
How to display submitted data on the same page as the form in PHP - Quora
It covers form display, submission handling (POST/GET), validation/sanitization, repopulating fields, and preventing duplicate submissions. 1) Single-file structure (recommended) Use the same PHP file to render the form and handle the submission.
🌐
Bavotasan
bavotasan.com › home › processing multiple forms on one page with php
Processing Multiple Forms on One Page with PHP - bavotasan.com
October 30, 2012 - <form name="mailinglist" method="post"> <input type="text" name="email" /> <input type="submit" name="mailing-submit" value="Join Our Mailing List" /> </form> <form name="contactus" method="post"> <input type="text" name="email" /> <input type="text" name="subjet" /> <textarea name="message"></textarea> <input type="submit" name="contact-submit" value="Send Email" /> </form> Now lets put some PHP code before the <head> tag to have different processes for each form.
🌐
SitePoint
sitepoint.com › php
Multiple Forms on One Page - PHP - SitePoint Forums | Web Development & Design Community
July 19, 2014 - Under each Article on my website, members can post Comments. And beneath each Comment, other members can give the Comment a rating. So if there are 30 Comments, I would have 30 Forms!! What is the proper way to set up my Forms and Submit buttons so they work properly? Here is an example…
Top answer
1 of 3
2

This is what hidden inputs are for. Add one for your id:

<input type="hidden" name="id[]" value="<?=$rows['id']?>" />

Also, you don't need to save the count. You can count the number of items in an array using count($id).

Finally, sanitize your inputs. Never put user submitted data straight into a query. Use intval for integers and mysql_real_escape_string for strings, or use prepared statements.

2 of 3
0

Please check this out... I have added two lines in your code and ID is being fetched and you can update data accordingly. I have commented as NOTE HERE..

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name="inventory"; // Database name 
$tbl_name="computers"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 

mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form 
$school=$_POST['school'];
$make=$_POST['make'];
$model=$_POST['model'];
$barcode=$_POST['barcode'];
$location=$_POST['location'];
//Note here
$id = $_POST['id'];
?>

    <?php
    include 'nav-bar.php';
    ?>

    <h2 align="center">Filter Computers</h2>
    <form name="form" method="post" style="margin: 0; text-align: center;">
    <p><label>School Name:</label><input type="text" name="school" size="8" id="school" tabindex="1"</p>
    <p><label>Make:</label><input type="text" name="make" size="25" id="make" tabindex="1"</p>
    <p><label>Model:</label><input type="text" name="model" size="25" id="model" tabindex="1"</p>
    <p><label>Barcode:</label><input type="text" name="barcode" size="12" id="barcode" tabindex="1"</p>
    <p><label>Location:</label><input type="text" name="location" size="25" id="location" tabindex="1"</p>
    <p><label>Serial:</label><input type="text" name="serial" size="25" id="location" tabindex="1"</p>
    <p><label>Date Acquired yyyy-dd-mm:</label><input type="text" name="date" size="8" id="location" tabindex="1"</p>
    <p><label>Processor:</label><input type="text" name="processor" size="25" id="location" tabindex="1"</p>
    <p><label>RAM:</label><input type="text" name="ram" size="25" id="location" tabindex="1"</p>
    <p><input align="center" type="submit" name="Filter" value="Filter">
    </form>

    <?php

    if($_POST['Filter']){
    $sql = "SELECT * FROM $tbl_name WHERE school like '%$school' AND make like '%$make' AND model like '%$model' AND location like '%$location'";
    $result=mysql_query($sql);

    // Count table rows 
    $count=mysql_num_rows($result);
    $_SESSION['count']=$count;


    ?>

    <strong>Update Multiple Computers</strong><br> 
    <table width="500" border="0" cellspacing="1" cellpadding="0">
    <form name="form1" method="post" action="">
    <tr> 
    <td>
    <table width="500" border="0" cellspacing="1" cellpadding="0">


    <tr>
    <td align="center"><strong>Id</strong></td>
    <td align="center"><strong>School</strong></td>
    <td align="center"><strong>Make</strong></td>
    <td align="center"><strong>Model</strong></td>
    <td align="center"><strong>Barcode</strong></td>
    <td align="center"><strong>Location</strong></td>
    </tr>

    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
    <td align="center"><input name="school[]" type="text" id="school" value="<?php echo $rows['school']; ?>"></td>
    <td align="center"><input name="make[]" type="text" id="make" value="<?php echo $rows['make']; ?>"></td>
    <td align="center"><input name="model[]" type="text" id="model" value="<?php echo $rows['model']; ?>"></td>
    <td align="center"><input name="barcode[]" type="text" id="barcode" value="<?php echo $rows['barcode']; ?>"></td>
    <td align="center"><input name="location[]" type="text" id="location" value="<?php echo $rows['location']; ?>"></td>
    <!-- Note here-->
    <input type="hidden" name="id[]" id="id" value="<?php echo $rows['id']; ?>" />
    </tr>

    <?php
    }
    ?>
    <tr>
    <td colspan="4" align="center"><input type="submit" name="Update" value="Update"></td>
    </tr>
    </table>
    </td>
    </tr>
    </form>
    </table>
    <?php
    }
    // Check if button name "Update" is active, do this 
    if(isset($_POST['Update'])){
    for($i=0;$i<$_SESSION['count'];$i++){
    $sql1="UPDATE $tbl_name SET school='$school[$i]', make='$make[$i]', model='$model[$i]' , barcode='$barcode[$i]' , location='$location[$i]' WHERE id='$id[$i]'";
    $result1=mysql_query($sql1);
    }
    session_destroy();
    }
    if(isset($result1)){
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=update_multiple.php\">";
    }
    ?>

I hope that will help you.

🌐
CopyProgramming
copyprogramming.com › howto › single-page-application-form
Application Form on a Single Page - Php
April 8, 2023 - To avoid a <form> from reloading ... a single page application with php?, 0. To write a single page application with PHP you have to use "$_SERVER ['PHP_SELF']" in your form tag....