<?php
// Connects to your Database
$connect = mysql_connect("localhost", "******", "******");
mysql_select_db("dealers");
//checks cookies to make sure they are logged in
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username' AND approved = '1'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password'])
{header("Location: index.php");
}
else
{
//Start of Content
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<meta name="robots" content="noindex, nofollow, noarchive">
</head>
<body>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center" width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td align="center"><strong>Canon Part Number</strong></td>
<td align="center"><strong>Description</strong></td>
<td align="center"><strong>Price</strong></td>
<td align="center"><strong>Quantity</strong></td>
<td align="center"><strong>Condition</strong></td>
</tr>
<tr>
<td align="right"><strong>1.</strong></td>
<td align="center"><input type="text" name="part_no1" /></td>
<td align="center"><input type="text" name="description1" /></td>
<td align="center"><input type="text" name="price1" /></td>
<td align="center"><input type="text" name="quantity1" /></td>
<td align="center"><input type="text" name="condition1" /></td>
</tr>
<tr>
<td align="right"><strong>2.</strong></td>
<td align="center"><input type="text" name="part_no2" /></td>
<td align="center"><input type="text" name="description2" /></td>
<td align="center"><input type="text" name="price2" /></td>
<td align="center"><input type="text" name="quantity2" /></td>
<td align="center"><input type="text" name="condition" /></td>
</tr>
<tr>
<td align="right"><strong>3.</strong></td>
<td align="center"><input type="text" name="part_no3" /></td>
<td align="center"><input type="text" name="description3" /></td>
<td align="center"><input type="text" name="price3" /></td>
<td align="center"><input type="text" name="quantity3" /></td>
<td align="center"><input type="text" name="condition3" /></td>
</tr>
<tr>
<td align="right"><strong>4.</strong></td>
<td align="center"><input type="text" name="part_no4" /></td>
<td align="center"><input type="text" name="description4" /></td>
<td align="center"><input type="text" name="price4" /></td>
<td align="center"><input type="text" name="quantity4" /></td>
<td align="center"><input type="text" name="condition4" /></td>
</tr>
<tr>
<td align="right"><strong>5.</strong></td>
<td align="center"><input type="text" name="part_no5" /></td>
<td align="center"><input type="text" name="description5" /></td>
<td align="center"><input type="text" name="price5" /></td>
<td align="center"><input type="text" name="quantity5" /></td>
<td align="center"><input type="text" name="condition5" /></td>
</tr>
</table>
<hr />
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><input type="submit" name="submit" value="Submit Parts" default="default" />
<input type="reset" onClick="return confirm('Are you sure you want to clear the form?')" />
</td>
</tr>
<tr>
<td align="center"><input type="hidden" name="date" value="<? echo date("j-M"); ?>" /></td>
</tr>
</table>
</form>
</body>
</html>
<?
if (isset($_POST['submit'])) {
$i=1;
while($i<=5) {
$check2 = 'part_no'.$i;
if(!empty($_POST[$check2])) {
$sql = "INSERT INTO `parts` (`part_no`, `description`, `price`, `quantity`, `date`, `user`, `avaliable`, `condition`) VALUES ('".$_POST["part_no".$i]."', '".$_POST["description".$i]."', '".$_POST["price".$i]."', '".$_POST["quantity".$i]."', '$_POST[date]', '$username', '1', '".$_POST["condition".$i]."')";
//echo $sql ."<br>";
mysql_query($sql) or die(mysql_error());
//echo ("<br>Inserted<br>");
}
$i++;
}
echo ("<br /><h4 align='center'>Inserted</h4>");
}
//End of content
}
}
else
//if the cookie does not exist, they are taken to the login screen
{
header("Location: index.php");
}
?>I have spent ages trying to figure out what is wrong... when i comment out the PHP it works (the form is displayed), when it's not the page is white. I've tried adding sections of the PHP slowly but still can't pin point it... i'm probably just tired and its an easy fix... but i can't find it. I've checked and the cookie is being created, so that's not the problem either...
I'm not to sure on the
if(!empty($_POST[$check2]))
but i have it on another page and it works fine.
or should it be
$check2 = $_POST['part_no'.$i]; if(!empty($check2))
This post has been edited by KamakaZ: 19 March 2010 - 04:45 AM

Help


Back to top










