Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help on Insert data to phpMyAdmin

    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:
    PHP Code:
    <?php
    session_start
    ();

    $MySQLUsername "MySQLUsername";
    $MYSQLUsersensor "MYSQLUsersensor";
    $MySQLPassword "MySQLPassword";


    $MySQLHost "localhost";
    $MySQLDB "gpio";
    $MYSQLDBsensor "sensor";

    If ((
    $MySQLUsername == "USERNAME HERE") || ($MySQLPassword == "PASSWORD HERE")){
        print 
    'ERROR - Please set up the script first';
        exit();
    }

    $dbConnection mysql_connect($MySQLHost$MySQLUsername$MySQLPassword);
    mysql_select_db($MySQLDB$dbConnection);
    If (isset(
    $_POST['action'])){
        If (
    $_POST['action'] == "setPassword"){
            
    $password1 $_POST['password1'];
            
    $password2 $_POST['password2'];
            If (
    $password1 != $password2){
                
    header('Location: control.php');
            }
            
    $password mysql_real_escape_string($_POST['password1']);
            If (
    strlen($password) > 28){
                
    mysql_close();
                
    header('location: control.php');
            }
            
    $resetQuery "SELECT username, salt FROM users WHERE username = 'admin';";
            
    $resetResult mysql_query($resetQuery);
            If (
    mysql_num_rows($resetResult) < 1){
                
    mysql_close();
                
    header('location: control.php');
            }
            
    $resetData mysql_fetch_array($resetResultMYSQL_ASSOC);
            
    $resetHash hash('sha256'$salt hash('sha256'$password));
            
    $hash hash('sha256'$password);
            function 
    createSalt(){
                
    $string md5(uniqid(rand(), true));
                return 
    substr($string08);
            }
            
    $salt createSalt();
            
    $hash hash('sha256'$salt $hash);
            
    mysql_query("UPDATE users SET salt='$salt' WHERE username='admin'");
            
    mysql_query("UPDATE users SET password='$hash' WHERE username='admin'");
            
    mysql_close();
            
    header('location: control.php');
        }
    }
    If ((isset(
    $_POST['username'])) && (isset($_POST['password']))){
        
    $username mysql_real_escape_string($_POST['username']);
        
    $password mysql_real_escape_string($_POST['password']);
        
    $loginQuery "SELECT UserID, password, salt FROM users WHERE username = '$username';";
        
    $loginResult mysql_query($loginQuery);
        If (
    mysql_num_rows($loginResult) < 1){
            
    mysql_close();
            
    header('location: control.php?error=incorrectLogin');
        }
        
    $loginData mysql_fetch_array($loginResultMYSQL_ASSOC);
        
    $loginHash hash('sha256'$loginData['salt'] . hash('sha256'$password));
        If (
    $loginHash != $loginData['password']){
            
    mysql_close();
            
    header('location: control.php?error=incorrectLogin');
        } else {
            
    session_regenerate_id();
            
    $_SESSION['username'] = "admin";
            
    $_SESSION['userID'] = "1";
            
    mysql_close();
            
    header('location: control.php');
        }
    }
    If ((!isset(
    $_SESSION['username'])) || (!isset($_SESSION['userID']))){
        print 
    '
        <html>
        <head>
        <title>GPIO Control - Login</title>
        </head>
        <body>
        <table border="0" align="center">
        <form name="login" action="control.php" method="post">
        <tr>
        <td>Username: </td><td><input type="text" name="username"></td>
        </tr>
        <tr>
        <td>Password: </td><td><input type="password" name="password"></td>
        </tr>
        <tr>
        <td colspan="2" align="center"><input type="submit" value="Log In"></td>
        </tr>
        </form>
        </table>
        </body>
        </html>
        '
    ;
        die();
    }
    If (isset(
    $_GET['action'])){
        If (
    $_GET['action'] == "logout"){
            
    $_SESSION = array();
            
    session_destroy();
            
    header('Location: control.php');
        } else If (
    $_GET['action'] == "setPassword"){
            print 
    '
            <form name="changePassword" action="control.php" method="post">
            <input type="hidden" name="action" value="setPassword">
            <p>Enter New Password: <input type="password" name="password1">  Confirm: <input type="password" name="password2"><input type="submit" value="submit"></p>
            </form>
            '
    ;
        } else {
            
    $action $_GET['action'];
            
    $pin mysql_real_escape_string($_GET['pin']);
            if (
    $action == "turnOn"){
                
    $setting "1";
                
    mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='$pin';");
                
    mysql_close();
                
    header('Location: control.php');
            } else If (
    $action == "turnOff"){
                
    $setting "0";
                
    mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='$pin';");
                
    mysql_close();
                
    header('Location: control.php');
            } else IF (
    $action =="edit"){
                
    $pin mysql_real_escape_string($_GET['pin']);
                
    $query mysql_query("SELECT pinDescription FROM pinDescription WHERE pinNumber='$pin';");
                
    $descRow mysql_fetch_assoc($query);
                
    $description $descRow['pinDescription'];
                print 
    '
                <html><head><title>Update Pin ' 
    $pin '</title></head><body>
                <table border="0">
                <form name="edit" action="control.php" method="get">
                <input type="hidden" name="action" value="update">
                <input type="hidden" name="pin" value="' 
    $pin '">
                <tr>
                <td><p>Description: </p></td><td><input type="text" name="description" value="' 
    $description '"></td><td><input type="submit" value="Confirm"></td>
                </tr>
                </form>
                </table>
                </body></html>
                '
    ;
                
    mysql_close();
            } else IF (
    $action =="update"){
                
    $pin mysql_real_escape_string($_GET['pin']);
                
    $description mysql_real_escape_string($_GET['description']);
                
    mysql_query("UPDATE pinDescription SET pinDescription='$description' WHERE pinNumber='$pin';");
                
    header('Location: control.php');
            } else {
                
    header('Location: control.php');
            }
        } else {
                    
    $now = new DateTime();
            
    $action $_POST['action'];
            
    $pin mysql_real_escape_string($_POST['pin']);
            
    $dbConnectionSensor mysql_connect($MySQLHost$MySQLUserSensor$MySQLPassword);
            
    mysql_select_db($MySQLDBSensor$dbConnectionSensor);
            if (
    $action == "turnOn" && "4"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('1', 'Red LED', $now, '')");
            } else If (
    $action == "turnOn" && "17"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('2', 'Blue LED', $now, '')");
            } else If (
    $action == "turnOn" && "18"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('3', 'Green LED', $now, '')");
            } else If (
    $action == "turnOn" && "21"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('4', 'LED', $now, '')");
            } else If (
    $action == "turnOn" && "22"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('5', 'LED', $now, '')");
            } else If (
    $action == "turnOn" && "23"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('6', 'LED', $now, '')");
            } else If (
    $action == "turnOn" && "24"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('7', 'LED', $now, '')");
            } else If (
    $action == "turnOn" && "25"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('8', 'LED', $now, '')");
                
    mysql_close();
                
    header('Location: control.php');
            } else If (
    $action == "turnOff" && "4"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('1', 'Red LED', '', $now)");
            } else If (
    $action == "turnOff" && "17"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('2', 'Blue LED', '', $now)");
            } else If (
    $action == "turnOff" && "18"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('3', 'Green LED', '', $now)");
            } else If (
    $action == "turnOff" && "21"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('4', 'LED', '', $now)");
            } else If (
    $action == "turnOff" && "22"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('5', 'LED', '', $now)");
            } else If (
    $action == "turnOff" && "23"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('6', 'LED', '', $now)");
            } else If (
    $action == "turnOff" && "24"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('7', 'LED', '', $now)");
            } else If (
    $action == "turnOff" && "25"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('8', 'LED', '', $now)");
                
    mysql_close();
                
    header('Location: control.php');
            }
        }
    } else {
        print 
    '
            <html>
            <head>
            <title>GPIO Control</title>
            </head>
            <font face="verdana">
            <p><h1>Sensors</h1></p>
            '
    ;
            
    $query mysql_query("SELECT pinNumber, pinStatus FROM pinStatus;");
            
    $query2 mysql_query("SELECT pinNumber, pinDescription FROM pinDescription;");
            
    $totalGPIOCount mysql_num_rows($query);
            
    $currentGPIOCount 0;
            print 
    '<table name="GPIO" border="1" cellpadding="5">';
            print 
    '<tr><th>GPIO #</th><th>GPIO Description</th><th>Status</th><th>Action</th><th>Edit</th></tr>';
            while (
    $currentGPIOCount $totalGPIOCount){
                
    $pinRow mysql_fetch_assoc($query);
                
    $descRow mysql_fetch_assoc($query2);
                
    $pinNumber $pinRow['pinNumber'];
                
    $pinStatus $pinRow['pinStatus'];
                
    $pinDescription $descRow['pinDescription'];
                If (
    $pinStatus == "0"){
                    
    $buttonValue "Turn On";
                    
    $action "turnOn";
                    
    $image "off.jpg";
                } else {
                    
    $buttonValue "Turn Off";
                    
    $action "turnOff";
                    
    $image "on.jpg";
                }
                print 
    '<tr>';
                print 
    '<td align="center">' $pinNumber '</td><td>' $pinDescription '</td><td align="center"><img src="' $image '" width="50"></td><td align="center" valign="middle"><form name="pin' $pinNumber 'edit" action="control.php" method="get"><input type="hidden" name="action" value="' $action '"><input type="hidden" name="pin" value="' $pinNumber '"><input type="submit" value="' $buttonValue '"></form></td><td><form name="pin' $pinNumber '" action="control.php" method="get"><input type="hidden" name="action" value="edit"><input type="hidden" name="pin" value="' $pinNumber '"><input type="submit" value="Edit"></form></td>';
                print 
    '</tr>';
                
    $currentGPIOCount ++;
            }
            print 
    '</table>';
            
    mysql_close();
        print 
    '
        <br><br>
        <a href="control.php?action=logout">Log Out</a>
        </font>
        </html>
        '
    ;
    }
    ?>
    This is my pinDirection SQL database:
    Code:
        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 ;
    This is my pinStatus SQL database:
    Code:
        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 ;
    This is my sensor SQL database:
    Code:
        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;
    Hope you guys could help me out with it as soon as possible, thanks in advance, guys

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    phpmyadmin is not a database. It is an admin tool to operate on the database and change various things such as values, settings etc. Mysql is the database.

    As for why your queries are failing, typically we use "insert into <table> (columns) values (values)". You're omitting the (columns) part however from vague memories that IS allowed if you're supplying ALL fields with data.

    What you need to do is print the complete query to the screen (including the variables) and then run it in phpmyadmins SQL page for your database. If it has a fault, it will then be displayed here. That or you use the mysql_error() function and print whatever message it returns.
    I can't really think of anything to write here now...

  • #3
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    phpmyadmin is not a database. It is an admin tool to operate on the database and change various things such as values, settings etc. Mysql is the database.

    As for why your queries are failing, typically we use "insert into <table> (columns) values (values)". You're omitting the (columns) part however from vague memories that IS allowed if you're supplying ALL fields with data.

    What you need to do is print the complete query to the screen (including the variables) and then run it in phpmyadmins SQL page for your database. If it has a fault, it will then be displayed here. That or you use the mysql_error() function and print whatever message it returns.
    Thanks a lot, tangoforce xD
    You saved my life xD
    I have tried out the error reporting and I have solved all of the errors, everything working fine now but can't store data now.

    This is my newly edited which have zero errors for PHP:
    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors','On');

    <?php
    session_start
    ();

    $MySQLUsername "gpio";
    $MySQLPassword "kang";

    $MySQLHost "localhost";
    $MySQLDB "gpio";

    If ((
    $MySQLUsername == "USERNAME HERE") || ($MySQLPassword == "PASSWORD HERE")){
        print 
    'ERROR - Please set up the script first';
        exit();
    }

    $dbConnection mysql_connect($MySQLHost$MySQLUsername$MySQLPassword);
    mysql_select_db($MySQLDB$dbConnection);
    If (isset(
    $_POST['action'])){
        If (
    $_POST['action'] == "setPassword"){
            
    $password1 $_POST['password1'];
            
    $password2 $_POST['password2'];
            If (
    $password1 != $password2){
                
    header('Location: control.php');
            }
            
    $password mysql_real_escape_string($_POST['password1']);
            If (
    strlen($password) > 28){
                
    mysql_close();
                
    header('location: control.php');
            }
            
    $resetQuery "SELECT username, salt FROM users WHERE username = 'admin';";
            
    $resetResult mysql_query($resetQuery);
            If (
    mysql_num_rows($resetResult) < 1){
                
    mysql_close();
                
    header('location: control.php');
            }
            
    $resetData mysql_fetch_array($resetResultMYSQL_ASSOC);
            
    $resetHash hash('sha256'$salt hash('sha256'$password));
            
    $hash hash('sha256'$password);
            function 
    createSalt(){
                
    $string md5(uniqid(rand(), true));
                return 
    substr($string08);
            }
            
    $salt createSalt();
            
    $hash hash('sha256'$salt $hash);
            
    mysql_query("UPDATE users SET salt='$salt' WHERE username='admin'");
            
    mysql_query("UPDATE users SET password='$hash' WHERE username='admin'");
            
    mysql_close();
            
    header('location: control.php');
        }
    }
    If ((isset(
    $_POST['username'])) && (isset($_POST['password']))){
        
    $username mysql_real_escape_string($_POST['username']);
        
    $password mysql_real_escape_string($_POST['password']);
        
    $loginQuery "SELECT UserID, password, salt FROM users WHERE username = '$username';";
        
    $loginResult mysql_query($loginQuery);
        If (
    mysql_num_rows($loginResult) < 1){
            
    mysql_close();
            
    header('location: control.php?error=incorrectLogin');
        }
        
    $loginData mysql_fetch_array($loginResultMYSQL_ASSOC);
        
    $loginHash hash('sha256'$loginData['salt'] . hash('sha256'$password));
        If (
    $loginHash != $loginData['password']){
            
    mysql_close();
            
    header('location: control.php?error=incorrectLogin');
        } else {
            
    session_regenerate_id();
            
    $_SESSION['username'] = "admin";
            
    $_SESSION['userID'] = "1";
            
    mysql_close();
            
    header('location: control.php');
        }
    }
    If ((!isset(
    $_SESSION['username'])) || (!isset($_SESSION['userID']))){
        print 
    '
        <html>
        <head>
        <title>GPIO Control - Login</title>
        </head>
        <body>
        <table border="0" align="center">
        <form name="login" action="control.php" method="post">
        <tr>
        <td>Username: </td><td><input type="text" name="username"></td>
        </tr>
        <tr>
        <td>Password: </td><td><input type="password" name="password"></td>
        </tr>
        <tr>
        <td colspan="2" align="center"><input type="submit" value="Log In"></td>
        </tr>
        </form>
        </table>
        </body>
        </html>
        '
    ;
        die();
    }
    If (isset(
    $_GET['action'])){
        If (
    $_GET['action'] == "logout"){
            
    $_SESSION = array();
            
    session_destroy();
            
    header('Location: control.php');
        } else If (
    $_GET['action'] == "setPassword"){
            print 
    '
            <form name="changePassword" action="control.php" method="post">
            <input type="hidden" name="action" value="setPassword">
            <p>Enter New Password: <input type="password" name="password1">  Confirm: <input type="password" name="password2"><input type="submit" value="submit"></p>
            </form>
            '
    ;
        } else {
            
    $action $_GET['action'];
            
    $pin mysql_real_escape_string($_GET['pin']);
            if (
    $action == "turnOn"){
                
    $setting "1";
                
    mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='$pin';");
                
    mysql_close();
                
    header('Location: control.php');
            } else If (
    $action == "turnOff"){
                
    $setting "0";
                
    mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='$pin';");
                
    mysql_close();
                
    header('Location: control.php');
        } else {
            
    $storing $_POST['storing'];
            
    $pin mysql_real_escape_string($_POST['pin']);
            
    $now = new DateTime();
            if (
    $storing == "turnOn"){
                
    $setting "1";
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('1', 'Red LED', $now, '') WHERE pinNumber= '4';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('2', 'Blue LED', $now, '') WHERE pinNumber= '17';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('3', 'LED', $now, '') WHERE pinNumber= '18';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('4', 'LED', $now, '') WHERE pinNumber= '21';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('5', 'LED', $now, '') WHERE pinNumber= '22';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('6', 'Green LED', $now, '') WHERE pinNumber= '23';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('7', 'LED', $now, '') WHERE pinNumber= '24';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('8', 'LED', $now, '') WHERE pinNumber= '25';");
                
    mysql_close();
                
    header('Location: control.php');
            } else If (
    $storing == "turnOff"){
                
    $setting "0";
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('1', 'Red LED', '', $now) WHERE pinNumber= '4';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('2', 'Blue LED', '', $now) WHERE pinNumber= '17';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('3', 'LED', '', $now) WHERE pinNumber= '18';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('4', 'LED', '', $now) WHERE pinNumber= '21';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('5', 'LED', '' $now) WHERE pinNumber= '22';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('6', 'Green LED', '', $now) WHERE pinNumber= '23';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('7', 'LED', '', $now) WHERE pinNumber= '24';");
                
    mysql_query("INSERT INTO sensor('id, 'sensor', 'switchOnLog', 'switchOffLog') Values('8', 'LED', '', $now) WHERE pinNumber= '25';");
                
    mysql_close();
                
    header('Location: control.php');
            } else IF (
    $action =="edit"){
                
    $pin mysql_real_escape_string($_GET['pin']);
                
    $query mysql_query("SELECT pinDescription FROM pinDescription WHERE pinNumber='$pin';");
                
    $descRow mysql_fetch_assoc($query);
                
    $description $descRow['pinDescription'];
                print 
    '
                <html><head><title>Update Pin ' 
    $pin '</title></head><body>
                <table border="0">
                <form name="edit" action="control.php" method="get">
                <input type="hidden" name="action" value="update">
                <input type="hidden" name="pin" value="' 
    $pin '">
                <tr>
                <td><p>Description: </p></td><td><input type="text" name="description" value="' 
    $description '"></td><td><input type="submit" value="Confirm"></td>
                </tr>
                </form>
                </table>
                </body></html>
                '
    ;
                
    mysql_close();
            } else IF (
    $action =="update"){
                
    $pin mysql_real_escape_string($_GET['pin']);
                
    $description mysql_real_escape_string($_GET['description']);
                
    mysql_query("UPDATE pinDescription SET pinDescription='$description' WHERE pinNumber='$pin';");
                
    header('Location: control.php');
            } else {
                
    header('Location: control.php');
            }
        }
    }
    } else {
        print 
    '
            <html>
            <head>
            <title>GPIO Control</title>
            </head>
            <font face="verdana">
            <p><h1>Sensors</h1></p>
            '
    ;
            
    $query mysql_query("SELECT pinNumber, pinStatus FROM pinStatus;");
            
    $query2 mysql_query("SELECT pinNumber, pinDescription FROM pinDescription;");
            
    $totalGPIOCount mysql_num_rows($query);
            
    $currentGPIOCount 0;
            print 
    '<table name="GPIO" border="1" cellpadding="5">';
            print 
    '<tr><th>GPIO #</th><th>GPIO Description</th><th>Status</th><th>Action</th><th>Edit</th></tr>';
            while (
    $currentGPIOCount $totalGPIOCount){
                
    $pinRow mysql_fetch_assoc($query);
                
    $descRow mysql_fetch_assoc($query2);
                
    $pinNumber $pinRow['pinNumber'];
                
    $pinStatus $pinRow['pinStatus'];
                
    $pinDescription $descRow['pinDescription'];
                If (
    $pinStatus == "0"){
                    
    $buttonValue "Turn On";
                    
    $action "turnOn";
                    
    $image "off.jpg";
                } else {
                    
    $buttonValue "Turn Off";
                    
    $action "turnOff";
                    
    $image "on.jpg";
                }
                print 
    '<tr>';
                print 
    '<td align="center">' $pinNumber '</td><td>' $pinDescription '</td><td align="center"><img src="' $image '" width="50"></td><td align="center" valign="middle"><form name="pin' $pinNumber 'edit" action="control.php" method="get"><input type="hidden" name="action" value="' $action '"><input type="hidden" name="pin" value="' $pinNumber '"><input type="submit" value="' $buttonValue '"></form></td><td><form name="pin' $pinNumber '" action="control.php" method="get"><input type="hidden" name="action" value="edit"><input type="hidden" name="pin" value="' $pinNumber '"><input type="submit" value="Edit"></form></td>';
                print 
    '</tr>';
                
    $currentGPIOCount ++;
            }
            print 
    '</table>';
            
    mysql_close();
        print 
    '
        <br><br>
        <a href="control.php?action=logout">Log Out</a>
        </font>
        </html>
        '
    ;
    }
    ?>
    Hope you could help me out with it as soon as possible, thanks in advance.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •