Lodius2000 Posted June 25, 2008 Share Posted June 25, 2008 what i want to do is insert values into 2 columns, (title and article) in only one row (id) and the row already exists and id is derived from $_GET so I should shield it using a ? can I have a query that says 'INSERT INTO tablename (article_title, article) VALUES(?, ?) WHERE article_id = ?', array($title, $article, $id) Quote Link to comment https://forums.phpfreaks.com/topic/111772-quickie-mysql-query-help/ Share on other sites More sharing options...
ohdang888 Posted June 25, 2008 Share Posted June 25, 2008 You cannot put an INSERT INTO with a WHERE clause, it doesn't work( and think about it, theres no point) use "UPDATE tablename SET `column`='$var' WHERE `id`='$id'" also, use "or die(mysql_error())" after every query to find the problems Quote Link to comment https://forums.phpfreaks.com/topic/111772-quickie-mysql-query-help/#findComment-573831 Share on other sites More sharing options...
Lodius2000 Posted June 25, 2008 Author Share Posted June 25, 2008 could I use UPDATE if title and article are currently empty? Quote Link to comment https://forums.phpfreaks.com/topic/111772-quickie-mysql-query-help/#findComment-573841 Share on other sites More sharing options...
Nexy Posted June 25, 2008 Share Posted June 25, 2008 UPDATE would be the way to go: $sql = "UPDATE tablename SET article_title = '$title', article = '$article' WHERE article_id = '$id'"; $res = mysql_query($sql) OR die(mysql_error()); Replace the text in single quotes to whatever you want, and this will work if they are empty, assuming the row exists. Now show about your array there. Quote Link to comment https://forums.phpfreaks.com/topic/111772-quickie-mysql-query-help/#findComment-573849 Share on other sites More sharing options...
.josh Posted June 25, 2008 Share Posted June 25, 2008 insert is for adding a new row. update is for editing an existing row. Quote Link to comment https://forums.phpfreaks.com/topic/111772-quickie-mysql-query-help/#findComment-573854 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.