0

您好,我知道这个答案在这里的某个地方,但找不到。我是编程新手。我正在尝试使用 php 和 MySql 创建一个用于房地产列表的脚本。在我的表单中,我希望人们将图片与他们的帖子一起上传。我现在的问题是如何将图像表连接到属性表,以便在查看帖子时也会拉出图像。我知道这很简单,但对于像我这样的傻瓜来说并不简单。

我正在使用 Dreamweaver,这是我的表单,包括行为:

<?php require_once('Connections/phpconfig.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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 ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "property")) {
  $insertSQL = sprintf("INSERT INTO property (title, prop_type, prop_region, prop_address, prop_cat, prop_price, prop_beds, prop_baths, prop_total_rooms, prop_living_size, prop_land_size, prop_car_spaces, prop_viability, prop_description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Title'], "text"),
                       GetSQLValueString($_POST['type_of_property'], "text"),
                       GetSQLValueString($_POST['region'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['property_category'], "text"),
                       GetSQLValueString($_POST['price'], "double"),
                       GetSQLValueString($_POST['bedroom'], "int"),
                       GetSQLValueString($_POST['baths'], "int"),
                       GetSQLValueString($_POST['total_rooms'], "int"),
                       GetSQLValueString($_POST['living_area_size'], "int"),
                       GetSQLValueString($_POST['land_area_size'], "int"),
                       GetSQLValueString($_POST['car_space'], "int"),
                       GetSQLValueString($_POST['prop_aviability'], "text"),
                       GetSQLValueString($_POST['description'], "text"));

  mysql_select_db($database_phpconfig, $phpconfig);
  $Result1 = mysql_query($insertSQL, $phpconfig) or die(mysql_error());

  $insertGoTo = "userpanel.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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=utf-8" />
<title>listing</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="property" id="property">
  <table width="400" border="0">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="sprytextfield1">
        <label>Title
          <input type="text" name="Title" id="Title" />
        </label>
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="spryselect1">
        <label for="type_of_property">Type of Property</label>
        <select name="type_of_property" id="type_of_property">
          <option value="">--Select--</option>
          <option value="House">House</option>
          <option value="Land">Land</option>
          <option value="Commercial">Commercial</option>
        </select>
      <span class="selectRequiredMsg">Please select an item.</span></span></td>
      <td>&nbsp;</td>
    </tr>

    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="spryselect2">
        <label for="region">Region</label>
        <select name="region" id="region">
         <option value="">--Select--</option>
              <option value="somecity">somecity</option>
              <option value="city">city</option>

        </select>
      <span class="selectRequiredMsg">Please select an item.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
     <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="sprytextfield2">
        <label for="address">Address</label>
        <input type="text" name="address" id="address" />
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <td><span id="spryselect3">
      <label for="property_category">Property Category</label>
      <select name="property_category" id="property_category">
        <option value="">--Select--</option>
        <option value="For_Rent">For Rent</option>
        <option value="For_Rent">Sale</option>
      </select>
      <span class="selectRequiredMsg">Please select an item.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="sprytextfield3">
        <label for="price">Price</label>
        <input type="text" name="price" id="price" />
      <span class="textfieldRequiredMsg">A value is required.</span></span> <span>$</span></td>
      <td>&nbsp;</td>
    </tr>
     <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="sprytextfield4">
        <label for="bedroom">Bedroom</label>
        <input type="text" name="bedroom" id="bedroom" />
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="baths">
        <label for="baths">Baths</label>
        <input type="text" name="baths" id="baths" />
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="total_rooms">
        <label for="total_rooms">Total Rooms</label>
        <input type="text" name="total_rooms" id="total_rooms" />
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
      <td><span id="sprytextfield7">
        <label for="living_area_size">Living area (m²)</label>
        <input type="text" name="living_area_size" id="living_area_size" />
        <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="sprytextfield8">
        <label for="land_area_size">Land area (m²)</label>
        <input type="text" name="land_area_size" id="land_area_size" />
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="ca_space">
        <label for="car_space">Car Spaces</label>
        <input type="text" name="car_space" id="car_space" />
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="sprytextfield9">
        <label for="prop_aviability">Property will be avialable from</label>
        <input type="text" name="prop_aviability" id="prop_aviability" />
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
     <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><span id="sprytextarea1">
        <label for="description">Description</label>
        <textarea name="description" id="description" cols="45" rows="5"></textarea>
      <span class="textareaRequiredMsg">A value is required.</span></span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
     <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>

      <p>Choose an to upload:
        <br /><input type="hidden" name="MAX_FILE_SIZE" value="100000" />
 <input name="uploadedfile" type="file" />
      Add Image</p></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><input type="submit" name="Submit" id="Submit" value="Submit" /></td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="property" />
</form>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2");
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var spryselect3 = new Spry.Widget.ValidationSelect("spryselect3");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7");
var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8");
var sprytextfield9 = new Spry.Widget.ValidationTextField("sprytextfield9");

</script>
</body>
</html>
4

1 回答 1

0

我不确定您的图像表是什么样的,但是如果图像和属性表是链接的,那么您可以在 SQL 查询中加入它们,就像这样

SELECT img.col1, img.col2
FROM images AS img
JOIN properties AS prop ON img.property_id = prop.property_id
WHERE prop.property_id = $propertyId

这是你要找的吗?

于 2013-10-10T18:20:14.577 回答