/    Sign up×
Community /Pin to ProfileBookmark

Need an extra pair of eyes im going crazy with this prob

Page 1 takes info using the following form

[CODE]<form method=”post” action=”listnew3preview.php” name=”listmachine” enctype=”multipart/form-data”>
<fieldset id=”personal_information” class=”contact_form”>
<legend>Machine Information </legend>
<table width=”100%” class=”contact_form” id=”personal_info”>
<tr>
<th width=”34%”><label for=”_r_name”><font color=”#FF0000″>*</font> Select Category </label></th>
<td width=”66%”><?
if($pid!=”)
{
?>
<select name=”catid”>
<?
$selcat=mysql_query(“select * from category WHERE subid = 0 order by cat_name”);
while($rew=mysql_fetch_array($selcat))
{
if ($rew[‘cat_id’]==$prow[‘category_id’]) { $selected=’ selected=”SELECTED”‘; } else { $selected=”; }
echo ‘<option value=”‘.$rew[‘cat_id’].'”‘.$selected.’>’.$rew[‘cat_name’].'</option>’;

$selcat2=mysql_query(“select * from category WHERE subid = “.$rew[‘cat_id’].” order by cat_name”);
while($rew2=mysql_fetch_array($selcat2))
{
if ($rew2[‘cat_id’]==$prow[‘category_id’]) { $selectedm=’ selected=”SELECTED”‘; } else { $selectedm=”; }
echo ‘<option value=”‘.$rew2[‘cat_id’].'”‘.$selectedm.’>&nbsp;&nbsp;&nbsp;-‘.$rew2[‘cat_name’].'</option>’;
}
}
?>
</select>
<?
}
else
{
?>
<select name=”catid”>
<?
$selcat=mysql_query(“select * from category WHERE subid = 0 order by cat_name”);
while($rew=mysql_fetch_array($selcat))
{
if ($rew[‘cat_id’]==$prow[‘category_id’]) { $selected=’ selected=”SELECTED”‘; } else { $selected=”; }
echo ‘<option value=”‘.$rew[‘cat_id’].'”‘.$selected.’>’.$rew[‘cat_name’].'</option>’;

$selcat2=mysql_query(“select * from category WHERE subid = “.$rew[‘cat_id’].” order by cat_name”);
while($rew2=mysql_fetch_array($selcat2))
{
if ($rew2[‘cat_id’]==$prow[‘category_id’]) { $selectedm=’ selected=”SELECTED”‘; } else { $selectedm=”; }
echo ‘<option value=”‘.$rew2[‘cat_id’].'”‘.$selectedm.’>&nbsp;&nbsp;&nbsp;-‘.$rew2[‘cat_name’].'</option>’;
}
}
?>
</select>
<? }
?></td>
</tr>

<tr>
<th><font color=”#FF0000″>*</font> Make/Model</th>
<td><input type=”text” name=”makemodel” value=””></td>
</tr>
<tr>
<th>Price (optional) </th>
<td><input type=”text” name=”prices” value=””></td>
</tr>
<tr>
<th valign=”top”>&nbsp;Description</th>
<td><textarea cols=”30″ rows=”6″ name=”desc”></textarea></td>
</tr>
<tr>
<th valign=”top”><font color=”#FF0000″>*</font> Capacity </th>
<td><input type=”text” name=”capacity” value=””></td>
</tr>
<tr>
<th valign=”top”><font color=”#FF0000″>*</font> Control </th>
<td><input name=”control” type=”radio” value=”CNC” checked>
CNC
<input name=”control” type=”radio” value=”Manual”>
Manual
<input name=”control” type=”radio” value=”Other”>
Other</td>
</tr>
<tr>
<th valign=”baseline”><label for=”state”><font color=”#FF0000″>*</font> Year of Manufacture </label></th>
<td><input name=”mdate” type=”text” maxlength=”4″>
&nbsp;&nbsp;(YYYY)</td>
</tr>
<tr>
<th valign=”baseline”><font color=”#FF0000″>*</font> Product Image</th>
<td valign=”baseline”><input type=”file” name=”photo” /></td>
</tr>
</table>
</fieldset>
<p></p>
<div id=”buttons” class=”contact_form” align=”right”>
<div align=”center”>
<input name=”reset” type=”reset” id=”reset” value=”Reset” />
<input name=”submit” type=”submit” id=”submit” value=”Submit” />
</div>
</div>
<input type=”hidden” value=”add” name=”add”>
</form>[/CODE]

