Re: Insert problems in to a MySQL database.
| From: | Andrew Rush | Date: | Thu, 05 Oct 2000 19:16:05 +0000 |
| Subject: | Re: Insert problems in to a MySQL database. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18760@lists.php.net to get a copy of this message | ||
At 10:11 AM -0700 10/5/00, Joao Prado Maia wrote:
On Thu, 5 Oct 2000, Jari Ivanoff wrote: mysql_query("insert into news.news values(NULL,curdate(),curtime(),'$rubrik','$content';") or die("InvalidQuery"); mysql_query("insert into news.news values(NULL,curdate(),curtime(),%s,%s",$rubrik,$content") or die("InvalidQuery");
Your SQL queries looks very broken to me, thats why it is not working.the query is broken, but not for the reasons given/
1 - Why are you putting "insert into news.news ..." ? As far as I know, you don't need that extra ".news".nope- it's not necessary, but it ain't broken either. news.news qualifies both the database and the table. you can take it a step further and qualify the exact column- i.e. news.news.date or news.news.time
2 - The date and time columns are VARCHAR, but you are not quoting them when you run your query.while inserting date and time data into a VARCHAR is not the best database design, it's perfectly acceptable, and- so long as there are no spaces in the string- quotes aren't necessary
3 - You don't need to put anything on the id column on those queries.no, but it saves you the time necessary to specify the columns. this can be a real time saver when you are inserting into a lot of fields at once.
So your query should be something like this :$current_date and $current_time are undefined. it would simpler if you rewrote the query show below:
$sql = "INSERT INTO news "; $sql .= "(date, time, head, content) "; $sql .= "VALUES ('$current_date', '$current_time', '$head', '$content')"; mysql_query($sql);as $sql = "INSERT INTO news "; $sql .= "(date, time, head, content) "; $sql .= "VALUES (curdate(), curtime(), '$head', '$content')"; mysql_query($sql); the original query was breaking because of the "%s"'s in "curtime(),%s,%s" which i assume are attempts to format the time. curtime() doesn't support formatting in that manner- it returns hh:mm:ss if called as "curtime()", and it returns hhmmss if called as "curtime()+0".