Ok, let's start from the beginning.
I personally, would do it the other way around:
<?
include("db_connect.php");
if (!isset($_POST["submit"])) // If form not submitted
{
$barcode1=$_POST["barcode1"];
$barcode2=$_POST["barcode2"];
$barcode3=$_POST["barcode3"];
$barcode4=$_POST["barcode4"];
}
else
{
//printing the form:
?>
You'll also notice from this that I've changed the include ""; to include("");
Ok, next...
There are quite a few mistakes in the HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.01 transitional//EN">
<html>
<head><title>Your title goes here</title></head>
<body>
<form action="print.php" method="post">
<TABLE border=0 cellpadding=3 cellspacing=3>
<tr>
<td>barcode1</td>
<td><input type="text" name="barcode1" size="15" maxlength="9" value="<?php echo $_POST["barcode1"]; ?>"></td>
</tr>
<tr>
<td>barcode2</td>
<td><input type="text" name="barcode2" size="5" maxlength="8" value="<?php echo $_POST["barcode2"]; ?>"></td>
</tr>
<tr>
<td>barcode3</td>
<td><input type="text" name="barcode3" size="5" maxlength="8" value="<?php echo $_POST["barcode3"]; ?>"></td>
</tr>
<tr>
<td>barcode4</td>
<td><input type="text" name="barcode4" size="5" maxlength="8" value="<?php echo $_POST["barcode4"]; ?>"></td>
</tr>
<tr>
<td align="right"><input type="submit" name="submit" value="Send"></td>
<td align="left"><input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
<?
}
?>
As you can see, the PHP values used should always be written as follows:
<?php echo $_POST["postname"]; ?>
I've also added quotation marks in the HTML plus a !DOC TYPE (although this isn't really neccessary unless you're putting this up on the web.
I can't understand the last bit, it would help in future if you used the php tags as it helps to make it readable (as above), however the errors have been corrected for you below:
<?php
include "db_connect.php"; //connecting to MySQL server and DB
$sql = "SELECT price
FROM classics WHERE barcode = " + $_POST['barcode1'];
$res = mysql_query($sql);
$total = 0;
while($row=mysql_fetch_array($res)) {
$total += $row['price'];
}
echo $_POST["barcode1"];
echo "<br />";
echo $_POST["barcode2"];
echo "<br />";
echo $_POST["barcode3"];
echo "<br />";
echo $_POST["barcode4"];
echo "<br />";
echo $total;
?>
If the above were declared as variables and not $_POST's then you can use:
echo $barcode1;
But don't forget that <br /> is not part of the PHP syntax so you always write it as follows:
echo "<br />";
Hope this helps,
Chris