Jump to content

nelquintin

Members
  • Posts

    46
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

nelquintin's Achievements

Member

Member (2/5)

0

Reputation

  1. I can get files to upload to folder and add a new row for each in to a mysql db using the code below, how do I get all the filles in one row with multiple uploads //Check if the form was submitted. if(isset($_POST['uploadButton'])) { //Specify folder path where the file is going. $path = 'uploads/'; //Upload file one by one. foreach($_FILES['file']['name'] as $key => $val) { if($val != '') { $file_name = $_FILES['file']['name'][$key]; //Get file name. $file_tmp = $_FILES['file']['tmp_name'][$key]; //Get temporary file name. $file = $path . $file_name; mysql_query("INSERT INTO images (img1) VALUES('$file');") or trigger_error('Unable to INsert: ' . mysql_error()); //Move uploaded file if(move_uploaded_file($file_tmp, $file)) { echo 'File was succesfully uploaded to: ' . $file . '<br />'; } else { //Display error message if there was a problem uploading file. echo 'Error uploading file "' . $key . '."<br />'; } echo $target_path; } } } ?>
  2. sorry to be stupid if i put it in double quotes i get a parse error how do i escape?
  3. How can i display a array in a form? in the example below if i print "$path1"; it show the path. how do i insert this path in to the form? print '<form method="post" action="test2.php"> <input type="text" name="$path1"/><br/><br/> <input type="text" name="$path2"/><br/><br/> <input type="text" name="$path3"/><br/><br/> <input type="submit" name="submit"/> </form> '; print "$path1";
  4. ive tried this now? any ideas please <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="test.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td><strong>Property Upload </strong></td> </tr> <tr> <td> Price: <input name="price" type="text" id="price"></td> </tr> <tr> <td>Description: <input name="description" type="text" id="description"></td> </tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="submit" value="sumbit" /></td> </tr> </table> </td> </form> </tr> </table> <?php // Get the PHP file containing the DbConnector class require_once('../includes/DbConnector.php'); require_once('../includes/Validator.php'); // Create an instance of DbConnector $connector = new DbConnector(); // Check whether a form has been submitted. If so, carry on if ($_POST){ // Validate the entries $validator = new Validator(); $validator->validateTextOnly($_POST['price'],'Price'); $validator->validateTextOnly($_POST['description'],'Description'); //set where you want to store files //in this example we keep file in folder upload //$_FILES['ufile']['name']; = upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif $path1= "images/".$_FILES['ufile']['name'][0]; $path2= "images/".$_FILES['ufile']['name'][1]; $path3= "images/".$_FILES['ufile']['name'][2]; //copy file to where you want to store file copy($_FILES['ufile']['tmp_name'][0], $path1); copy($_FILES['ufile']['tmp_name'][1], $path2); copy($_FILES['ufile']['tmp_name'][2], $path3); // Check whether the validator found any problems if ( $validator->foundErrors() ){ echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each }else{ // Create an SQL query (MySQL version) // The 'addslashes' command is used 5 lines below for added security // Remember to use 'stripslashes' later to remove them (they are inserted in front of any // special characters //"SELECT * FROM `properties` WHERE `id` = '1'" $insertQuery = "INSERT INTO `properties` (`price`, `description`, `path1`, `path2`, `path3`) VALUES ('{$_POST['price']}' , '{$_POST['description']}' , '{$_POST['path1']}' , '{$_POST['path2']}' , '{$_POST['path3']}' ,)"; // Save the form data into the database if ($result = $connector->query($insertQuery)){ // It worked, give confirmation echo '<center><b>Property added to the database</b></center><br>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! exit('<center>Sorry, there was an error saving to the database</center>'); } } } ?> </body> </html>
  5. I have a upload script that save images in an image folder. What I would like to do is pass the path in to another php page and then insert the image path into the database so as to link text and images together. below is the code... <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="upload.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td><strong>Images Upload </strong></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="submit" value="sumbit" /></td> </tr> </table> </td> </form> </tr> </table> <?php //set where you want to store files //in this example we keep file in folder upload //$_FILES['ufile']['name']; = upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif $path1= "images/".$_FILES['ufile']['name'][0]; $path2= "images/".$_FILES['ufile']['name'][1]; $path3= "images/".$_FILES['ufile']['name'][2]; //copy file to where you want to store file copy($_FILES['ufile']['tmp_name'][0], $path1); copy($_FILES['ufile']['tmp_name'][1], $path2); copy($_FILES['ufile']['tmp_name'][2], $path3); //$_FILES['ufile']['name'] = file name //$_FILES['ufile']['size'] = file size //$_FILES['ufile']['type'] = type of file echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>"; echo "<img src=\"$path1\" width=\"150\" height=\"150\">"; echo "<P>"; echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>"; echo "<img src=\"$path2\" width=\"150\" height=\"150\">"; echo "<P>"; echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>"; echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>"; echo "<img src=\"$path3\" width=\"150\" height=\"150\">"; /////////////////////////////////////////////////////// // Use this code to display the error or success. $filesize1=$_FILES['ufile']['size'][0]; $filesize2=$_FILES['ufile']['size'][1]; $filesize3=$_FILES['ufile']['size'][2]; if($filesize1 && $filesize2 && $filesize3 != 0) { echo "Uploaded"; } else { echo "ERROR....."; } ////////////////////////////////////////////// // What files that have a problem? (if found) if($filesize1==0) { echo "There're something error in your first file"; echo "<BR />"; } if($filesize2==0) { echo "There're something error in your second file"; echo "<BR />"; } if($filesize3==0) { echo "There're something error in your third file"; echo "<BR />"; } ?> <html> <head> <title>Add an Property</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <?php // Get the PHP file containing the DbConnector class require_once('../includes/DbConnector.php'); require_once('../includes/Validator.php'); // Create an instance of DbConnector $connector = new DbConnector(); // Check whether a form has been submitted. If so, carry on if ($_POST){ // Validate the entries $validator = new Validator(); $validator->validateTextOnly($_POST['price'],'Price'); $validator->validateTextOnly($_POST['description'],'Description'); // Check whether the validator found any problems if ( $validator->foundErrors() ){ echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each }else{ // Create an SQL query (MySQL version) // The 'addslashes' command is used 5 lines below for added security // Remember to use 'stripslashes' later to remove them (they are inserted in front of any // special characters //"SELECT * FROM `properties` WHERE `id` = '1'" $insertQuery = "INSERT INTO `properties` (`price`, `description`, `imagepath`) VALUES ('{$_POST['price']}' , '{$_POST['description']}' , '{$_POST['imagepath']}')"; // Save the form data into the database if ($result = $connector->query($insertQuery)){ // It worked, give confirmation echo '<center><b>Property added to the database</b></center><br>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! exit('<center>Sorry, there was an error saving to the database</center>'); } } } ?> <body> <form name="form1" method="post" action="newproperty.php"> <p> Price: <input name="price" type="text" id="price"> </p> <p> Description: <input name="description" type="text" id="description"> </p> <a href="upload.php">Add pictures</a> </p> <p align="center"> <input type="submit" name="Submit" value="Submit"> </p> </form> </body> </html>
  6. here is all the code including mysql_query and yes i can echo the varibles. <?php require_once('includes/config.php'); ?> <?php include('includes/sc-includes.php'); $pagetitle = Property; $update = 0; if (isset($_GET['property_id'])) { $update = 1; } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } // if ($update==1) { mysql_select_db($database_contacts, $contacts); $query_property = "SELECT * FROM property WHERE property_id = ".$_GET['property_id'].""; $contacts = mysql_query($query_property, $contacts) or die(mysql_error()); $row_property = mysql_fetch_assoc($contacts); $totalRows_property = mysql_num_rows($contacts); } // //UPLOAD PICTURE $picture = $_POST['image_location']; $time = substr(time(),0,5); if($HTTP_POST_FILES['image'] && $HTTP_POST_FILES['image']['size'] > 0){ $ori_name = $_FILES['image']['name']; $ori_name = $time.$ori_name; $tmp_name = $_FILES['image']['tmp_name']; $src = imagecreatefromjpeg($tmp_name); list($width,$height)=getimagesize($tmp_name); $newwidth=95; $newheight=($height/$width)*95; $tmp=imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); $filename = "images/". $ori_name; imagejpeg($tmp,$filename,100); $picture = $ori_name; imagedestroy($src); imagedestroy($tmp); } //END UPLOAD PICTURE if ($update==0) { if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO property(property_image, property_type, property_price, property_area, property_ref, property_header, property_option, property_info, property_status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($picture, "text"), GetSQLValueString(trim($_POST['property_type']), "text"), GetSQLValueString(trim($_POST['property_price']), "text"), GetSQLValueString(trim($_POST['property_area']), "text"), GetSQLValueString(trim($_POST['property_ref']), "text"), GetSQLValueString(trim($_POST['property_header']), "text"), GetSQLValueString(trim($_POST['property_option']), "text"), GetSQLValueString(trim($_POST['property_info']), "text"), GetSQLValueString($_POST['property_status'], "text")); mysql_select_db($database_contacts, $contacts); $Result1 = mysql_query($insertSQL, $contacts) or die(mysql_error()); set_msg('Property Added'); $cid = mysql_insert_id(); $redirect = "property-details.php?id=$cid"; header(sprintf('Location: %s', $redirect)); die; } } if ($update==1) { if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE property SET property_type=%s, property_price=%s, property_area=%s, property_ref=%s, property_header=%s, property_option=%s, property_info=%s, property_status=%s WHERE property_id= %s", GetSQLValueString($picture, "text"), GetSQLValueString(trim($_POST['property_type']), "text"), GetSQLValueString(trim($_POST['property_price']), "text"), GetSQLValueString(trim($_POST['property_area']), "text"), GetSQLValueString(trim($_POST['property_ref']), "text"), GetSQLValueString(trim($_POST['property_header']), "text"), GetSQLValueString(trim($_POST['property_option']), "text"), GetSQLValueString(trim($_POST['property_info']), "text"), GetSQLValueString(trim($_POST['property_status']), "text"), GetSQLValueString(trim($_POST['property_id']), "int")); $contacts = mysql_connect($hostname_contacts, $username_contacts, $password_contacts) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($database_contacts, $contacts)or trigger_error(mysql_error(),E_USER_ERROR); $Result1 = mysql_query($updateSQL, $contacts) or die(mysql_error()); set_msg('Property Updated'); $cid = $_GET['property_id']; $redirect = "properties.php?id=$cid"; header(sprintf('Location: %s', $redirect)); die; } } ?> <!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><?php if ($update==0) { echo "Add Property"; } ?><?php echo $row_property['property_ref']; ?> <?php echo $row_address['property_address']; ?></title> <script src="includes/lib/prototype.js" type="text/javascript"></script> <script src="includes/src/effects.js" type="text/javascript"></script> <script src="includes/validation.js" type="text/javascript"></script> <script src="includes/src/scriptaculous.js" type="text/javascript"></script> <script language="javascript"> function toggleLayer(whichLayer) { if (document.getElementById) { // this is the way the standards work var style2 = document.getElementById(whichLayer).style; style2.display = style2.display? "":"block"; } else if (document.all) { // this is the way old msie versions work var style2 = document.all[whichLayer].style; style2.display = style2.display? "":"block"; } else if (document.layers) { // this is the way nn4 works var style2 = document.layers[whichLayer].style; style2.display = style2.display? "":"block"; } } </script> <link href="includes/style.css" rel="stylesheet" type="text/css" /> <link href="includes/simplecustomer.css" rel="stylesheet" type="text/css" /> </head> <body> <?php include('includes/header.php'); ?> <div class="container"> <div class="leftcolumn"> <h2><?php if ($update==1) { echo Update; } else { echo Add; } ?> Property </h2> <p> </p> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Image<br /> <input name="image" type="file" id="image" /><?php if ($row_property['property_image']) { ?> <br /> <img src="images/<?php echo $row_property['property_image']; ?>" width="95" /> <?php } ?> </td> </tr> <td>Price<br /> <input name="property_price" type="text" id="property_price" value="<?php echo $row_property['property_price']; ?>" size="35" /></td> </tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="39%">Property option<br /> <select name="property_option" id="property_option" value="<?php echo $row_property['property_option']; ?>" size="1" /> <option selected="selected">Select</option> <option value="Sale">For Sale</option> <option value="Rent">To Let</option> </select> <td width="34%">Type of property<br /> <select name="property_type" id="property_type" value="<?php echo $row_property['property_type']; ?>" size="1" /> <option selected="selected">Select</option> <option value="Residential">Residential</option> <option value="Commercial">Commercial</option> <option value="Land">Land</option> </select> </tr> </table></td> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="39%">Area<br /> <select name="property_area" id="property_area" value="<?php echo $row_property['property_area']; ?>" size="1" /> <option selected="selected">Select</option> <option value="Brackenfell">Brackenfell</option> <option value="Blouberg surround">Blouberg surround</option> <option value="Cape Town CBD">Cape Town CBD</option> <option value="Durbanville">Durbanville</option> <option value="Goodwood">Goodwood</option> <option value="Killarney Gardens">Killarney Gardens</option> <option value="Maitland">Maitland</option> <option value="Montague Gardens">Montague Gardens</option> <option value="Ndabeni">Ndabeni</option> <option value="Paarden Eiland">Paarden Eiland</option> <option value="Paarl">Paarl</option> <option value="Racing Park">Racing Park</option> <option value="Sommerset West">Sommerset West</option> <option value="Stellenbosch">Stellenbosch</option> <option value="Tygerberg">Tygerberg</option> </select> <td width="34%">Reference<br /> <input name="property_ref" type="text" id="property_ref" value="<?php echo $row_property['property_ref']?>" size="10" /></td> </tr> </table></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100%">Header<br /> <input name="property_header" type="text" id="property_header" value="<?php echo $row_property['property_header'];?>" size="50" /></td> </tr> </table></td> </tr> <tr> <td>Additional Infomation<br /> <textarea name="property_info" cols="60" rows="3" id="property_info"><?php echo $row_property['property_info'];?></textarea></td> </tr> <tr> <td>Status<br /> <select name="property_status" id="property_status" value="<?php echo $row_property['property_status']; ?>" size="1" /> <option selected="selected">Select</option> <option value="Online">Online</option> <option value="Offline">Offline</option> </select> </tr> </table> <p> </p></td> </tr> <tr> <td colspan="2"><p> <input type="submit" name="Submit2" value="<?php if ($update==1) { echo Update; } else { echo Add; } ?> property" /> <input type="hidden" name="MM_insert" value="form1" /> <input name="property_id" type="hidden" id="property_id" value="<?php echo $row_property['property_id']; ?>" /> <input name="image_location" type="hidden" id="image_location" value="<?php echo $row_property['property_image']; ?>" /> </p></td> </tr> </table> <p> </p> <input type="hidden" name="MM_update" value="form1"> </form> </div> <?php include('includes/right-column.php'); ?> <br clear="all" /> </div> <?php include('includes/footer.php'); ?> </body> </html>
  7. this wont update and there no error messages. please help. if ($update==1) { if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE property SET property_type=%s, property_price=%s, property_area=%s, property_ref=%s, property_header=%s, property_option=%s, property_info=%s, property_status=%s WHERE property_id= %s", GetSQLValueString($picture, "text"), GetSQLValueString(trim($_POST['property_type']), "text"), GetSQLValueString(trim($_POST['property_price']), "text"), GetSQLValueString(trim($_POST['property_area']), "text"), GetSQLValueString(trim($_POST['property_ref']), "text"), GetSQLValueString(trim($_POST['property_header']), "text"), GetSQLValueString(trim($_POST['property_option']), "text"), GetSQLValueString(trim($_POST['property_info']), "text"), GetSQLValueString(trim($_POST['property_status']), "text"), GetSQLValueString(trim($_POST['property_id']), "int")); $contacts = mysql_connect($hostname_contacts, $username_contacts, $password_contacts) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($database_contacts, $contacts)or trigger_error(mysql_error(),E_USER_ERROR); set_msg('Property Updated'); $cid = $_GET['property_id']; $redirect = "properties.php?id=$cid"; header(sprintf('Location: %s', $redirect)); die; } }
  8. // some code $link= $query = "SELECT * FROM `customers` WHERE `price_min` <= '" . $_POST['price'] . "' AND `price_max` >= '" . $_POST['price'] . "'"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); echo "<table>\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; mysql_free_result($result); mysql_close($link); ?> sql dump: /*!40000 ALTER TABLE `customers` DISABLE KEYS */; INSERT INTO `contacts` (`username`,`price_max`,`price_min`) VALUES ('quintin','100','10'); /*!40000 ALTER TABLE `customers` ENABLE KEYS */; this returns nothing why??
  9. thanks ive tried $query = "SELECT * FROM customers WHERE price_min < '".$_POST['price']."' AND price_max > '".$_POST['price']."'"; this returns nothing
  10. ive tried this $query = "SELECT * FROM customers WHERE '".$_POST['minprice']."' AND '".$_POST['maxprice']."' LIKE '".$_POST['price']."' "; nothing
  11. that code is perfect when i am matching customer to the product. what i would like to do is match the product to the client. so for example if a book cost $20 i want to pull all the customer that have $20 in their price range.
  12. i use this line to match customer with product $query = "SELECT * FROM product WHERE price BETWEEN '".$_POST['minprice']."' AND '".$_POST['maxprice']."'"; $result = mysql_query($query); how can i match the product with customer? Bearing in mind the customer has a min range and a max range and product a set price.
  13. why wont this update the database? <? include("include/session.php"); ?> <? $propertyid=$_GET['propertyid']; $query=" SELECT * FROM propertys WHERE propertyid='$propertyid'"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $picture=mysql_result($result,$i,"picture"); $price=mysql_result($result,$i,"price"); .... $username=mysql_result($result,$i,"username"); ?> <form action="propertys_change_record.php" method="post"> <input type="hidden" name="ud_propertyid" value="<? echo "$propertyid" ?>"><br> Image:<br> <input type="File" name="ud_picture" size="<? print "$picture"?>"><br> Price:<br> <input type="text" name="ud_price" value="<? print "$price"?>"><br> ....... Username:<br> <input type="text" name="ud_username" value="<? print "$username"?>"></br> <br><input type="Submit" value="Update"> </form> <? ++$i; } ?> and... <? include("include/session.php"); ?> <?php $ud_propertyid=$_POST['ud_propertyid']; $ud_picture=$_POST['ud_picture']; ... $ud_username=$_POST['ud_username']; mysql_query(" UPDATE propertys SET picture='$ud_picture' ,price='$ud_price' ,ref='$ud_ref' ,type='$ud_type' ,erf='$ud_erf' ,description='$ud_description' ,bed='$ud_bed' ,bath='$ud_bath' ,gar='$ud_gar' ,username='$ud_username' WHERE propertyid='$ud_propertyid'"); echo "Record Updated"; ?> <br> <a href="main.php">Back to main page</a> </body> </html> <? ++$i; ?>
×
×
  • 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.