Table doesn't appear to be accepting new rows? - mysql

It has come to my attention that one of my websites is not allowing users to register. Upon looking through the table and running through different scenarios it appears as if my table isn't allowing any more rows.
I'm on PHP 7.0 running MariaDB on cPanel. My table was at 499 rows and I could not add a new user from the script I haven't changed in years. I tested the code on a new table and it inserted the value just fine and the rest of the script executes just fine. This is leading me to believe it's something with the table.
CREATE TABLE `members` (
`id` int(10) NOT NULL,
`name` varchar(30) NOT NULL DEFAULT '',
`ipaddress` varchar(15) NOT NULL DEFAULT '',
`salt` varchar(32) NOT NULL DEFAULT '',
`gender` varchar(10) NOT NULL DEFAULT '',
`country` varchar(2) NOT NULL DEFAULT '',
`password` varchar(33) NOT NULL DEFAULT '',
`email` varchar(400) NOT NULL DEFAULT '',
`lastactive` varchar(20) NOT NULL DEFAULT '',
`photo` varchar(100) NOT NULL DEFAULT '',
`about` text NOT NULL,
`intrests` text NOT NULL,
`aim` varchar(15) NOT NULL DEFAULT '',
`yahoo` varchar(25) NOT NULL DEFAULT '',
`msn` varchar(25) NOT NULL DEFAULT '',
`website` varchar(30) NOT NULL DEFAULT '',
`points` int(10) NOT NULL DEFAULT 0,
`view` char(1) NOT NULL DEFAULT '',
`joined` timestamp NOT NULL DEFAULT current_timestamp(),
`act` char(1) NOT NULL DEFAULT '',
`xlink` varchar(30) NOT NULL,
`isstaff` int(1) NOT NULL DEFAULT 0,
`stgr` int(3) NOT NULL,
`rights` int(3) NOT NULL,
`stpr` int(10) NOT NULL,
`trs` varchar(30) NOT NULL,
`sttitle` varchar(60) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Indexes for table `members`
--
ALTER TABLE `members`
ADD PRIMARY KEY (`id`),
ADD KEY `id` (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `members`
--
ALTER TABLE `members`
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=502;
COMMIT;
///Here is the insert code for my PHP script
mysqli_query($connection, "INSERT INTO members (name,ipaddress,salt,gender,country,password,email,act) VALUES (
'".mysqli_real_escape_string( $connection, $member['name'])."',
'".mysqli_real_escape_string( $connection, $ip)."',
'".mysqli_real_escape_string( $connection, $enurl)."',
'".mysqli_real_escape_string( $connection, $member['gender'])."',
'".mysqli_real_escape_string( $connection, $member['country'])."',
'".mysqli_real_escape_string( $connection, $pass2)."',
'".mysqli_real_escape_string( $connection, $member['email'])."',
'".mysqli_real_escape_string( $connection, $anumber)."')");
My error_log does not populate with any errors nor is there an error dumped on the page. Like I said the script runs it's course just fine inserting these same details into other tables.

Related

Cant create a relation in mysql - Error creating foreign key on id_produk (check data types)

here is my table :
CREATE TABLE `pesanan` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ref_number` varchar(50) NOT NULL DEFAULT '',
`id_produk` int(11) NOT NULL,
`id_user` int(11) NOT NULL,
`qty` int(11) NOT NULL,
`total` varchar(50) NOT NULL DEFAULT '',
`tanggal` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
i want to create a relation of id_produk to table produk.id and id_user to user.id, here is the other table :
CREATE TABLE `produk` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_kategori` int(11) NOT NULL,
`status` varchar(10) NOT NULL DEFAULT '',
`slug` varchar(100) NOT NULL DEFAULT '',
`judul` varchar(100) NOT NULL DEFAULT '',
`harga` varchar(10) DEFAULT '',
`target` int(11) DEFAULT NULL,
`desc` text,
`cover` varchar(100) DEFAULT NULL,
`tanggal` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1;
and user table
CREATE TABLE `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`suspended` int(11) DEFAULT NULL,
`level` varchar(11) DEFAULT NULL,
`nama` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`password` varchar(100) DEFAULT NULL,
`alamat` text,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=latin1;
when i try to relation it , it give me this error :
Error creating foreign key on id_produk (check data types)
The columns should have the exact same data type in both tables. In your case in the "produk" and "user" tables they are unsigned, which means they go from 0 to 4294967295 but in the "pesanan" table they are signed which means they go from -2147483648 to 2147483647. See more here.
If the server allowed you to create such foreign keys, it would possibly create situations where, for example, a user is added with and ID of 2147483648 that cannot ever be referenced in the "pesanan" table.
You should change the "id_produk" and "id_user" columns in the "pesanan" table to be unsigned.

MariaDB - CONNECT ENGINE - ORDER BY error

I'm trying to get Asterisk CDR records from MySQL table (5.5.45) by CONNECT engine on other server running MariaDB (10.0.29).
I can create the connection between table easily:
CREATE TABLE `calls` engine=CONNECT table_type=MYSQL
CONNECTION='mysql://user#IP/asteriskcdrdb/calls';
When I run simple SELECT * FROM calls, everything works good, when I add some WHERE conditions, still everything okay.
But the problem start when I add ORDER BY column parameter, then I got this error from MariaDB:
#1032 - Can't find record in 'calls'
I checked MySQL log, MariaDB log - there are no errors at all.
Did I miss something?
Thank you!
Update: The whole query is simple:
SELECT * FROM `calls` ORDER BY `calldate`
The table structure:
CREATE TABLE `calls` (
`calldate` datetime NOT NULL default '0000-00-00 00:00:00',
`clid` varchar(80) NOT NULL default '',
`src` varchar(80) NOT NULL default '',
`dst` varchar(80) NOT NULL default '',
`dcontext` varchar(80) NOT NULL default '',
`channel` varchar(80) NOT NULL default '',
`dstchannel` varchar(80) NOT NULL default '',
`lastapp` varchar(80) NOT NULL default '',
`lastdata` varchar(80) NOT NULL default '',
`duration` int(11) NOT NULL default '0',
`billsec` int(11) NOT NULL default '0',
`disposition` varchar(45) NOT NULL default '',
`amaflags` int(11) NOT NULL default '0',
`accountcode` varchar(20) NOT NULL default '',
`uniqueid` varchar(32) NOT NULL default '',
`userfield` varchar(255) NOT NULL default '',
`recordingfile` varchar(255) NOT NULL default '',
`cnum` varchar(40) NOT NULL default '',
`cnam` varchar(40) NOT NULL default '',
`outbound_cnum` varchar(40) NOT NULL default '',
`outbound_cnam` varchar(40) NOT NULL default '',
`dst_cnam` varchar(40) NOT NULL default '',
`call_charge` float NOT NULL default '0',
`from_did` varchar(30) NOT NULL,
`did` varchar(50) NOT NULL default '',
`user_id` int(8) unsigned default NULL,
`client_id` int(8) unsigned default NULL,
KEY `IDX_UNIQUEID` (`uniqueid`),
KEY `src` (`src`),
KEY `dst` (`dst`),
KEY `calldate` (`calldate`),
KEY `uniqueid` (`uniqueid`),
KEY `userfield` (`userfield`),
KEY `from_did` (`from_did`),
KEY `user_id` (`user_id`),
KEY `client_id` (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Update #2: Update the table names, to don't confuse, but it's not the issue. The CONNECTION table is created okay.
Query works:
SELECT * FROM `calls`
Query works:
SELECT * FROM `calls` WHERE `user_id`=X
Query return error:
SELECT * FROM `calls` ORDER BY `calldate`
Update #3: The MySQL was updated to veriosn 5.5.45, the type was changed to InnoDB and the charset was converted to UTF8. But no success.
PROBLEM SOLVED
Well, it's MariaDB bug, when I changed to FederatedX engine (which is basically little bit limited version of CONNECT), everything works as expected.
In your query you do
SELECT * FROM calls
but in your table structure you have
CREATE TABLE cdr
and both have calldate column. Check if you querying the right table.

Create table in magento module

I am new in magento. How can I create table in db ? I tried some code, but table didn't create. But in core_resource table I have setup my table. The version of my php file is match with version of my config file. Help me please, I am looking answer for that question two days , but nowhere can find anything.
There are many ways to create a table.
You can create table by direct phpmyadmin
write own sql and run that by php file
Both ways are applicable on magento too.
but if you are trying to create your own table by your own custom module then you have to play with xml and magento models.
I am providing you an example of module.
XML
<models>
<magenotification>
<class>Magestore_Magenotification_Model</class>
<resourceModel>magenotification_mysql4</resourceModel>
</magenotification>
<magenotification_mysql4>
<class>Magestore_Magenotification_Model_Mysql4</class>
<entities>
<magenotification>
<table>magenotification</table>
</magenotification>
<feedback>
<table>magenotification_extension_feedback</table>
</feedback>
<feedbackmessage>
<table>magenotification_extension_feedbackmessage</table>
</feedbackmessage>
<logger>
<table>magenotification_log</table>
</logger>
<license>
<table>magenotification_license</table>
</license>
</entities>
</magenotification_mysql4>
</models>
SQL
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
DROP TABLE IF EXISTS {$this->getTable('magenotification_extension_feedbackmessage')};
DROP TABLE IF EXISTS {$this->getTable('magenotification_extension_feedback')};
DROP TABLE IF EXISTS {$this->getTable('magenotification_log')};
DROP TABLE IF EXISTS {$this->getTable('magenotification')};
CREATE TABLE {$this->getTable('magenotification')} (
`magenotification_id` int(11) unsigned NOT NULL auto_increment,
`notification_id` int(10) unsigned NOT NULL,
`url` varchar(255) NOT NULL default '',
`added_date` datetime NOT NULL,
UNIQUE (`notification_id`, `url`),
PRIMARY KEY (`magenotification_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE {$this->getTable('magenotification_log')} (
`log_id` int(11) unsigned NOT NULL auto_increment,
`extension_code` varchar(100) NOT NULL default '',
`license_type` varchar(50) NOT NULL default '',
`license_key` text NOT NULL default '',
`check_date` date NOT NULL,
`sum_code` varchar(255),
`response_code` smallint(5),
`expired_time` varchar(255),
`is_valid` tinyint(1),
PRIMARY KEY (`log_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE {$this->getTable('magenotification_extension_feedback')} (
`feedback_id` int(11) unsigned NOT NULL auto_increment,
`code` varchar(255) NOT NULL default '',
`extension` varchar(255) NOT NULL default '',
`extension_version` varchar(50) NOT NULL default '',
`coupon_code` varchar(255) NOT NULL default '',
`coupon_value` varchar(50) NOT NULL default '',
`expired_counpon` datetime NOT NULL,
`content` text NOT NULL default '',
`file` text NOT NULL default '',
`comment` text NOT NULL default '',
`latest_message` text NOT NULL default '',
`latest_response` text NOT NULL default '',
`latest_response_time` datetime,
`status` tinyint(1) NOT NULL DEFAULT '3',
`is_sent` tinyint(1) NOT NULL DEFAULT '2',
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`feedback_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE {$this->getTable('magenotification_extension_feedbackmessage')} (
`feedbackmessage_id` int(11) unsigned NOT NULL auto_increment,
`feedback_id` int(11) unsigned NOT NULL,
`feedback_code` varchar(255) NOT NULL default '',
`user` varchar(255) NOT NULL default '',
`is_customer` tinyint(1) default '2',
`message` text NOT NULL default '',
`file` text NOT NULL default '',
`posted_time` datetime NULL,
`is_sent` tinyint(1) default '2',
PRIMARY KEY (`feedbackmessage_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup();
You have to learn how to create custom module in magento for more information.
custom module with database

mysql selecting data from a table

I have an Users Table with a staff column and a remove column.
I don't want to show Users that have the remove column with the value of 1
SELECT *
FROM Users
WHERE
Users.staff = 1
AND Users.remove != 1
I don't get an error but my code doesn't work.
this is the schema
CREATE TABLE `Users` (
`userId` int(11) unsigned NOT NULL AUTO_INCREMENT,
`fullName` varchar(50) DEFAULT NULL,
`firstName` varchar(25) NOT NULL DEFAULT '',
`lastName` varchar(25) NOT NULL DEFAULT '',
`address` varchar(50) NOT NULL DEFAULT '',
`city` varchar(25) DEFAULT NULL,
`state` char(2) DEFAULT NULL,
`zipCode` varchar(25) DEFAULT NULL,
`email` varchar(50) NOT NULL DEFAULT '',
`cellPhone` varchar(15) DEFAULT NULL,
`birthDate` date NOT NULL,
`creditCard` varchar(250) NOT NULL DEFAULT '',
`subscriptionStarted` date NOT NULL,
`subscriptionEnded` date NOT NULL,
`basicPlan` tinyint(1) DEFAULT NULL,
`standardPlan` tinyint(1) DEFAULT NULL,
`premiumPlan` tinyint(1) DEFAULT NULL,
`remove` tinyint(1) DEFAULT NULL,
`staff` tinyint(1) DEFAULT NULL,
`admin` tinyint(1) DEFAULT NULL,
`systemAdmin` tinyint(1) DEFAULT NULL,
`edited` datetime DEFAULT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1;
both work for me Boss.
create table users
( staff int not null,
remove int not null
);
insert users (staff,remove) values (1,0);
insert users (staff,remove) values (1,1);
insert users (staff,remove) values (2,0);
insert users (staff,remove) values (2,1);
SELECT *
FROM Users
WHERE
Users.staff = 1
AND Users.remove != 1
SELECT *
FROM Users
WHERE
Users.staff = 1
AND Users.remove <> 1
Edit due to nullability:
SELECT * FROM Users
WHERE staff=1
and remove <> 1 or remove is null
SELECT * FROM Users
WHERE staff=1
and remove is not null

MySQL: referencing foreign keys

I am trying to reference a foreign key to its parent key in mysql and i get an awkward error.
I have tried the following.
ALTER TABLE `website`
ADD CONSTRAINT `website_cms_fk1` FOREIGN KEY (`cms_id`) REFERENCES `cms_technology` (`ID`);
also
ALTER TABLE website ADD FOREIGN KEY (cms_id) REFERENCES cms_technology (ID)
And I get the following error.
*#1005 - Can't create table 'script.#sql-5203_110b8ba' (errno: 150)*
The following is my tables
CREATE TABLE IF NOT EXISTS `cms_technology` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`cms_name` varchar(250) NOT NULL DEFAULT '',
`cms_description` varchar(250) NOT NULL DEFAULT '',
PRIMARY KEY (`ID`)
);
INSERT INTO `cms_technology` (`ID`, `cms_name`, `cms_description`) VALUES
(1, 'Wordpress', 'WordPress › Blog Tool, Publishing Platform, and CMS');
CREATE TABLE IF NOT EXISTS `website` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`website_url` varchar(60) NOT NULL DEFAULT '',
`website_ip` varchar(20) NOT NULL DEFAULT '',
`website_title` varchar(250) NOT NULL DEFAULT '',
`website_status` varchar(10) NOT NULL DEFAULT '',
`website_scanned` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`website_response` int(3) NOT NULL DEFAULT '0',
`cms_id` int(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`)
);
INSERT INTO `website` (`ID`, `website_url`, `website_ip`, `website_title`, `website_status`, `website_scanned`, `website_response`, `website_cms`) VALUES
(1, 'http://www.wpbeginner.com/', '', '', '', '0000-00-00 00:00:00', 0, 0);
What im I doing wrong?
you need to change the data type of the of column cms_ID from table website in order to reference table cms_technology. The properties of the to columns must be the same.
CREATE TABLE IF NOT EXISTS `website` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`website_url` varchar(60) NOT NULL DEFAULT '',
`website_ip` varchar(20) NOT NULL DEFAULT '',
`website_title` varchar(250) NOT NULL DEFAULT '',
`website_status` varchar(10) NOT NULL DEFAULT '',
`website_scanned` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`website_response` int(3) NOT NULL DEFAULT '0',
`cms_id` bigint(20) unsigned NOT NULL, -- <<== HERE
PRIMARY KEY (`ID`)
);
SQLFiddle Demo
I was missing the KEY cms_id (cms_id)
CREATE TABLE IF NOT EXISTS `website` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`website_url` varchar(60) NOT NULL DEFAULT '',
`website_ip` varchar(20) NOT NULL DEFAULT '',
`website_title` varchar(250) NOT NULL DEFAULT '',
`website_status` varchar(10) NOT NULL DEFAULT '',
`website_scanned` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`website_response` int(3) NOT NULL DEFAULT '0',
`cms_id` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `cms_id` (`cms_id`)
);
ALTER TABLE `website`
ADD CONSTRAINT `website_cms_fk1` FOREIGN KEY (`cms_id`) REFERENCES `cms_technology` (`ID`);