PDA

View Full Version : can't update when id is varchar


nanny
02-16-2010, 06:12 AM
Hi for my country table which is a foreign key in another table I use country varchar(140) for the id. Like this:
CREATE TABLE IF NOT EXISTS country (
country varchar(120) NOT NULL DEFAULT '',
PRIMARY KEY (country)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

The reason is that I am manually adding different country names to multiple forms in an international site and no I can't have a dropdown field. So it is easier to add the name as a primary key.

However I don't seem to be able to update the country table. I can in phpmyadmin but not in dreamweaver. When I do an update it says error. Does anybody have any suggestions to get the id of the repeat region to go to update selected country.

Thanks

davidj
02-16-2010, 06:34 AM
nanny

you have been doing this PHP malarkey for sooooooooo long now

ever fancied learning to hand code

nanny
02-16-2010, 08:54 PM
Davidj I am hand coding.....

domedia
02-16-2010, 08:57 PM
When I do an update it says error. Does anybody have any suggestions to get the id of the repeat region to go to update selected country.
Can you post error?

nanny
02-16-2010, 09:44 PM
OK I changed my table name to countries to stop confusion.

this is the image link that connects to the page for editing:

<a href="country2.php?category=<?php echo $row['country']; ?>"><img src="images/edit.gif" alt="edit" width="48" height="48" /></a>



this is the select statement:


"SELECT * FROM countries WHERE countries.country = 'category'";



This is the update:

if (array_key_exists('send', $_POST)) {
$category = $_GET['country'];
if (empty($country)) {
$error['country'] = 'Please put the country name in box.';
}

if (!isset($error)) {
$update = "UPDATE countries SET country= '$country' WHERE country = $category";
mysql_query($update);
header ("Location: country.php");

}



this is the error message regarding every country I select:

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 country='Argentina and South America'' at line 1


thanks....

edbr
02-16-2010, 10:54 PM
?category= but $category = $_GET['country'];

nanny
02-16-2010, 11:17 PM
Yes but doesn't matter whether I change category to be country the problem still exists e.g.

<a href="country2.php?country=<?php echo $row['country']; ?>"><img src="images/edit.gif" alt="edit" width="48" height="48" /></a>


"SELECT * FROM countries WHERE countries.country = 'country'";


if (array_key_exists('send', $_POST)) {
$country = $_GET['country'];
if (empty($country)) {
$error['country'] = 'Please put the country name in box.';
}

if (!isset($error)) {
$update = "UPDATE countries SET country= '$country' WHERE country = $country";
mysql_query($update);
header ("Location: country.php");

}



what do you suggest?

davidj
02-17-2010, 05:41 AM
echo $update so i can see what its made up of