Hello everyone, I'm new to this forum and to PHP in general. I'm doing a project for Uni and just can not figure out what's wrong with the code I've been staring at it for hours! Can you help? 🙂
I'm getting this: Parse error: syntax error, unexpected T_STRING in /home/.koshi/saras2740/saras.ccacolchester.com/webprog/SoundsGood/webdevstie/addProduct.php on line 108
I think there will be more problems than just this one though! :S
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/maintemp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<?php // check we have data, or do we need to run the form again?
$cd_artist = '';
$cd_title = '';
$cd_genre = '';
$cd_year = '';
$cd_type = 1;
$cd_price = 0.0;
$cd_description = '';
$cs_stock = 0;
$cd_img = '';
$goodload='';
if (isset($_POST['submitted'])) {$errors = array();
//keep a list of problems
require('DBConnection.inc');
if (empty($_POST['artist'])) {$errors[] = 'missing artist';}
else {$cd_artist = $_POST['artist'];}
if (empty($_POST['title'])) {$errors[] = 'missing title';}
else {$cd_title = $_POST['title'];}
if (empty($_POST['genre'])) {$errors[] = 'missing genre';}
else {$cd_genre = $_POST['genre'];}
if (empty($_POST['year'])) {$errors[] = 'missing year';}
else {$cd_year = $_POST['year'];}
if (empty($_POST['type'])) {$errors[] = 'missing type';}
else {$cd_type = $_POST['type'];}
if (empty($_POST['price'])) {$errors[] = 'Missing price';}
else {$cd_price = $_POST['price'];}
if (empty($_POST['description'])) {$cd_decription = '';}
else {$b_reorder = $_POST['decription'];}
if (empty($_POST['stock'])) {$cd_stock = 1;}
else {$cd_stock = $_POST['stock'];}
if (isset($_FILES['uploaded']))
{
if ($_FILES['uploaded']['error'] != 0)
{
$errors[] = 'error uploading file';
//failed to upload a file
}
else
{
$cd_img = $_FILES['uploaded']['tmp_name'];
}
}
else
{
$cd_img = '';
//didnot upload a file}/**** * a submitted form with no errors * so update the database and move that picture (if we uploaded one) ****/
if (empty($errors))
{
if ($cd_img != '')
{
$extn = 'txt';
if (eregi('gif$',$_FILES['uploaded']['type']))
$extn = 'gif';
else
{
if (eregi('jpeg$',$_FILES['uploaded']['type']))$extn = 'jpg';
}
if (move_uploaded_file($cd_img, "pictures/{$cd_title}.{$extn}"))
{
$cd_img = "{$cd_title}.{$extn}";
}
else
{
$cd_img = "failed to load";
}
}
$cmd = "INSERT INTO tProducts (productTypeID, title, description, price, stockCount, artist, genre, year, imgUrl ) values('$cd_type','$cd_title','$cd_description','$cd_price','$cd_stock', '$cd_artist', '$cd_genre', '$cd_year',$b_price, $b_instock ,$b_reorder, '$cd_img')";
$result = mysql_query($cmd);
if ($result)
{
$upload_id = mysql_insert_id();
$goodload = "successfully added id=$upload_id, <em>$cd_title</em>";
}
else
{
$errors[] = "failed to add <em>$cd_title</em> : " . mysql_error();
}
}
// end of empty
($errors)mysql_close();
//finished with the database connection.
}
// end of isset(submitted) ?>
<!-- InstanceEndEditable -->
<?php include('includes/head.inc'); ?>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body>
<div class="container">
<?php include('includes/header.inc'); ?>
<!-- InstanceBeginEditable name="content" -->
<div class="marginbottom">
<div class="left530"><h1>Edit Product</h1></div>
<div class="clearboth"></div>
<div class="formcontainter">
<?php
if (!empty($errors)) {
echo "<h3>errors</h3><br>\n<ul>\n";
foreach ($errors as $msg) {
echo "<li>$msg</li>\n";}
echo "</ul>\n<hr />";}
else {
if ($goodload != '') {
echo $goodload . "<hr />\n";}
} ?>
<form enctype="multipart/form-data" action="addedProduct.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="520000" />
<input type="hidden" name="submitted" value="TRUE" />
<table>
<tr>
<td class="coltype1">
Artist
</td>
<td class="coltype2">
<input id="artist" value=<?php echo "'$cd_artist'"; ?> type="text" />
</td>
<td class="coltype3">
</td>
<td class="coltype1">
Title
</td>
<td class="coltype2">
<input id="title" value=<?php echo "'$cd_title'"; ?> type="text" />
</td>
</tr>
<tr>
<td class="coltype1">
Genre
</td>
<td class="coltype2">
<input id="genre" value=<?php echo "'$cd_genre'"; ?> type="text" />
</td>
<td class="coltype3">
</td>
<td class="coltype1">
Year
</td>
<td class="coltype2">
<input id="year" value=<?php echo "'$cd_year'"; ?> type="text" />
</td>
</tr>
<tr>
<td class="coltype1">
Type
</td>
<td class="coltype2">
<select id="type">
<option value="1">CD</option>
<option value="2">DVD</option>
</select>
</td>
<td class="coltype3">
</td>
<td class="coltype1">
Price
</td>
<td class="coltype2">
<input id="price" value=<?php echo "'$cd_price'"; ?> type="text" />
</td>
</tr>
<tr>
<td class="coltype1">
Des
</td>
<td class="coltype2" colspan="4">
<textarea id="desciption" cols="74" rows="3"></textarea>
</td>
</tr>
<tr>
<td class="coltype1">
Image
</td>
<td class="coltype2">
<input type="file" name="uploaded">
</td>
<td class="coltype3">
</td>
<td class="coltype1">
Stock<br />
</td>
<td class="coltype2">
<input id="stock" value=<?php echo "'$cd_stock'"; ?> type="text" />
</td>
</tr>
<tr>
<td>
</td>
<td colspan="4">
<input class="submit" id="addProduct" name="submit" type="submit" value="Add Product" />
</td>
</tr>
</table></form>
</div>
<!-- InstanceEndEditable -->
<?php include('includes/footer.inc'); ?>
</body>
<!-- InstanceEnd --></html>