Page 2 receives the submitted info including an image, creates a resized image file stores it and a thumbnail image on the server and then submits the info posted plus the filename of the image all into a database table

[CODE]$chkeditorial=mysql_query(“select MAX(product_id) as lastid from cms_product”);
$row1=mysql_fetch_array($chkeditorial);
$lastid=$row1[‘lastid’]+1;

$uploads_dir = $_SERVER[‘DOCUMENT_ROOT’].’/product/’;
$thumbs_dir = $_SERVER[‘DOCUMENT_ROOT’].’/product/thumbs/’;
$fieldname = ‘photo’;
//added specify max size
$upload_size = 400; #pixels
$thumb_size = 190; # pixels
//end added specify max size

//Added for size checking
if ($_FILES[$fieldname][‘tmp_name’]) {
$sizes = getimagesize($_FILES[$fieldname][‘tmp_name’]);
$aspect_ratio = $sizes[1]/$sizes[0];
if ($sizes[0] <= $upload_size)
{
$upload_size = $sizes[0];
}
//end added for size checking
$now = time();
$now2 = time()*2;
while(file_exists($filename = $now.’_product_’.$now2.$_FILES[$fieldname][‘name’].”.jpg”))
{
$now++;
}
$filename = $now.’_product_’.$now2.$_FILES[$fieldname][‘name’].”.jpg”;
//added resize file and save
$thumb = ‘thumb_’.$filename;
ResizeConserveAspectRatio($_FILES[$fieldname][‘tmp_name’], $uploads_dir.$filename, $upload_size);
ResizeConserveAspectRatio($_FILES[$fieldname][‘tmp_name’], $thumbs_dir.$thumb, $thumb_size);
//end added resize file and save

}

$catid = $_POST[‘catid’];
$modelnames = $_POST[‘makemodel’];
$prices = $_POST[‘prices’];
$proddes = $_POST[‘desc’];
$capacity = $_POST[‘capacity’];
$control = $_POST[‘control’];
$mdate = $_POST[‘mdate’];

$enddate=time()+60*60*24*30;
$query= “INSERT INTO cms_product (category_id,model_names,prices,product_description,capacity,control,manufacturing_date,email,product_image,status,enddate) VALUES ($catname,’$modelnames’,’$prices’,’$proddes’,’$capacity’,’$control’,$mdate,’$emailmain’,’$filename’,’active’,$enddate)”;
$sql=mysql_query($query);

function ResizeConserveAspectRatio($source, $destination = NULL, $long_dimension = 100)
{
$w = $long_dimension;
$h = $long_dimension;
$source = @imagecreatefromstring(
@file_get_contents($source))
or die(‘Not a valid image format.’);
$x = imagesx($source);
$y = imagesy($source);
if($w && ($x < $y)) $w = round(($h / $y) * $x); // maintain aspect ratio
else $h = round(($w / $x) * $y); // maintain aspect ratio
$slate = @imagecreatetruecolor($w, $h) or die(‘Invalid image dimmensions’);
imagecopyresampled($slate, $source, 0, 0, 0, 0, $w, $h, $x, $y);
if(!$destination) header(‘Content-type: image/jpeg’);
@imagejpeg($slate, $destination, 100) or die(‘Directory permission problem’);
imagedestroy($slate);
imagedestroy($source);
if(!$destination) exit; // return details about the thumbnail
return array($w,$h,’width=”‘.$w.'” height=”‘.$h.'”‘,’mime’=>’image/jpeg’);
}[/CODE]

I get no images created and no info inserted into the DB

Where am i going wrong, ive used this code similarly before but this time i must have missed somethign or messed something up some how

Any advice, i been working on it for hours and im on a tight deadline

Forgive the fact that the code may be un tidy as im fixing someone elses bodge up job

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @BWWebDesigns spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...