Eh, I was wondering if anyone could help me with a SQL query problem
I'm having. I'm a complete newbie to SQL and MySQL, so any help would
be greatly appreciated.
I am using PHP to allow users to submit ISBNs, prices, and item
conditions into a MySQL database. The table the values are inserted
into is declared with
CREATE TABLE prices (isbn VARCHAR(10), price FLOAT UNSIGNED,
conditions VARCHAR(5))
I use this SQL query to check whether or not the passed ISBN is
already in the database. If it does, it updates the columns with the
new price and conditions. If it does not, it inserts a fresh row. The
variables $isbn, $price, and $conditions are all PHP variables which
are automatically inserted into the query.
BEGIN
SELECT "true" INTO $exists FROM prices WHERE isbn = "$isbn";
IF $exists = "true" THEN
UPDATE prices SET price = $price, conditions = "$condition s" WHERE
isbn = "$isbn";
ELSE
INSERT INTO prices (isbn, price, conditions) VALUES ("$isbn",
$price, "$condition s");
ENDIF;
END
However, it doesn't understand my SELECT statement, and I'm sure it
has other problems.
Regards,
RG
I'm having. I'm a complete newbie to SQL and MySQL, so any help would
be greatly appreciated.
I am using PHP to allow users to submit ISBNs, prices, and item
conditions into a MySQL database. The table the values are inserted
into is declared with
CREATE TABLE prices (isbn VARCHAR(10), price FLOAT UNSIGNED,
conditions VARCHAR(5))
I use this SQL query to check whether or not the passed ISBN is
already in the database. If it does, it updates the columns with the
new price and conditions. If it does not, it inserts a fresh row. The
variables $isbn, $price, and $conditions are all PHP variables which
are automatically inserted into the query.
BEGIN
SELECT "true" INTO $exists FROM prices WHERE isbn = "$isbn";
IF $exists = "true" THEN
UPDATE prices SET price = $price, conditions = "$condition s" WHERE
isbn = "$isbn";
ELSE
INSERT INTO prices (isbn, price, conditions) VALUES ("$isbn",
$price, "$condition s");
ENDIF;
END
However, it doesn't understand my SELECT statement, and I'm sure it
has other problems.
Regards,
RG
Comment