...

View Full Version : Problem getting info from database



elitis
05-11-2011, 12:31 AM
Getting this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/xtraz/public_html/test/news/post_news/index.php on line 4

What exactly does this error mean? A whitespace is a space after an end tag right? What about T_ENCAPSED?


<?php
session_start();
include "database.php";
$level = "SELECT level from user WHERE userid='$_SESSION['userid']'";
$result = mysql_query($level,$con);
echo (mysql_fetch_array($result));
if($level !=4)
{
echo <meta http-equiv='refresh' content="0;url=">;
}
?>

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

<?php
$query = "INSERT INTO news(title, news, date) VALUES('mysql_real_escape_string($_POST[title])','mysql_real_escape_string($_POST[news])', NOW())";
mysql_query($query);
print "News successfully added.";
mysql_close($c);
?>

Old Pedant
05-11-2011, 12:37 AM
Nothing to do with database. That's strictly a PHP syntax issue. You'd have the same error in code unrelated to a database if you made the same error.

I'm *NOT* a PHP person, but I'd guess that PHP is having trouble with your " and ' nesting.

Why not clarify the code, thus:


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

elitis
05-11-2011, 12:40 AM
Nothing to do with database. That's strictly a PHP syntax issue. You'd have the same error in code unrelated to a database if you made the same error.

I'm *NOT* a PHP person, but I'd guess that PHP is having trouble with your " and ' nesting.

Why not clarify the code, thus:


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


Parse error: syntax error, unexpected '<' in /home/xtraz/public_html/test/news/post_news/index.php on line 9

crap, thought this was mysql since it was getting the info from the database

EDIT: Nvm. Fixed that error/ Now getting: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/xtraz/public_html/test/news/post_news/index.php on line 5

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xtraz/public_html/test/news/post_news/index.php on line 6

Old Pedant
05-11-2011, 01:01 AM
Again, I'm not a PHP person, but in this line:


$result = mysql_query($level,$con);

$level can't possibly be an invalid "resource" because it's only a string. But $con well could be invalid.

Normally, in PHP code I see, where the user only has one DB connection per page, the second argument to mysql_query() is omitted, since then mysql will use the default current connection.

You might try that:


$result = mysql_query($level);

elitis
05-11-2011, 01:45 AM
Again, I'm not a PHP person, but in this line:


$result = mysql_query($level,$con);

$level can't possibly be an invalid "resource" because it's only a string. But $con well could be invalid.

Normally, in PHP code I see, where the user only has one DB connection per page, the second argument to mysql_query() is omitted, since then mysql will use the default current connection.

You might try that:


$result = mysql_query($level);



Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xtraz/public_html/test/news/post_news/index.php on line 6

error after error

EDIT: Nvm fixed tht error. But now its echoing array at the top of the page

Old Pedant
05-11-2011, 01:50 AM
Have to get somebody who knows PHP involved, I'm afraid.

You might also need to show the code for the database.php file.

elitis
05-11-2011, 01:58 AM
Have to get somebody who knows PHP involved, I'm afraid.

You might also need to show the code for the database.php file.

the database file is just normal standard code for connecting to the database.

Old Pedant
05-11-2011, 03:02 AM
But now its echoing array at the top of the page

Yes?

What did you expect.

You are doing this:


echo (mysql_fetch_array($result));

You asked it to fetch an array, and then you echoed the array.

And the next line makes less sense:


if($level !=4)

But that will *always* be true.

You previously assigned the *STRING* containing the SQL command to the $level variable.

And that STRING will never be equal to the number 4.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum