Announcement

Collapse
No announcement yet.

Error when using PHP to access a MySQL Database

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error when using PHP to access a MySQL Database

    Hi! I tried a few different examples to use a php script to get data from a MySQL database because external access is not allowed. But I could not make it work, yet. Is anyone experienced with PHP/MySQL and can take a look at my code please?

    I have a db with a table containing username+serial+hardwareid+blocked and want to check the entered name+serial (maybe hardwaareid) and get the data from the database. Then the app will check if blocked is 0 or 1 to unlock the app.

    I tried the video tutorial example with the phonebook (http://www.indigorose.com/products/a...deo-tutorials/) but the php manual says some of the used functions are deprecated. I tried the old code and new code but I always get an "Undefined variable" error.

    The Code (commented is old code):
    PHP Code:
    <?php
    error_reporting
    (E_ALL);

    //connect
    //$link = mysql_connect("db516590485.db.1and1.com","dbo516590485","B4SqWaSyX82DB");
    //mysql_select_db("db516590485",$link);

    // NEUER CODE
    // mysqli
    $mysqli = new mysqli("host""user""pass""dbname");
    $result $mysqli->query("SELECT * FROM TABLE WHERE Name=".$username." AND Serial=".$serial);
    $data $result->fetch_assoc();
        foreach(
    $data as $key => $value) {
        
    $myData .= $value.";;";
        }
        
    //if($username != "" && $serial != "") {
    //    $query = "SELECT * FROM CWLP WHERE Name=".$username." AND Serial=".$serial;
    //    $result = mysql_query($query,$link);

    //    while($data = mysql_fetch_assoc($result)) {
    //    foreach($data as $key => $value) {
    //    $myData .= $value.";;";
        //}
    //}

    echo $myData;
    //}



    ?>
    I tried adding " $username = $_POST['username']; $serial = $_POST['serial'];" but this did not help either. (worked in another example. Error messages says undefined index instead of variable)

    The Error:
    Code:
    Notice: Undefined variable: username in /homepages/29/xxx/htdocs/sites/b/apps/cwlp/checkserial.php on line 11
    
    Notice: Undefined variable: serial in /homepages/29/xxx/htdocs/sites/b/apps/cwlp/checkserial.php on line 11
    
    Fatal error: Call to a member function fetch_assoc() on a non-object in /homepages/29/xxx/htdocs/sites/b/apps/cwlp/checkserial.php on line 12
    Button Code:
    Code:
    httpresult = HTTP.Submit("http://www.playbird.at/sites/b/apps/cwlp/checkserial.php", {username="test", serial="testserial"}, SUBMITWEB_GET, 20, 80, nil, nil);
    I tried it in the browser with this line:
    http://playbird.at/sites/b/apps/cwlp...ial=testserial
    Last edited by Bl4ckSh33p; 02-24-2014, 07:29 AM.
    Bl4ckSh33p-Soft - Custom Software and Indie Games

  • #2
    If you submit your data via GET, then you can't use $_POST[] to retrieve the fields. Instead, use $_GET[] or $_REQUEST[].
    You will still find PHP code using globally registered variables, but for years this feature is disabled by default. Perhaps you should get a PHP tutorial to get better acquainted with the language.

    Ulrich

    Comment


    • #3
      This is air code but it will get your started.
      PHP Code:
      <?php
      error_reporting
      (E_ALL);
      if (isset(
      $_REQUEST['username']) && isset($_REQUEST['serial']){
          
      $mysqli = new mysqli("host""user""pass""dbname");
          
      $result $mysqli->query("SELECT * FROM TABLE WHERE Name = '" $_REQUEST['username'] . "' AND Serial='" $_REQUEST['serial'] . "'");
          
      $data $result->fetch_assoc();
          foreach(
      $data as $key => $value) {
              
      $myData .= $value.";;";
          }
              echo 
      $myData;
      }else{
          echo 
      'Woop\'s what happened there then?';
      }
      ?>
      The php Post option is used more for when you have posted to a file from a html form, as I use this in a installer I am working for a php script.
      Last edited by kingzooly; 02-26-2014, 01:18 PM. Reason: added more
      Plugins or Sources MokoX
      BunnyHop 2021 Here

      Comment


      • #4
        Thank you very much! I will try it with your example.
        Bl4ckSh33p-Soft - Custom Software and Indie Games

        Comment

        Working...
        X