Whenever I try to create a new table with this...
CREATE TABLE IF NOT EXISTS `users` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(300) NOT NULL UNIQUE,
`password` varchar(300) NOT NULL,
`activation` varchar(300) NOT NULL UNIQUE,
`status` enum('0','1') NOT NULL DEFAULT '0',
PRIMARY KEY (`uid`)
)
I get a pop up that says. Missing value in the form!. I've tried looking for answers, but most of them say to disable Ajax, which I cannot do. I've also tried different browsers and nothing seems to work. I'm using phpMyAdmin 4.1.6
varchar must have no more than 255 character, and you set is 300 character
look at this ( https://dev.mysql.com/doc/refman/5.0/en/char.html )
Related
Continuation from this question:
PDO query updating a datetime column not in query
A column in my table called lastLoginDate was being automatically updated even though my prepared statement did not include said column.
Apparently, when I created the new column, a trigger was set.
Upon using the command SHOW CREATE TABLE table_name, I returned the following results:
CREATE TABLE `users_edi` (
`username` varchar(30) NOT NULL DEFAULT '',
`fullname` varchar(50) DEFAULT NULL,
`userlevel` tinyint(1) unsigned NOT NULL,
`ipaddress` varchar(30) DEFAULT NULL,
`email` varchar(150) DEFAULT NULL,
`entrydate` datetime DEFAULT NULL,
`division` varchar(35) DEFAULT NULL,
`password` varchar(32) DEFAULT NULL,
`userid` varchar(32) DEFAULT NULL,
`timestamp` int(11) unsigned NOT NULL,
`job_title` varchar(30) DEFAULT NULL,
`dept` varchar(50) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`lastLoginDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, // <-- here
PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
The table is years old. I just created the column and somehow, a trigger was set to it (I guess).
Regardless, I tried to remove it using the following command:
ALTER TABLE `users_edi`
`lastLoginDate` datetime DEFAULT NULL
But I only get the following error:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`lastLoginDate` datetime DEFAULT NULL' at line 4
How do I remove this trigger using the ALTER TABLE command or any other command?
ALTER TABLE users_edi MODIFY COLUMN lastLoginDate DATETIME DEFAULT NULL;
You might like to read this page on ALTER TABLE: https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
I really need help on this and couldn't find any previous questions related to my problem so here I am.
I have a registration form which is split up into 3 stages and therefore 3 tables. Keep in mind I have indexed and created foreign key constraints in phpmyadmin.
First stage is users (table):
CREATE TABLE `dbtest`.`users`(
`user_id` INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`email` VARCHAR(35) NOT NULL,
`password` VARCHAR(50) NOT NULL,
UNIQUE(`email`)
) ENGINE = INNODB;
When a user fills in the first stage and the data is posted into the database and first user_id becomes 1. The user is then redirected onto the next stage (table):
CREATE TABLE `dbtest`.`personal`(
`player_id` INT(5) NOT NULL,
`first` VARCHAR(35) NOT NULL,
`last` VARCHAR(35) NOT NULL,
`mobile` INT(12) NOT NULL,
`parentmobile` INT(12) NOT NULL,
`gender` VARCHAR(6) NOT NULL,
`address` VARCHAR(50) NOT NULL,
`city` VARCHAR(25) NOT NULL,
`postcode` VARCHAR(10) NOT NULL,
`county` VARCHAR(35) NOT NULL,
`country` VARCHAR(35) NOT NULL,
PRIMARY KEY(mobile)
) ENGINE = INNODB;
When he fills in this form all the data gets posted into the database however player_id is 0 not 1. My question is how do I pass the user_id from stage 1 to player_id in stage 2. I have attached pictures my code.
PHP code for Stage 1:
PHP code for Stage 2:
I do not know php, but I have faced similar problems in other languages. What you want, is the id of the last inserted row, right? And then use it to insert the other related parts of the registration.
All you really need to know, is how to find the id:
Object oriented style
mixed $mysqli->insert_id;
Procedural style
mixed mysqli_insert_id ( mysqli $link )
Reference and more info: http://php.net/manual/en/mysqli.insert-id.php
Hi any one please help i have a contact table in which i can Insert,Delete,Modify database using PHP web pages....but only current changes will be updated to database. what i want is how i can maintain history of database...
Is there any tutorial for this using (PHP/MYSQL).
I tried creating version of MySQL table for patient... how to proceed further.
CREATE TABLE IF NOT EXISTS `contact` (
`name` varchar(30) NOT NULL,
`phone` varchar(12) NOT NULL,
`mobile` varchar(12) NOT NULL,
`email` varchar(30) NOT NULL,
`address` text NOT NULL,
`conid` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`conid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; # MySQL returned an empty result set (i.e. zero rows).
CREATE TABLE IF NOT EXISTS `contactversion` (
`name` varchar(30) NOT NULL,
`phone` varchar(12) NOT NULL,
`mobile` varchar(12) NOT NULL,
`email` varchar(30) NOT NULL,
`address` text NOT NULL,
`conid` int(11) NOT NULL,
`revision_id` int(11) AUTO_INCREMENT,
type ENUM('INSERT', 'UPDATE', 'DELETE') NOT NULL,
`change_time` DEFAULT current_timestamp,
PRIMARY KEY (`revision_id`)
);
what to do next....
When running the queries to contact, just simply run this right before to take the current contact and copy it in your revision table...
"INSERT INTO
contactversion (name,phone,mobile,email,address,conid,type)
SELECT
name,phone,mobile,email,address,conid,'".$type."' as type
FROM contact
WHERE conid='".$conid."'"
Both tables will require to be identical, with contactversion having type and change_time as additionnal last columns.
It is obvious that this query should be ran before UPDATE and DELETE of the contact table, but after an INSERT. If you are updating multiple contacts with another where clause than the conid, you'll want to consider building the where statement in a variable to use it inside the INSERT's SELECT and the UPDATE/DELETE
While creating contactversions table make sure conid should not be primary key and auto incremented. I hope that is causing the problem.
I have database structure like this.
CREATE TABLE IF NOT EXISTS `addreminde` (
`SMSId` int(11) NOT NULL AUTO_INCREMENT,
`UserId` int(11) NOT NULL,
`SendFrom` varchar(20) NOT NULL,
`SendTo` varchar(400) NOT NULL,
`Message` varchar(400) NOT NULL,
`ReminderTime` datetime NOT NULL,
`Status` varchar(400) DEFAULT NULL,
`datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`SMSId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15;
So i am storing the ReminderTime in database.
Now want to know how i can send a email or (let say execute a php script ) to "SendTo" at the "ReminderTime"
Any help will be appreciated.
This cannot be done in PHP. PHP only comes to 'live' when a user makes a request to the webserver.
As mentioned, a cron job is the way to go. And a query ones a minute and sending some email will not be a big load for your server.
currently I am in the process of structuring a database for a site I am creating. However, I have come across a problem. I want to log the amount of times a user has logged in each day, and then be able to keep track of that info over large periods of time such as a 8 months, a year, 2 years, etc.
The only way I can think of right now, is to just have a column for each day of the year/automatically create a column each day. This idea however, just seems plain stupid to me. I'm sure there has to be a better way to do this, I just can't think of one.
Any suggestions?
Thanks,
Rob
Create a separate table where you store user_id, and datetime the user logs in.
Averytime the user logs in, you insert a new record on this table.
Example:
CREATE TABLE user_activity (
userid varchar(50),
log_in_datetime datetime
);
Here is a login table I use for one of my sites. The datetime can either be logged as a datetime or as a timestamp. If you use datetime make sure to consider the timezone of your mysql server.
There is plenty of stuff to track. Then you can just query it later. Each of these column names should be self explanatory with a google search.
CREATE TABLE `t_login` (
`id_login` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_user` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`id_visit` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'fk to t_visit',
`id_org` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`when_attempt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`uname_attempt` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'attempted username' COLLATE 'latin1_swedish_ci',
`valid_uname` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'valid username',
`valid_uname_pword` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'valid username and valid password together',
`pw_hash_attempt` BINARY(32) NOT NULL DEFAULT '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0',
`remote_ip` CHAR(20) NOT NULL DEFAULT '' COLLATE 'latin1_swedish_ci',
`user_agent` VARCHAR(2000) NOT NULL DEFAULT '' COLLATE 'latin1_swedish_ci',
PRIMARY KEY (`id_login`),
INDEX `when_attempt` (`when_attempt`),
INDEX `rempte_ip` (`remote_ip`),
INDEX `valid_user` (`valid_uname`),
INDEX `valid_password` (`valid_uname_pword`),
INDEX `username` (`uname_attempt`),
INDEX `id_ten` (`id_org`),
INDEX `id_user` (`id_user`),
INDEX `id_visit` (`id_visit`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=429;