Jump to content

Keep getting errmsg array


mark103

Recommended Posts

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>";
  }
}
?>

 

 

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?

Link to comment
https://forums.phpfreaks.com/topic/216418-keep-getting-errmsg-array/
Share on other sites

Thanks for your help. I have fixed the problem. However I am getting an error:

 

Parse error: syntax error, unexpected T_ELSE in /home/username/public_html/mysite.com/myscript.php on line 30

 

 

Here it is the line 30:

 

   else {

 

 

And here's the full code:

 

<?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($encryption == 'thestrings') {
  echo "<p id='strings1'>";
  echo $row['strings1'] . "</p>";
   else {
   }
  $URL="http://www.google.com";
  header ("Location: $URL");
    }
    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());
}
}
?>

 

Do you know why I am getting an error?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.