Jump to content

lonesoac0

New Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by lonesoac0

  1. Hello all,

     

              I am interested in creating a very simple form that onclick it adds a new record to my table.  Can I accomplish this task with the basic code that I have on the line with "Button Type" ?  I am totally open to different methods too.

    <?php
    $servername = "localhost";
    $username = "bleh";
    $password = "password";
    $dbname = "logger";
    
    try {
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        // set the PDO error mode to exception.
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
        // sql to select last record inserted.
        foreach($conn->query('select status from comins_and_goins order by id DESC limit 1') as $row) {
        $var = $row['status'];
    }
        if ($var == 1) {
            echo "You are going to work or somewhere else for a while.";
            echo '<button type="button" onclick="MySQL query that inserts record.">Click Me</button>';
        }
        else{
            echo "You are back home!  I missed you!";
        }
    }
    catch (PDOExecption $e)
        {
        echo $sql . "<br>" . $e->getMessage();
        }
    
    $conn = null;
    ?>
    

      On a side note, I also feel that I need to acknowledge the foreach statement is a little redundant for the MySQL syntax that I am executing on the same line.  I figured, it works and I just want my new toy operational ASAP. ;)

  2. Thank you soo much for pointing out my bad code!  I caught the <?php part first time but I 100% missed the other two errors.  After those were corrected I actually managed select and submit my data.  The information is actually showing correct as well.  It is no longer 0's but the actual id field value! Thank you guys!

  3. So, yeah.  I added the code of:
     
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
     
    to both of my php pages.  I have attached them and the message I now get when I try to reload the settings_table.php page.
     
    Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in[/size]/var/www/whos_turn/php/settings_table.php on line [/size]5

    Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in [/size]/var/www/whos_turn/php/settings_table.php on line [/size]5
    Connection Failed[/size]

     

    I am using a password, but for security reasons I removed it.

    testing.php

    settings_table.php

  4. Hello all,

     

        I am really new to PHP coding and what it can do.  I recently found an example of how to populate HTML select boxes based off of information contained in MySQL tables.  After I select and submit from my page I get an error code of just Error.  I know that my php code is just telling me something went wrong but I have no idea.  At one time I had it to where the PHP form was submitting data but in my table the value was always 0 even though I was selecting different records within the table.  Some how I managed to lose that code.  I have attached the two php pages that I am trying to pass values from page to another and the MySQL table layouts that I am using.

     

    My code will never see the light of the WWW so security is not an issue.

    showing_table_layout.txt

    testing.php

    settings_table.php

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.