Jump to content

unexpected $end error, cant get IF statement to work


mikebyrne

Recommended Posts

I want my code to check that the user HAS selected a radio button before proceeding with the code but I keep getting an $end error refering to the last line of my code. I've taken out some CSS to make it easier to view

 


<?php
if($_POST['something'] == "")
{
    echo "Please select item";

}	
else
{
?>
<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  <tr align="left">
    <td><a href="#">SELECT</a></td>
    <td><a href="#">PRODCT NO</a></td>
    <td><a href="#">PRODUCT NAME</a></td>
    <td><a href="#">STOCK LEVEL</a></td>
    <td><a href="#">DISPLAY</a></td>
    <td><a href="#">PRICE</a></td>
  </tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'DVD' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
// loop through and display
?>
  <tr align="left">
    <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    <td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    <td><?php echo $row['ProductName'];?></td>
    <td><?php echo $row['Stockamount'];?></td>
    <td><?php echo $row['Display'] ;?></td>
    <td><?php echo $row['Price'];?></td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>



</div>

</div>
</form>
</body>
</html>

 

I assume that the code is looking for } to end the php but i cant see where I should put it ??

As stated by revraz, you do close the while statement, but you don't close the else statement.

 

also for the first line I would do something like

 

if(!$_POST['something'])
{
    echo "Please select item";

} else {
    echo "Item was selected, etc";
}	

So you tried doing:

 

<?php
if (!$_POST['something'])
{
    echo "Please select item";

}	
else
{
?>
<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  			<tr align="left">
    			<td><a href="#">SELECT</a></td>
    			<td><a href="#">PRODCT NO</a></td>
		    <td><a href="#">PRODUCT NAME</a></td>
    			<td><a href="#">STOCK LEVEL</a></td>
  			    <td><a href="#">DISPLAY</a></td>
    			<td><a href="#">PRICE</a></td>
  			</tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'DVD' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
	// loop through and display
?>
	<tr align="left">
    		<td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    		<td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    		<td><?php echo $row['ProductName'];?></td>
    		<td><?php echo $row['Stockamount'];?></td>
    		<td><?php echo $row['Display'] ;?></td>
    		<td><?php echo $row['Price'];?></td>
  		</tr>

	<tr><td colspan="6"><hr /></td><td></tr>
<?php
} // close while statement.
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>



</div>

</div>
</form>
<?php 
} // close if/else
?>
</body>
</html>

?

 

No the code you gave me fixed it!

 

<?php

} // close if/else

?>

 

I was only using } as opposed to wrapping the php tags around it!!

 

Now the problem is that my php to list all the items doesnt start. I just see "Please select item" as opposed the list of items from the database

No the code you gave me fixed it!

 

<?php

} // close if/else

?>

 

I was only using } as opposed to wrapping the php tags around it!!

 

Now the problem is that my php to list all the items doesnt start. I just see "Please select item" as opposed the list of items from the database

 

Probably because your design.  When the user requests the page, they obviously haven't even selected anything yet.  So in that case since there is no $_POST it will only display the "Please Select Item".

 

For a simple procedural approach like this I would make a custom showForm() function or something

<html><body>
<?php

function showForm()
{
?>
<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  			<tr align="left">
    			<td><a href="#">SELECT</a></td>
    			<td><a href="#">PRODCT NO</a></td>
		    <td><a href="#">PRODUCT NAME</a></td>
    			<td><a href="#">STOCK LEVEL</a></td>
  			    <td><a href="#">DISPLAY</a></td>
    			<td><a href="#">PRICE</a></td>
  			</tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'DVD' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
	// loop through and display
?>
	<tr align="left">
    		<td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    		<td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    		<td><?php echo $row['ProductName'];?></td>
    		<td><?php echo $row['Stockamount'];?></td>
    		<td><?php echo $row['Display'] ;?></td>
    		<td><?php echo $row['Price'];?></td>
  		</tr>

	<tr><td colspan="6"><hr /></td><td></tr>
<?php
} // close while statement.
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>

</div>

</div>
</form>

<?php
} // end of function show form




if (!$_POST['something'])
{
    echo "Please select item";
showForm();

}	
elseif (!$_POST['submit'])
{
showForm();	
} // close if/else
?>
</body>
</html>

 

 

That's actually not even the best way of going about it, it's crude and will work, but is not flexible.  As you get better you'll find better ways of solving this problem.

Yeah that would be great. Im not familar with functions. My complete code includind the CSS is

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample | item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>

<div id="contentBox">

<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- logo finish -->



<!-- menu start -->

	<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/new.php" class="black">order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
		<div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>

	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"> </div>
		<div id="menu_space1"><!-- --></div>
		<div class="clr"><!-- --></div>
  <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_on"><!-- --></div>
          <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div>
          <div id="menu_space2">
            <!-- -->
          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div>
          <div id="menu_space2">
            <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div>
          <div class="clr">
            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
          <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        
<!-- menu finish -->



<!-- top start -->
<div id="container">

	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->









<!-- 1px space start -->
<div id="containerBg1">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">
<?php
if($_POST['something'] == "")
{
    echo "Please select item";

}	
else
{
?>
<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  <tr align="left">
    <td><a href="#">SELECT</a></td>
    <td><a href="#">PRODCT NO</a></td>
    <td><a href="#">PRODUCT NAME</a></td>
    <td><a href="#">STOCK LEVEL</a></td>
    <td><a href="#">DISPLAY</a></td>
    <td><a href="#">PRICE</a></td>
  </tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'DVD' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
// loop through and display
?>
  <tr align="left">
    <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    <td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    <td><?php echo $row['ProductName'];?></td>
    <td><?php echo $row['Stockamount'];?></td>
    <td><?php echo $row['Display'] ;?></td>
    <td><?php echo $row['Price'];?></td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>



</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->


</div>

</div>
</form>
<?php 
} // close if/else
?>
</body>
</html>

 

Really appreciate the help!!!

The problem is you are mixing design layer and code layer.  You need to work to modulize even small amounts of code because as your projects grow larger, it will be very hard to maintain.

 

A few months ago someone told me that, and it didn't make sense to me then, so I don't expect you to understand what I just said but once you do you will see what I mean.

 

Really, this entire thing would be very very simple if you used Objects, but since you are still learning here's a simple procedural script that will work fine for your purposes.

 

<?php

function showForm()
{
?>
<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  			<tr align="left">
    			<td><a href="#">SELECT</a></td>
    			<td><a href="#">PRODCT NO</a></td>
		    <td><a href="#">PRODUCT NAME</a></td>
    			<td><a href="#">STOCK LEVEL</a></td>
  			    <td><a href="#">DISPLAY</a></td>
    			<td><a href="#">PRICE</a></td>
  			</tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'DVD' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
	// loop through and display
?>
	<tr align="left">
    		<td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    		<td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    		<td><?php echo $row['ProductName'];?></td>
    		<td><?php echo $row['Stockamount'];?></td>
    		<td><?php echo $row['Display'] ;?></td>
    		<td><?php echo $row['Price'];?></td>
  		</tr>

	<tr><td colspan="6"><hr /></td><td></tr>
<?php
} // close while statement.



?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>

</div>

</div>
</form>

<?php
} // end of function show form



// core code



if (!$_POST['submit'])
{
// form has not been submitted!!
showForm();	
} else {
// form has been submitted, let's check it!
$errors = array();  // initialize an errors array.

if (!$_POST['something'])
{ 
	// we didnt get 'something', so we'll add an error.
	$errors[] = "You need to select an item!<br />"; 
}

/* heres to show how you can add other parameters to check for"
if (!$_POST['something_else']
{
	$errors[] . "You forgot to enter something_else! <br />";
}
*/

if ($errors)
{
	// if there's errors in the validation, we'll echo them and the form.
	foreach ($errors as $errormsg)
	{
		echo $errormsg;
	}
	showForm();
} else {
	// otherwise we'll put the customers selection into a database or whatever we want to do with the form data
	echo "form completed correct, do data entry or whatever here";
}

}

?>

 

I hope what I did is self-explanatory, lemme know if you have more questions though.

 

 

 

BTW you can create your own functions to do jobs that you will do a lot (such as show the form both on failure and if the form hasn't been submitted yet.... just make sure you don't name your functions after built in PHP functions [for instance... dont have a function named echo() ... ])

Ok I made a first attempt to put the code together but the validation doesnt take place

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample | item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>

<div id="contentBox">

<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- logo finish -->



<!-- menu start -->

	<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/new.php" class="black">order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
		<div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>

	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"> </div>
		<div id="menu_space1"><!-- --></div>
		<div class="clr"><!-- --></div>
  <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_on"><!-- --></div>
          <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div>
          <div id="menu_space2">
            <!-- -->
          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div>
          <div id="menu_space2">
            <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div>
          <div class="clr">
            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
          <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        
<!-- menu finish -->



<!-- top start -->
<div id="container">

	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->









<!-- 1px space start -->
<div id="containerBg1">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">
<?php

