Jump to content

[SOLVED] wont update database no error


nelquintin

Recommended Posts

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;
}
}

Link to comment
Share on other sites

Have you tried to echo out $update   $_POST["MM_update"]  &  $_POST["MM_update"], to make sure they are set? You hay not even be running your query by the looks of it. I would try and echo those variables out at the top and make sure I am getting that far at least.

 

You also need a mysql_query like PFM said above  :o

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

Echo out $updateSQL to see what it actually contains. If your property_id = statement does not match any rows, the query will execute but nothing will be updated. Also, if the UPDATE values match the existing values in the row, nothing will be updated. You can use mysql_affected_rows() to find out if the UPDATE actually changed anything.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.