FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Dunno what...but somthing wrong here .. :(





salman_500
hey..

this is my script...

Code:


if ($_POST['submit']){

function randomid() {
  $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  srand((double)time()*1000000); 
      $i = 0;
      while ($i <= 5) {
            $num = rand() % 33;
            $tmp = substr($salt, $num, 1);
            $randid = $randid . $tmp;
            $i++;
      }
      return $randid;
}

$id = randomid();
$name = $_POST['name'];
$category = $_POST['category'];
$description = $_POST['description'];
$type = $_POST['type'];
$resolution = $_POST['resolution'];
$authur = $_POST['authur'];


mysql_query("INSERT INTO templates (id, name, category, description, type, resolution, authur, addition_date) VALUES ('$id', '$name', '$category', '$description', '$type', '$resolution', '$authur', now())") or die (mysql_error());

$maxfilesize = 1000000;
// check if there was a file uploaded
if (!is_uploaded_file($_FILES['image']['tmp_name'])) {
    $error = "<b>you didn't select a file to upload.</b><br />";
// if it was, go ahead with other checks
} else {
    if ($_FILES['image']['size'] > $maxfilesize) {
        $error = "<b>your image file was too large.</b><br />";
        unlink($_FILES['image']['tmp_name']);
    } else {
        $ext = strrchr($_FILES['image']['name'], ".");
        if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG") {
            $error = "your file was an unacceptable type.<br />";
            unlink($_FILES['image']['tmp_name']);
        // if it's there, an okay size and type, copy to server and update the photo value in SQL
        } else {
             
           $newname = $id.$ext;
           move_uploaded_file($_FILES['image']['tmp_name'],"modules/templates/images/".$newname);
           mysql_query("INSERT INTO templates (image) VALUES ('$newname') WHERE id= '$id'") or die (mysql_error());
             
       }
   }
}


}


but when i submit it..... i get all the field in the databse except for the one that is uploaded.... its named and uploaded... but when the time comes when it has to enter the info into the data base... i get am error...

Quote:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id= '2hqz2v'' at line 1


here "2hqz2v" is the randomly generated id..

it is entered into the id column, value being in the array $id... but when i use this method.... WHERE id= '$id' .... i get the above error.... the id field has the right value... but i dont understand whats rong..

plz help !! Sad Embarassed
hexkid
Replace your
salman_500 wrote:
Code:
           mysql_query("INSERT INTO templates (image) VALUES ('$newname') WHERE id= '$id'") or die (mysql_error());
with
Code:
           mysql_query("UPDATE templates SET image='$newname' WHERE id= '$id'") or die (mysql_error());
salman_500
hexkid wrote:
Replace your
salman_500 wrote:
Code:
           mysql_query("INSERT INTO templates (image) VALUES ('$newname') WHERE id= '$id'") or die (mysql_error());
with
Code:
           mysql_query("UPDATE templates SET image='$newname' WHERE id= '$id'") or die (mysql_error());


gee thanks !!!!!!!!!! Very Happy

i knew it was gonna hit head when i saw reply of hexkid !@!@!@! Cool Very Happy Razz
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.