So I've been trying to insert sql into this one specific table for the past three hours and I think I'm starting to go insane. I've isolated things I think could be the problem, although if you want more information feel free to ask
Essentially I currently have two sql tables: concepts
and FUideas
(I got really frusturated with it) which are stored in the same database. When I run the following code:
$con = mysql_connect('localhost', 'username', 'password');
mysql_select_db("my_db", $con);
$sql = "INSERT开发者_如何学JAVA INTO `concepts` (description) VALUES ('HAI THAR')";
mysql_query($sql,$con);
It inserts a row into concepts, but when i run this code:
$con = mysql_connect('localhost', 'username', 'password');
mysql_select_db("my_db", $con);
$sql = "INSERT INTO `FUideas` (description) VALUES ('HAI THAR')";
mysql_query($sql,$con);
It does nothing. And just to further mess with your head: if you execute this in phpMyAdmin tab:
INSERT INTO `FUideas` (description) VALUES ('HAI THAR')
it works!?!?!
PLEASE ANY IDEAS, CODE, HACKS? I'M DESPERATE! If you have any hunch or clues tell me and I'll try it and report back with the results
EDIT
PHP Myadmin dump of how to create tables:
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 04, 2011 at 11:21 AM
-- Server version: 5.0.91
-- PHP Version: 5.2.9
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
CREATE TABLE concepts (
id int(10) unsigned NOT NULL auto_increment,
title tinytext NOT NULL,
`user` tinytext NOT NULL,
`date` int(10) unsigned NOT NULL default '0',
summary tinytext NOT NULL,
description text NOT NULL,
tags tinytext NOT NULL,
ip tinytext NOT NULL,
appreciates tinyint(3) unsigned NOT NULL default '4',
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 04, 2011 at 11:23 AM
-- Server version: 5.0.91
-- PHP Version: 5.2.9
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Table structure for table 'FUideas'
--
CREATE TABLE FUideas (
id int(10) unsigned NOT NULL auto_increment,
`user` tinytext NOT NULL,
`date` int(10) unsigned NOT NULL default '0',
description text NOT NULL,
upvotes text NOT NULL,
downvotes text NOT NULL,
appreciated tinyint(3) unsigned NOT NULL default '0',
ip tinytext NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
FINAL UPDATE
For anyone else looking at this problem, it turns out that I had old code running at the same time which was creating the errors and inconsistencies.
Try thiS:
mysql_query($sql,$con) or die(mysql_error());
If there is a problem with the query (syntax error, or a key violation, etc...), then the die() call will spit out the error message describing the problem.
Try
$sql = "INSERT INTO `FUideas` (`description`) VALUES ('HAI THAR')";
If that doesn't work then i ask, in your SQL to create the table, how come user
and date
are quoted, but the other fields aren't?
Since it works as an admin, my guess is that the username you are using in the connection does not have insert privileges over the FUIdeas table.
I am not exactly sure, but description may be reserved, try..
$con = mysql_connect('localhost', 'username', 'password');
mysql_select_db("my_db", $con);
$sql = "INSERT INTO `FUideas` (`description`) VALUES ('HAI THAR')";
mysql_query($sql,$con) or die(mysql_error());
I guess that would'nt make sense with the first one working...
is my_db the same for both instances?
Can you see the SQL-error? I can't see how your first query works since you have a bunch of not null columns without DEFAULT-values.
You are trying to insert single value:
$sql = "INSERT INTO
concepts
(description) VALUES ('HAI THAR')";
While you have many fields market as NOT NULL
in your table. You must fill at least ALL required fields with one insert statement.
BTW your first "working" expression could not work also if DDL you passed is real.
精彩评论