无法将SQL插入一个特定的表 [英] Cannot Insert SQL Into One Specific Table

查看:83
本文介绍了无法将SQL插入一个特定的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在过去的三个小时中,我一直试图将sql插入到该特定表中,我想我开始发疯了. 我隔离了一些我认为可能是问题的东西,尽管如果您想了解更多信息,请随时询问

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

基本上,我目前有两个sql表:conceptsFUideas(我对此感到非常沮丧),它们存储在同一数据库中.当我运行以下代码时:

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 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);

它什么都不做. 如果要进一步弄乱您的头脑,:如果您在phpMyAdmin标签中执行此操作:

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')

有效!!!?!

请输入任何想法,代码和密码吗?我很绝望! 如果您有任何直觉或线索,请告诉我,我会尝试并报告结果

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

PHP Myadmin转储如何创建表:

-- 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.

推荐答案

尝试以下方法:

mysql_query($sql,$con) or die(mysql_error());

如果查询存在问题(语法错误或键冲突等),则die()调用将吐出描述该问题的错误消息.

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.

这篇关于无法将SQL插入一个特定的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