mark103 Posted October 20, 2010 Share Posted October 20, 2010 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? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 20, 2010 Share Posted October 20, 2010 $_GET['strings1'] is probably empty. Echo it, and you should have your answer. Quote Link to comment Share on other sites More sharing options...
mark103 Posted October 20, 2010 Author Share Posted October 20, 2010 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? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 20, 2010 Share Posted October 20, 2010 It looks like the else { should be on the next line, after the } not before it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.