Jump to content

[SOLVED] truncate error


alienmojo

Recommended Posts

let me guess, you inserted into a database and you got this error?

if i'm right, you might want to verify your data before insert into database.
in this case, you inserted a string '66 heavans gate' to a field that accept only double value.

perhap it was something other?
Link to comment
https://forums.phpfreaks.com/topic/33306-solved-truncate-error/#findComment-155620
Share on other sites

ok i can do that just to let u know iv been messing with it and now it says Error: Query was empty


[code]<html>
<head>
<title>Record Status</title>
<link rel="stylesheet" href="CSS.css" type="text/css" />
</head>

<body>
<div id="sidebar">
<img src="images/bigdoglogo.gif" width="225"height="79"  border="0"><div id="menu">
<a href="Home.html">Home</a>
<a href="Apartments.php">Apartments</a>
<a href="Industrial.php">Industrial</a>
<a href="Land.php">Land</a>
<a href="Retail.php">Retail</a>
<a href="OfficeSpace.php">Office Space</a>
<a href="AboutUs.html">About Us</a>
</div>
</div>

<div id="content"><h3>
<?php

$accountnum=$_GET["accountnum"];

$con = mysql_connect("localhost","root","******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("realestate", $con);

mysql_query("DELETE FROM estate WHERE accountnum='$accountnum'");

mysql_query("INSERT INTO estate (address,zipcode,price,baths,bedrooms,state,city,squarefeet,county,subdivision,yearbuilt,description,buyorlease,typeofprop,imagename,acreage)
VALUES
('$_POST[Address]','$_POST[zipcode]','$_POST[price]','$_POST[baths]','$_POST[bedrooms]','$_POST[state]','$_POST[city]','$_POST[squarefeet]','$_POST[county]','$_POST[subdivision]','$_POST[yearbuilt]','$_POST[description]','$_POST[buyorlease]','$_POST[type]','$_POST[imagepath]','$_POST[acreage]')");


if (!mysql_query($sql,$con))
  {
die('Error: ' . mysql_error());
}

//FILE UPLOAD
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("C:/Documents and Settings/Marquis Taliaferro/Desktop/web page/images/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "C:/Documents and Settings/Marquis Taliaferro/Desktop/web page/images/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "C:/Documents and Settings/Marquis Taliaferro/Desktop/web page/images/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
//END OF UPLOAD

echo "<br>";
echo "1 record added";

mysql_close($con)
?>[/code]

im assuming this means that the delete quiery failed
Link to comment
https://forums.phpfreaks.com/topic/33306-solved-truncate-error/#findComment-155639
Share on other sites

I do not see any update queries.

Anyway, I saw an obvious error:

[code]
mysql_query("INSERT INTO estate (address,zipcode,price,baths,bedrooms,state,city,squarefeet,county,subdivision,yearbuilt,description,buyorlease,typeofprop,imagename,acreage)
VALUES
('$_POST[Address]','$_POST[zipcode]','$_POST[price]','$_POST[baths]','$_POST[bedrooms]','$_POST[state]','$_POST[city]','$_POST[squarefeet]','$_POST[county]','$_POST[subdivision]','$_POST[yearbuilt]','$_POST[description]','$_POST[buyorlease]','$_POST[type]','$_POST[imagepath]','$_POST[acreage]')");
[/code]

The error is that when you in-line an array variable like $_POST['something'] you need to wrap it with {}

so the above query should be like:

[code]
mysql_query("INSERT INTO estate (address,zipcode,price,baths,bedrooms,state,city,squarefeet,county,subdivision,yearbuilt,description,buyorlease,typeofprop,imagename,acreage)
VALUES
('{$_POST['Address']}','{$_POST['zipcode']}', ... and so on
[/code]

did you see I wrapped the {} around $_POST['Address']?
I also put single quote around Address, why?
This is to avoid confusion and possible bug to you program.

If you do:
$_POST[Address];  // PHP will first look a predefined symbol called Address, if it can not find this symbol, it then look for the index 'Address' on the array.

Just make sure you single quote out all array index symbol with single quote.

$_POST['address']  <-- Good
$_POST[address] <-- Bad
Link to comment
https://forums.phpfreaks.com/topic/33306-solved-truncate-error/#findComment-155643
Share on other sites

ok this is wierd about your comment on there not being any UPDATE things i said i was messing withit and desided to instead of modifing the row to just delete it and make a new one. here is the wierd part it is actually doing what i want it to but then its giving me that error.
Link to comment
https://forums.phpfreaks.com/topic/33306-solved-truncate-error/#findComment-155646
Share on other sites

ok i figured out why it was doing this through copy and pasting and then modifing a script that i have already wrote i forgot to take this out
if (!mysql_query($sql,$con))
  {
die('Error: ' . mysql_error());
}
im passing in a quiery stored in $sql and in the modified script there isnt a varible name $sql so the quiery is empty.
Link to comment
https://forums.phpfreaks.com/topic/33306-solved-truncate-error/#findComment-155647
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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