Jump to content

SQL doesn't want to update


ChaosKnight

Recommended Posts

Hi, this code is supposed to update a hotel entry, but each time I try to run it, it says that it doesn't update...

<?php
  //DB works, so that code is left out

  if(isset($_GET['id'])){
    $id = $_GET['id'];
  }
  if(isset($_POST['submit'])){

    //code that works is left out...

    $logoTxt = $_POST['logo'];
    $image1Txt = $_POST['image1'];
    $image2Txt = $_POST['image2'];
  
    $allowedExtensions = array("png","jpg","jpeg","gif");

    if((isset($_FILES['logoUpload']))&&($_FILES['logoUpload']['tmp_name'] > '')){
       // logo upload code works
       $logo = $_FILES['logoUpload']['name'];
    }else{
      $logo = $logoTxt;
    }
    if((isset($_FILES['image1Upload']))&&($_FILES['image1Upload']['tmp_name'] > '')){
       // image1 upload code works
       $image1 = $_FILES['image1Upload']['name'];
    }else{
      $image1 = $image1Txt;
    }
    if((isset($_FILES['image2Upload']))&&($_FILES['image2Upload']['tmp_name'] > '')){
       // image2 upload code works
       $image2 = $_FILES['image2Upload']['name'];
    }else{
      $image2 = $image2Txt;
    }
    if((isset($image1))&&(isset($image2))&&(isset($logo))){
      $sql = "UPDATE hotels name='$name', description='$description', location='$location', country_id='$country_id',
                 country='$country_name', province_id='$province_id', province='$province_name', town_id='$town_id',
                 town='$town_name', city_id='$city_id', city='$city_name', park_id='$park_id', park='$park_name', 
                 languages='$languages', logo='$logo', logo_width='$logo_width', logo_height='$logo_height',
                 image1='$image1', image2='$image2', homepage='$homepage', active='$active', type='$type'
                 WHERE `id`='".$id."'";
    }elseif((isset($image1))&&(isset($image2))){
      $sql = "UPDATE hotels name='$name', description='$description', location='$location', country_id='$country_id',
                 country='$country_name', province_id='$province_id', province='$province_name', town_id='$town_id',
                 town='$town_name', city_id='$city_id', city='$city_name', park_id='$park_id', park='$park_name',
                 languages='$languages', image1='$image1', image2='$image2', homepage='$homepage',
                 active='$active', type='$type' WHERE `id`='".$id."'";
    }elseif((isset($image1))&&(isset($logo))){
      $sql = "UPDATE hotels name='$name', description='$description', location='$location', country_id='$country_id',
                 country='$country_name', province_id='$province_id', province='$province_name', town_id='$town_id',
                 town='$town_name', city_id='$city_id', city='$city_name', park_id='$park_id', park='$park_name',
                 languages='$languages', logo='$logo', logo_width='$logo_width', logo_height='$logo_height',
                 image1='$image1', homepage='$homepage', active='$active', type='$type' WHERE `id`='".$id."'";
    }else{
      $sql = "UPDATE hotels name='$name', description='$description', location='$location', country_id='$country_id',
                 country='$country_name', province_id='$province_id', province='$province_name', town_id='$town_id',
                 town='$town_name', city_id='$city_id', city='$city_name', park_id='$park_id', park='$park_name',
                 languages='$languages', homepage='$homepage', active='$active', type='$type' WHERE `id`='".$id."'";
    }
    if(mysql_query($sql, $db_link)){
      echo "<h3>The hotel was updated successfully...</h3>";
    }else{
      echo "<h3>The hotel could not be updated...</h3>";
    }
  }
?>

 

Can anyone see what I did wrong??

Link to comment
Share on other sites

Hi there ChaosKnight,

 

WRT the $sql vars, after the if/elseif/else tree have you actually tried to echo the $sql var to screen to see if the query is being populated correctly?

 

Also you seem to be mixing and matching the concatonations, ie: the WHERE `id` = part is correct, but the rest of the qurey is using single quotes, I'm not saying as it will make the difference, but fluidity of code makes it easier to read ;-p

 

And you may want to add the or die(mysql_error()) to the end of the mysql_query() so that errors that end can be shown, obviously though, take it out when you go live, as leaving it there could give info away to would be hackers.

 

Cheers,

Rwwd

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.