Jump to content

[SOLVED] mysql update, what am I doing wrong?


crawlerbasher

Recommended Posts

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	
?>

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?

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;';
?>

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.