alexmark Posted July 16, 2012 Share Posted July 16, 2012 Hi all Ok I have a simple problem! lol as if tehre was such a thing. When I run teh form below it will not bring the make and year and model from the db. I have looked and tried just about everything apart from teh correct solution. If anyone could throw a light on this I would be so happy. <?php if ( $_SESSION['logged_in'] ): ?> (1) <?php endif; ?> <?php if($_POST['formSubmit'] == "Submit") { $errorMessage = ""; //echo "<PRE>";print_r($_POST['features']); if(empty($_POST['formmake'])) { $errorMessage .= "<li>You forgot to Select a Make!</li>"; } if(empty($_POST['formmodel'])) { $errorMessage .= "<li>You forgot to select a Model!</li>"; } if(empty($_POST['formvehicle_type'])) { $errorMessage .= "<li>You forgot to enter a Body Type!</li>"; } if(empty($_POST['formdoors'])) { $errorMessage .= "<li>You forgot to enter Doors!</li>"; } if(empty($_POST['formcolor'])) { $errorMessage .= "<li>You forgot to enter Color!</li>"; } if(empty($_POST['formmileage'])) { $errorMessage .= "<li>You forgot to enter Mileage!</li>"; } if(empty($_POST['formyear'])) { $errorMessage .= "<li>You forgot to enter Year!</li>"; } if(empty($_POST['formlisting_condition'])) { $errorMessage .= "<li>You forgot to enter Condition!</li>"; } if(empty($_POST['formengine'])) { $errorMessage .= "<li>You forgot to enter Engine!</li>"; } if(empty($_POST['formtrans'])) { $errorMessage .= "<li>You forgot to enter a Transmission Type!</li>"; } if(empty($_POST['formdrive_train'])) { $errorMessage .= "<li>You forgot to enter a Drive Train!</li>"; } if(empty($_POST['formmpg'])) { $errorMessage .= "<li>You forgot to enter the Miles Per Gallon!</li>"; } if(empty($_POST['formfuel_type'])) { $errorMessage .= "<li>You forgot to select a Fule Type!</li>"; } if(empty($_POST['formprice'])) { $errorMessage .= "<li>You forgot to enter a Price!</li>"; } if(empty($_POST['formadddesc'])) { $errorMessage .= "<li>You forgot to enter a Description!</li>"; } if(empty($_POST['features'])) { $errorMessage .= "<li>You forgot to select any Features!</li>"; } if(empty($_POST['formvin'])) { $errorMessage .= "<li>You forgot to enter a Vin Number!</li>"; } if(empty($_POST['formstock'])) { $errorMessage .= "<li>You forgot to enter a Stock Number!</li>"; } $varmake = $_POST['formmake']; $varmodel = $_POST['formmodel']; $varvehicle_type = $_POST['formvehicle_type']; $vardoors = $_POST['formdoors']; $varcolor = $_POST['formcolor']; $varmileage = $_POST['formmileage']; $varyear = $_POST['formyear']; $varlisting_condition = $_POST['formlisting_condition']; $varengine = $_POST['formengine']; $vartrans = $_POST['formtrans']; $vardrive_train = $_POST['formdrive_train']; $varmpg = $_POST['formmpg']; $varfuel_type = $_POST['formfuel_type']; $varprice = $_POST['formprice']; $varadddesc = $_POST['formadddesc']; $varfeatures = $_POST['features']; $varvin = $_POST['formvin']; $varstock = $_POST['formstock']; $hitcount = 0; $sold = 0; $added_on = date('Y-m-d H:i:s'); if(empty($errorMessage)) { include 'config.php'; $sql = "INSERT INTO listing (make, model, vehicle_type, doors,color, mileage, year, listing_condition, engine, trans, drive_train, mpg, fuel_type, price, adddesc, features, vin, stock, hitcount, sold, added_on, carofweek, featured) VALUES (". PrepSQL($varmake) . ", " . PrepSQL($varmodel) . ", " . PrepSQL($varvehicle_type) . ", " . PrepSQL($vardoors) . ", " . PrepSQL($varcolor) . ", " . PrepSQL($varmileage) . ", " . PrepSQL($varyear) . ", " . PrepSQL($varlisting_condition) . ", " . PrepSQL($varengine) . ", " . PrepSQL($vartrans) . ", " . PrepSQL($vardrive_train) . ", " . PrepSQL($varmpg) . ", " . PrepSQL($varfuel_type) . ", " . PrepSQL($varprice) . ", " . PrepSQL($varadddesc) . ", " . PrepSQL(serialize($varfeatures)) . ", " . PrepSQL($varvin) . ", " . PrepSQL($varstock) . ", " . PrepSQL($varcarofweek) . ", " . PrepSQL($varfeatured) . ", " . PrepSQL($hitcount) . ", " . PrepSQL($sold) . ", " . PrepSQL($added_on) . ")"; if(mysql_query($sql)){ $listingId = mysql_insert_id(); include '../../includes/imageresizer.class.php'; include '../../includes/upload_class.php'; $imagePath = '/admin/uploaded_photos/'; $thumbPath = '/admin/thumbnails/'; for($i==0; $i<10; $i++){ if(!empty($_FILES['formImage'.$i]['tmp_name'])){ if(!is_dir($imagePath.'/')){ mkdir($imagePath.'/', 0777); } // Generate Thumbnails if(!is_dir($thumbPath.'/')){ mkdir($thumbPath.'/', 0777); } $UF_obj = new Upload(); $UF_obj -> File = $_FILES['formImage'.$i]; $UF_obj -> SavePath = $imagePath.'/'; // PLACE where you want to save images. $UF_obj -> ThumbPath = $thumbPath.'/'; //if not specify will not create thumbnil $UF_obj -> NewName = $_FILES['formImage'.$i]['name']; //width and height of large image which will save in "pictures/" folder $UF_obj -> NewWidth = 800; $UF_obj -> NewHeight = 600; ////width and height of thumb image which will save in "pictures/thumb/" folder $UF_obj -> TWidth = 100; $UF_obj -> THeight = 100; /* * if you want to name image something other then upload image name then use bellow formate * for example you upload two images then * * $UF_obj -> NewName = array('NewName1.jpg', 'NewName2.jpg'); */ $UF_obj -> NameCase = 'lower'; //default no change. upper for upper case $UF_obj -> OverWrite = true; //default = true. replace existing image //UploadFile() function upload and resize image. //function return error message if any. //error variable is in array form. so you can get more then one error/warning messages. // or you can also access error message by class object varialbe like $UF_obj -> Error $Error = $UF_obj -> UploadFile(); // INSERT images to DB if(count($Error)<=0){ $imageInsert = "INSERT INTO listimages (imagepath, imagethumbpath, mainimage, listingid)Values ('".$imagePath."/".$_FILES['formImage'.$i]['name']."','".$thumbPath."/".$_FILES['formImage'.$i]['name']."','0','".$listingId."')"; mysql_query($imageInsert); }else{ if(is_array($Error)){ foreach($Error as $key=>$val) { echo $val . '<br>'; } } } } } echo("<ul style='color:green;'>Your Listing is Successfully Listed!</ul>\n"); } } } // function: PrepSQL() // use stripslashes and mysql_real_escape_string PHP functions // to sanitize a string for use in an SQL query // // also puts single quotes around the string // function PrepSQL($value) { // Stripslashes if(get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote $value = "'" . mysql_real_escape_string($value) . "'"; return($value); } ?> <script src="../../js/jquery-1.4.2.min.js" type="text/javascript"></script> <script src="../../js/jquery-validation/jquery.validate.js"></script> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Admin Add Vehicle</title> <link href="/csssheet.css" rel="stylesheet" type="text/css"> </head> <body> <center><div style="width:785px"> <table td class="background1" valign="top" width="785px" colspan="1" border=0 cellpadding=0 cellspacing=0 align="center"> <tr> <td width="100%"><center><br><a href= "../admin.php" class="creamlink11">Log Out</a></center></td> </tr> <td></td> </table> <?php include("../menu/admin_menu.php") ?> </td> </tr> <tr> <td bgcolor="#F6F6F6" height='1'></td> </tr> <tr> <td > <table width="785" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="785" bgcolor="#232B34" class="bodyfontred"> <table border=0 width='100%' cellspacing=0 cellpadding=0> <tr> <td valign="top" align=center> </td> </tr> <tr> <td align=center> <center> <img src="/images/linebreak.jpg" width="350" height="1"> </center> <?php if(!empty($errorMessage)) { echo("<p>There was an error with your form:</p>\n"); echo("<ul>" . $errorMessage . "</ul>\n"); } ?> <script type="text/javascript"> $().ready(function() { // validate signup form on keyup and submit $("#listing-form").validate({ rules: { formmake: "required", formmodel: "required", formvehicle_type: "required", formdoors: "required", formcolor: "required", formmileage: "required", formyear: "required", formlisting_condition: "required", formengine: "required", formtrans: "required", formdrive_train: "required", formmpg: "required", formfuel_type: "required", formprice: "required", formadddesc: "required", features: "required", formvin: "required", formstock: "required" }, messages: { formmake: "You forgot to Select a Make!", formmodel: "You forgot to Enter a Model!", formvehicle_type: "You forgot to Enter a Body Type!", formdoors: "You forgot to Enter Doors!", formcolor: "You forgot to Enter Color!", formmileage: "You forgot to Enter Mileage!", formyear: "You forgot to Select Year!", formlisting_condition: "You forgot to Select Condition!", formengine: "You forgot to Enter Engine!", formtrans: "You forgot to Select Transmission Type!", formdrive_train: "You forgot to Select a Drive Train!", formmpg: "You forgot to Enter a Mileage Per Gallon!", formfuel_type: "You forgot to Select a Fuel Type!", formprice: "You forgot to Enter a Price!", formadddesc: "You forgot to Enter a Description!", features: "You forgot to Select a Features!", formvin: "You forgot to Enter a Vin Number!", formstock: "You forgot to Enter a Stock Number!" } }); }); </script> <form id="listing-form" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post" enctype="multipart/form-data"> <table align="center"> <tr> <td class="bodyfontwhite" width="199" align="right" label for='formad_title'> </td> <td width="556"> </td> </tr> <tr> <td align="right" label for='formad_title'><div align="left"><strong>Vehicle Details:</strong></div></td> <td> </td> </tr> <tr> <td align="right" label for='formad_title'> </td> <td> </td> </tr> <tr> <td align="right" label for='formvin'>Vin Number: </td> <td><input name="formvin" type="text" value="<?php echo $varvin;?>" size="20" maxlength="100" /></td> </tr> <tr> <td align="right" label for='formstock'>Stock Number: </td> <td><input name="formstock" type="text" value="<?php echo $varstock;?>" size="20" maxlength="100" /></td> </tr> <tr> <td align="right" label for='formmake'>Make: </td> <td><select name="formmake" id="formmake" onchange="return populateModel(this.value);"> <?php $sql="SELECT id,manufacturer FROM manufacturer"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="<?php echo $data['id'] ?>" ><?php echo $data['manufacturer'] ?></option> <?php } ?> </select> </td> </tr> <tr> <td align="right" label for='formyear'>Year: </td> <td><select name="formyear"> <?php $sql="SELECT id,year FROM year"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="<?php echo $data['id'] ?>" ><?php echo $data['year'] ?></option> <?php } ?> </select></td> </tr> <tr> <td align="right" label for='formmodel'>Model: </td> <td> <select name="formmodel" id="formmodel"> <?php $sql="SELECT id,model FROM model WHERE year_id='1'"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="<?php echo $data['id'] ?>" ><?php echo $data['model'] ?></option> <?php } ?> </select> <!--<input name="formmodel" type="text" value="<?php echo $varmodel;?>" size="60" maxlength="100" />--> </td> </tr> <tr> <td align="right" label for='formvehicle_type'>Body Style: </label></td> <td> <select name="formvehicle_type"> <?php $sql="SELECT id,vehicle_type FROM vehicle_type"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="<?php echo $data['id'] ?>" ><?php echo $data['vehicle_type'] ?></option> <?php } ?> </select> </td> </tr> <tr> <td align="right" label for='formdoors'>Number of Doors: </td> <td><select name="formdoors"> <option value="0">Select Option</option> <option value="1"<?php if($vardoors=="1") echo(" selected=\"selected\"");?>>2 Door</option> <option value="2"<?php if($vardoors=="2") echo(" selected=\"selected\"");?>>4 Door</option> <option value="3"<?php if($vardoors=="3") echo(" selected=\"selected\"");?>>3 Door Hatchback</option> <option value="4"<?php if($vardoors=="4") echo(" selected=\"selected\"");?>>5 Door Hatchback</option> <option value="5"<?php if($vardoors=="5") echo(" selected=\"selected\"");?>>Other</option> </select></td> </tr> <tr> <td align="right" label for='formcolor'>Color: </td> <td><input name="formcolor" type="text" value="<?php echo $varcolor;?>" size="25" maxlength="60" /></td> </tr> <tr> <td align="right" label for='formmileage'>Mileage: </td> <td><input name="formmileage" type="text" value="<?php echo $varmileage;?>" size="25" maxlength="20" /></td> </tr> <tr> <td align="right" label for='formlisting_condition'>Condition: </td> <td><select name="formlisting_condition"> <option value="0">Select Option</option> <option value="1"<?php if($varlisting_condition=="1") echo(" selected=\"selected\"");?>>New</option> <option value="2"<?php if($varlisting_condition=="2") echo(" selected=\"selected\"");?>>Used</option> <option value="3"<?php if($varlisting_condition=="3") echo(" selected=\"selected\"");?>>Used with Warranty</option> <option value="4"<?php if($varlisting_condition=="4") echo(" selected=\"selected\"");?>>As is</option> <option value="5"<?php if($varlisting_condition=="5") echo(" selected=\"selected\"");?>>Other</option> </select></td> </tr> <tr> <td align="right" label for='formengine'>Engine: </td> <td><input name="formengine" type="text" value="<?php echo $varengine;?>" size="60" maxlength="100" /></td> </tr> <tr> <td align="right" label for='formtrans'>Transmission: </td> <td><select name="formtrans"> <option value="0">Select Option</option> <option value="1"<?php if($vartrans=="1") echo(" selected=\"selected\"");?>>Manual</option> <option value="2"<?php if($vartrans=="2") echo(" selected=\"selected\"");?>>Automatic</option> </select></td> </tr> <tr> <td align="right" label for='formdrive_train'>Drive Train: </td> <td><select name="formdrive_train"> <?php $sql="SELECT id,drive_train FROM drive_train"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="<?php echo $data['id'] ?>" ><?php echo $data['drive_train'] ?></option> <?php } ?> </select></td> </tr> <tr> <td align="right" label for='formmpg'>Miles Per Gallon: </td> <td><input name="formmpg" type="text" value="<?php echo $varmpg;?>" size="20" maxlength="100" /></td> </tr> <tr> <td align="right" label for='formfuel_type'>Fuel Type: </td> <td><select name="formfuel_type"> <option value="0">Select Option</option> <option value="1"<?php if($varfuel_type=="1") echo(" selected=\"selected\"");?>>Gasoline</option> <option value="2"<?php if($varfuel_type=="2") echo(" selected=\"selected\"");?>>Diesel</option> <option value="3"<?php if($varfuel_type=="3") echo(" selected=\"selected\"");?>>Hybrid</option> <option value="4"<?php if($varfuel_type=="4") echo(" selected=\"selected\"");?>>FleX-Fuel</option> <option value="5"<?php if($varfuel_type=="5") echo(" selected=\"selected\"");?>>Electric</option> </select></td> </tr> <tr> <td align="right" label for='formprice'>Price: </td> <td><input name="formprice" type="text" value="<?php echo $varprice;?>" size="20" maxlength="100" /></td> </tr> <tr> <td align="right" label for='formadddesc'>Description: </td> <td><textarea name="formadddesc" rows="10" cols="80" ><?php echo $varadddesc;?> </textarea></td> </tr> <tr> <td align="right" label for='formcarofweek'>Car of The Week: </td> <td><input type="checkbox" name="carofweek" value="1" <?php if($_POST['carofweek'][0] == '1') {echo 'checked="checked"';} ?> /></td> </tr> <tr> <td align="right" label for='formfeatured'>Featured Car: </td> <td><input type="checkbox" name="featured" value="1" <?php if($_POST['featured'][0] == '1') {echo 'checked="checked"';} ?> /></td> </tr> <tr> <td colspan="2" align="right"> </td> </tr> <tr> <td align="right"><div align="left"><strong>Features:</strong></div></td> <td align="right"> </td> </tr> <tr> <td colspan="2" align="right"> </td> </tr> <tr> <td colspan="2" align="right"><table width="100%" border="0"> <tr> <td><input type="checkbox" name="features[]" value="1" id="features_108" <?php if($_POST['features'][0] == '1') { echo 'checked="checked"'; }?> /> Air Bag Front Drive</td> <td><input type="checkbox" name="features[]" value="2" id="features_109" <?php if($_POST['features'][1] == '2') { echo 'checked="checked"'; }?> /> Air Bag Front Passenger</td> <td><input type="checkbox" name="features[]" value="3" id="features_110" <?php if($_POST['features'][2] == '3') { echo 'checked="checked"'; }?> /> THESE ARE MORE FEATURES REMOVED <td><input type="checkbox" name="features[]" value="107" id="features_107" <?php if($_POST['features'][106] == '107') { echo 'checked="checked"'; }?> /> Tachometer</td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> </table></td> </tr> <tr> <td align="right"><div align="left"><strong>Upload Images:</strong></div></td> <td> </td> </tr> <tr> <td align="right" label for='formImage1'> </td> <td> </td> </tr> <tr> <td align="right" label for='formImage1'>Add Image 1: </td> <td><input name="formImage1" type="file" id="formImage1" value="<?=$varImage1;?>"/></td> </tr> <tr> <td align="right" label for='formImage2'>Add Image 2: </td> <td><input name="formImage2" type="file" id="formImage2" value="<?=$varImage2;?>"/></td> </tr> <tr> <td align="right" label for='formImage3'>Add Image 3: </td> <td><input name="formImage3" type="file" id="formImage3" value="<?=$varImage3;?>"/></td> </tr> <tr> <td align="right" label for='formImage4'>Add Image 4: </td> <td><input name="formImage4" type="file" id="formImage4" value="<?=$varImage4;?>"/></td> </tr> <tr> <td align="right" label for='formImage5'>Add Image 5: </td> <td><input name="formImage5" type="file" id="formImage5" value="<?=$varImage5;?>"/></td> </tr> <tr> <td align="right" label for='formImage6'>Add Image 6: </td> <td><input name="formImage6" type="file" id="formImage6" value="<?=$varImage6;?>"/></td> </tr> <tr> <td align="right" label for='formImage7'>Add Image 7: </td> <td><input name="formImage7" type="file" id="formImage7" value="<?=$varImage7;?>"/></td> </tr> <tr> <td align="right" label for='formImage8'>Add Image 8: </td> <td><input name="formImage8" type="file" id="formImage8" value="<?=$varImage8;?>"/></td> </tr> <tr> <td align="right" label for='formImage[]'>Add Image 9: </td> <td><input name="formImage9" type="file" id="formImage9" value="<?=$varImage9;?>"/></td> </tr> <tr> <td align="right" label for='formImage10'>Add Image 10: </td> <td><input name="formImage10" type="file" id="formImage10" value="<?=$varImage10;?>"/></td> </tr> </table> <center><input type="submit" name="formSubmit" value="Submit"/></center> </form> <tr><td class=bodyfontwhite> <center><b><a name='help'></a>H E L P</b></center><br> <p align=justify>Work down the form and enter all information as it is listed. Select the Features of the vehicle by clicking in the check boxes. Once you have finished simply click the submit button. <br></br><br></br> If you wish the vehicle to be car of the week simply click the check box for car of the week. <br></br><br></br> ** REMEMBER** YOU CAN ONLY HAVE ONE CAR OF THE WEEK.** <br></br> </p> </td></tr></table> </td> </tr> </table> </td> </tr> <tr> <center><td width="785" align="center" bgcolor="#000000" class="bodyfont" height="40"><a href="http://www.improvedinternetmarketing.com/" title="Improved Internet Marketing">Web Design</a> by Improved Internet Marketing</TD></center> </tr> </table> </div></center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/265785-can-not-fetch-from-db/ Share on other sites More sharing options...
alexmark Posted July 16, 2012 Author Share Posted July 16, 2012 I missed a comma! lol wow that was crazy Quote Link to comment https://forums.phpfreaks.com/topic/265785-can-not-fetch-from-db/#findComment-1361988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.