crawlerbasher Posted February 8, 2007 Share Posted February 8, 2007 I've been checking out a few online sites, my php mysql book to try and find the answers and still I'm not sure what I'm doing wrong. I know that the mysql part is right, but I don't think the code is correct. When I try to update it, I get a message saying its done, but notthing has been updated or added to the database. This is part of the code <?php // Update the database now with the information updated on the form. // Start Database Entry include("config.php"); $databaseID = $_POST['databaseID']; $level = $_POST['level']; $items = $_POST['items']; $rank = $_POST['rank']; $hq = $_POST['hq']; $hq2 = $_POST['hq2']; $hq3 = $_POST['hq3']; $ingredients = $_POST['ingredients']; $crystal = $_POST['crystal']; $sub_craft = $_POST['subcraft']; $conn = mysql_connect($host, $username, $password); mysql_select_db($database, $conn); $sql = "UPDATE FFXI_Guild_Cooking SET item = '$items', crystal = '$crystal', ingredients = '$ingredients', hq_item = '$hq', hq_item2 = '$hq2', hq_item3 = '$hq3', rank = '$rank', lvl_cap = '$level', sub_craft = '$sub_craft' WHERE 'id' = '$databaseID' LIMIT 1"; $result = mysql_query($sql, $conn) or die(mysql_error()); if($result)//this works, as 1 = true { echo "Your Crafting Recipe has been added."; } } // end Database entry ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 8, 2007 Share Posted February 8, 2007 print $sql before inserting it to make sure it says what you think it should. You can also do print_r($_POST); at the top to see if the post vars are what you're expecting. Quote Link to comment Share on other sites More sharing options...
crawlerbasher Posted February 8, 2007 Author Share Posted February 8, 2007 Well the information from the $sql is the information that I've updated and information thats been left the same. Quote Link to comment Share on other sites More sharing options...
crawlerbasher Posted February 8, 2007 Author Share Posted February 8, 2007 I can't figure it out. The update script says its working but nothing has been updated into the database at all. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 8, 2007 Share Posted February 8, 2007 That's why I reccomended you PRINT out $sql so you can SEE what it says and find out if there is a problem there. If you don't get an error, and the SQL is fine, then you're in an 9th dimension and we can't help. Quote Link to comment Share on other sites More sharing options...
crawlerbasher Posted February 8, 2007 Author Share Posted February 8, 2007 When I did the print $sql I say all the information that I've inputed inlcuding the where id ='$id' where correct. Just had an idea, if the data in the verables are empty, could not couse the sql statment not to be updated, but still produce a error free script? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 8, 2007 Share Posted February 8, 2007 If the values are empty, it will update the record to an empty value. Why do you say it's not updated? How are you viewing the record? Quote Link to comment Share on other sites More sharing options...
crawlerbasher Posted February 8, 2007 Author Share Posted February 8, 2007 Via php script, and also via phpadmin to check on if the data is been enter correctley. And both are showing the same result, which is the same data as before the data was updated. Quote Link to comment Share on other sites More sharing options...
crawlerbasher Posted February 9, 2007 Author Share Posted February 9, 2007 Got it working. I still can't understand why the other one did not work. Could it be because of the diffrent version of mysql? Anyway this is the sql statment I changed it to this <?php $sql = 'UPDATE `FFXI_Guild_'.$id.'` SET `item` = \''.$items.'\', `crystal` = \''.$crystal.'\', `ingredients` = \''.$ingredients.'\', `hq_item` = \''.$hq.'\', `hq_item2` = \''.$hq2.'\', `hq_item3` = \''.$hq3.'\', `sub_craft` = \''.$sub_craft.'\' WHERE `FFXI_Guild_'.$id.'`.`id` = '.$databaseID.' LIMIT 1;'; ?> 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.