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.

Keep getting errmsg array

Discussion in 'PHP' started by mark103, Oct 20, 2010.

  1. #1
    Hey guys,

    I need your help. It took me hours to try and fix the problem as I am still trying to get the data from the mysql database to print into the php page, but I keep getting the error message of the array which it said "data is not found".


    
    <?php
    session_start();
        define('DB_HOST', 'localhost');
        define('DB_USER', 'username');
        define('DB_PASSWORD', 'password');
        define('DB_DATABASE', 'databasename');
           
        $errmsg_arr = array();
        $errflag = false;
    
        $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        if(!$link) {
      die('Failed to connect to server: ' . mysql_error());
        }
    
        $db = mysql_select_db(DB_DATABASE);
        if(!$db) {
      die("Unable to select database");
        }
    
       function clean($var){
    
    return mysql_real_escape_string(strip_tags($var));
        }
      
        $datastrings = clean($_GET['strings1']);
        if($datastrings== '') {
      $errmsg_arr[] = 'data is not found';
      $errflag = true;
        }
        if($errflag) {
      $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
      echo implode('<br />',$errmsg_arr);
       }
       else {
      $query  = "SELECT data_strings FROM table1";
      $result=mysql_query($query) or die('Error:<br />' . $qry . '<br />' . mysql_error());
    
    
    while ($row = mysql_fetch_array($result)) { 
      echo "<p id='data1'>";
      echo $row['data1'] . "</p>";
      }
     }
    ?>
    
    PHP:

    I am sure that the column in the database are valid. The name of the column is data_strings and the table name is called table1.


    Any idea why I keep getting the error message of the array?
     
    mark103, Oct 20, 2010 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    First, are you passing the string1 variable in the URL, as in:

    http://site.com/page.php?strings1=stringyouwant

    Second, your database query is static, never changes. Is that how you want it or do you actually want to use the variable $datastrings in place of the static field data_strings as in:

    
    $query  = "SELECT $datastrings FROM table1";
    
    PHP:
     
    ThePHPMaster, Oct 20, 2010 IP