Re: Insert problems in to a MySQL database.

From: Date: Thu, 05 Oct 2000 17:11:03 +0000
Subject: Re: Insert problems in to a MySQL database.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-18752@lists.php.net to get a copy of this message
On Thu, 5 Oct 2000, Jari Ivanoff wrote: > The database is set up as follows: > CREATE TABLE news ( id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT, date > varchar(10) NOT NULL,time varchar(8)NOT NULL, head varchar(20), content > blob, PRIMARY KEY (id), UNIQUE id (id)); > > DB Updatescript: > <?php > $db = mysql_connect("localhost","root"); > mysql_select_db("news",$db); > mysql_query("insert into news > values(NULL,curdate(),curtime(),%s,%s",$head,$content) or die("Invalid > Query"); > ?> > I have tried the following querys: > > mysql_query("insert into news.news > values(NULL,curdate(),curtime(),'$rubrik','$content';") or > die("Invalid > Query"); > mysql_query("insert into news.news > values(NULL,curdate(),curtime(),%s,%s",$rubrik,$content") or die("Invalid > Query"); > > With and without the ' signs and the ; signs in different places. > Any ideas? ;-) > /Jari Hi Jari, Your SQL queries looks very broken to me, thats why it is not working. 1 - Why are you putting "insert into news.news ..." ? As far as I know, you don't need that extra ".news". 2 - The date and time columns are VARCHAR, but you are not quoting them when you run your query. 3 - You don't need to put anything on the id column on those queries. So your query should be something like this : <?php $sql = "INSERT INTO news "; $sql .= "(date, time, head, content) "; $sql .= "VALUES ('$current_date', '$current_time', '$head', '$content')"; mysql_query($sql); ?> Regards, Joao -- Joao Prado Maia Web Developer Kefta, Inc. T: (415) 391-6881 ext 8008 F: (415) 391-7079

« previous php.general (#18752) next »