LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2004, 01:19 PM   #1
eam
Member
 
Registered: Nov 2003
Location: USA
Distribution: Slackware
Posts: 67

Rep: Reputation: 15
Problem with PHP and MySQL


I'm reading a MySQL tutorial and this is the first script I put together. When it's run I get the failed on insert 1 error. What's wrong?

Code:
<?php

include("conf.php");

$connection = mysql_connect($host,$user,$pass) or die ("Failed to connect<br>\n");

$db = mysql_select_db($database,$connection) or die ("\nFailed to select<br>");

$query = "CREATE TABLE bookx3 ( id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT,  title varchar(50),  author varchar(50),  description varchar(255),  price varchar(10),  PRIMARY KEY (id),  UNIQUE id (id))";
mysql_query($query) or die ("Failed on making the thing<br>");
$query = "INSERT INTO bookx3 VALUES ('the book','some guy','a book.','$1000')";
mysql_query($query) or die ("Failed on insert 1<br>");
$query = "INSERT INTO bookx3 VALUES ('the other book','who knows','the greatest book ever written','$0.02')";
mysql_query($query) or die ("Failed on insert 2<br>");

?>
 
Old 08-24-2004, 02:00 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
You try to Insert a string ("the book") where mysql expects an integer (id tinyint(4))

Try to change your insert line by something like :

INSERT INTO bookx3 VALUES ('','the book','some guy','a book.','$1000')
 
Old 08-24-2004, 02:33 PM   #3
eam
Member
 
Registered: Nov 2003
Location: USA
Distribution: Slackware
Posts: 67

Original Poster
Rep: Reputation: 15
I added the 1 and 2 back to the beginning and it worked. Before it didn't so I took the numbers out. Oh well. Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/MySQL Problem! SpiderIRE Programming 3 10-19-2005 11:24 AM
php-mysql problem need help productive Linux - Software 1 04-28-2005 02:27 PM
Problem with MySQL 4.1.7 and PHP 5.0.2 Lars79 Slackware 4 10-28-2004 08:09 AM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 08:54 PM
MySQL / PHP problem jjd228 Linux - Software 5 03-15-2004 10:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration