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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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