function showForm()
{
?>



<!-- data start -->



<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  







<tr align="left">
    







<td><a href="#">SELECT</a></td>
    







<td><a href="#">PRODCT NO</a></td>







    <td><a href="#">PRODUCT NAME</a></td>
    







<td><a href="#">STOCK LEVEL</a></td>
  







    <td><a href="#">DISPLAY</a></td>
    







<td><a href="#">PRICE</a></td>
  







</tr>
<?php



// let's get some data



include('adminconnect.php');



$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' ";



$result = mysql_query($query) or die (mysql_error());



while ($row = mysql_fetch_array($result))



{





// loop through and display
?>





<tr align="left">
    





<td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    





<td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    





<td><?php echo $row['ProductName'];?></td>
    





<td><?php echo $row['Stockamount'];?></td>
    





<td><?php echo $row['Display'] ;?></td>
    





<td><?php echo $row['Price'];?></td>
  





</tr>





<tr><td colspan="6"><hr /></td><td></tr>
<?php



} // close while statement.



?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>

</div>

</div>
</form>

<?php
} // end of function show form



// core code



if (!$_POST['submit'])
{



// form has not been submitted!!



showForm();




} else {



// form has been submitted, let's check it!



$errors = array();  // initialize an errors array.






if (!$_POST['something'])



{ 





// we didnt get 'something', so we'll add an error.





$errors[] = "You need to select an item!<br />"; 



}






/* heres to show how you can add other parameters to check for"



if (!$_POST['something_else']



{





$errors[] . "You forgot to enter something_else! <br />";



}



*/






if ($errors)



{





// if there's errors in the validation, we'll echo them and the form.





foreach ($errors as $errormsg)





{







echo $errormsg;





}





showForm();



} else {





// otherwise we'll put the customers selection into a database or whatever we want to do with the form data





echo "form completed correct, do data entry or whatever here";



}




}

?>

<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->
</form>
</body>
</html>

 

 

Im having 2 small problems

 

1) The SQL doesnt run when the page loads and therefore doesnt fill the tables

 

2) If I select no optionbox and press Edit it doesnt perform the validation

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample | item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>

<div id="contentBox">

<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- logo finish -->



<!-- menu start -->

	<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/new.php" class="black">order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
		<div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>

	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"> </div>
		<div id="menu_space1"><!-- --></div>
		<div class="clr"><!-- --></div>
  <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_on"><!-- --></div>
          <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div>
          <div id="menu_space2">
            <!-- -->
          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div>
          <div id="menu_space2">
            <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div>
          <div class="clr">
            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
          <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        
<!-- menu finish -->



<!-- top start -->
<div id="container">

	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->









<!-- 1px space start -->
<div id="containerBg1">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">
<?php

function showForm()
{
?>



<!-- data start -->



<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  







<tr align="left">
    







<td><a href="#">SELECT</a></td>
    







<td><a href="#">PRODCT NO</a></td>







    <td><a href="#">PRODUCT NAME</a></td>
    







<td><a href="#">STOCK LEVEL</a></td>
  







    <td><a href="#">DISPLAY</a></td>
    







<td><a href="#">PRICE</a></td>
  







</tr>
<?php



// let's get some data



include('adminconnect.php');



$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' ";



$result = mysql_query($query) or die (mysql_error());



while ($row = mysql_fetch_array($result))



{





// loop through and display
?>





<tr align="left">
    





<td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    





<td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    





<td><?php echo $row['ProductName'];?></td>
    





<td><?php echo $row['Stockamount'];?></td>
    





<td><?php echo $row['Display'] ;?></td>
    





<td><?php echo $row['Price'];?></td>
  





</tr>





<tr><td colspan="6"><hr /></td><td></tr>
<?php



} // close while statement.



?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>

</div>

</div>
</form>

<?php
} // end of function show form



// core code



if (!$_POST['submit'])
{



// form has not been submitted!!



showForm();




} else {



// form has been submitted, let's check it!



$errors = array();  // initialize an errors array.






if (!$_POST['something'])



{ 





// we didnt get 'something', so we'll add an error.





$errors[] = "You need to select an item!<br />"; 



}






/* heres to show how you can add other parameters to check for"



if (!$_POST['something_else']



{





$errors[] . "You forgot to enter something_else! <br />";



}



*/






if ($errors)



{





// if there's errors in the validation, we'll echo them and the form.





foreach ($errors as $errormsg)





{







echo $errormsg;





}





showForm();



} else {





// otherwise we'll put the customers selection into a database or whatever we want to do with the form data





echo "form completed correct, do data entry or whatever here";



}




}

?>

<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->
</form>
</body>
</html>

 

Archived

This topic is now archived and is closed to further replies.

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