ChaosKnight Posted May 28, 2010 Share Posted May 28, 2010 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?? Quote Link to comment Share on other sites More sharing options...
rwwd Posted May 28, 2010 Share Posted May 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
mattal999 Posted May 28, 2010 Share Posted May 28, 2010 You're missing the SET part at the start of the query: UPDATE hotels SET name='$name' Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted May 28, 2010 Author Share Posted May 28, 2010 Hahaha thanks mate, you saved me from a huge headache lol... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.