I would like to store a value which is sometimes a string, sometimes an integer. (In PHP and mySQL)
The variables are set up like this:
$userID = 123; // Unique primary key, always a number
$name = "nameOfTheProperty"; // Always a string
$value = "someText" or 1234; // Depending on the property to save
This works if its a integer property:
$sql = "INSERT INTO saves (`User_ID`, `$name`) VALUES ($userID, $value) ON DUPLICATE KEY UPDATE `$name`=$value";
And this if its a string property:
$sql = "INSERT INTO saves (`User_ID`, `$name`) VALUES ($userID, '$value') ON DUPLICATE KEY UPDATE `$name`='$value'";
How can I get this to work in general? Best in one query.