1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help on Insert data to phpMyAdmin mySQL database

Discussion in 'PHP' started by aoiregion, Jul 18, 2014.

  1. #1
    Hi guys, I would like to seek help on inserting data whenever the switch is on or off to my sensor mySQL database in phpMyAdmin from my control.php. I'm using Raspberry PI as my hardware and follow a few tutorials to create my own Web Control Interface, it works perfectly without insert method. After I implemented insert method to my control.php and execute it, it cannot works and cannot store.

    This is my control.php:
    This is my pinDirection SQL database:
    
    DROP TABLE IF EXISTS `pinDirection`;
    CREATE TABLE IF NOT EXISTS `pinDirection` (
      `pinID` int(11) NOT NULL AUTO_INCREMENT,
      `pinNumber` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
      `pinDirection` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
      PRIMARY KEY (`pinID`),
      UNIQUE KEY `pinNumber` (`pinNumber`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=9 ;
    
    Code (markup):
    This is my pinStatus SQL database:
    
    DROP TABLE IF EXISTS `pinStatus`;
    CREATE TABLE IF NOT EXISTS `pinStatus` (
      `pinID` int(11) NOT NULL AUTO_INCREMENT,
      `pinNumber` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
      `pinStatus` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
      PRIMARY KEY (`pinID`),
      UNIQUE KEY `pinNumber` (`pinNumber`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=9 ;
    
    Code (markup):
    This is my sensor SQL database:
    
    CREATE TABLE IF NOT EXISTS `sensor` (
      `id` int(11) NOT NULL,
      `sensor` text NOT NULL,
      `switchOnLog` datetime NOT NULL,
      `switchOffLog` datetime NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    Code (markup):
    Hope you guys could help me out with it as soon as possible, thanks in advance, guys
     
    aoiregion, Jul 18, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Well-Known Member

    Messages:
    1,761
    Likes Received:
    178
    Best Answers:
    66
    Trophy Points:
    160
    #2
    First off, you should look into not using mysql_ - use mysqli_ or PDO to connect to the database, and prepared queries - first off, they're a lot safer, and the amount of code needed is quite a bit less.
    Second, you should provide proper error-messages instead of just reloading files and such. For a login-script, the better is to just have the processing and the form in the same file, displaying error-messages if there's an error during login (wrong password, or similar).
     
    PoPSiCLe, Jul 18, 2014 IP
  3. aoiregion

    aoiregion Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Quite complicated, PoPSiCLe.
    Could you guide me if you don't mind cause I'm lost now, PoPSiCLe.
     
    aoiregion, Jul 18, 2014 IP
  4. aoiregion

    aoiregion Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    This is my latest edited code where I found out that I set my POST in GET and I have amended it already but the problem is still there.
     
    aoiregion, Jul 19, 2014 IP