View Full Version : News script echoing array

05-26-2011, 02:04 AM
Is there something I did wrong in this script? Its echoing the word Array at the top of the page and keeps refreshing even though my account's level is 4. I've tried <=4 and !==4 but neither seem to work. It also echoes "news successfully added once the page has loaded without any info being entered into the form.

include "/home/xtraz/public_html/test/includes/database.php";
$level = "SELECT level from users WHERE userid='" . $_SESSION['userid'] . "'";
$result = mysql_query($level) or die ('Error: '.mysql_error ());
echo (mysql_fetch_array($result));
if($level !=4)
echo "<meta http-equiv='refresh' content='0;url='http://test.xtraz.cz.cc/'>";

<form name="news" action="" method="post">
<input type="text" name="title" value="Title" />
<textarea rows="2" cols="20" name"news">
<input type="submit" value="Submit" />

$query = "INSERT INTO news(title, news, date) VALUES('$_POST[title]','$_POST[news]', NOW())";
print "News successfully added.";

05-26-2011, 02:42 AM
mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both

^ that's the reason it's echoing an Array based on your

echo (mysql_fetch_array($result));

instead, do a


Based on my comments below, I doubt you wanted to do an echo in the first place. I believe what you wanted to achieve was retrieve the value of the "level" field from the result set and assign it to the $level variable.

if($level !=4)

will ALWAYS occur because you're testing

"SELECT level from users WHERE userid='" . $_SESSION['userid'] . "'";

against the value 4.
Just do an

echo $level;

before your "if" conditional; basic preliminary test.

I'd suggest you go back and look up some basic tutorial on SQL queries. Should fix your problem. And before attempting anything else, try to do a simple query (like

SELECT * FROM users WHERE userid = 1;
) and print out the result to the screen. Once you get that part sorted out then you can move on.