Computing.Net > Forums > Web Development > error in php

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

error in php

Reply to Message Icon

Name: BigShow
Date: April 2, 2008 at 14:08:46 Pacific
OS: xm
CPU/Ram: pentium
Product: del
Comment:

hey guys I am getting an unexpected error message fo the following coed, any ideas...


<body>
<?php
include("includes/open_db.php");


$result = mysql_query("SELECT * FROM index")
or die(mysql_error());


while($row = mysql_fetch_row($result))
{
$leftdiv1 = $row[0];
$leftdiv2 = $row[1];
$leftdiv3 = $row[2];
$contentdiv1 = $row[3];


?>

</body>
</html>


my include file code follows

<?php
$con = mysql_connect("localhost" ,"name","pass") or die(mysql_error());

<?php
mysql_select_db("dbname") or die(mysql_error());
?>


Also, I want to extract some information from the database and echo it out firther down in the code, can I close the <?php nad the nreopen it further down and still have access to the variables?


The error I am getting is

Parse error: syntax error, unexpected $end in /home/psctestc/public_html/sherrilyn/index.php on line 50

line 50 being the closing html tag




Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: April 2, 2008 at 15:17:08 Pacific
Reply:

no closing curly bracket after while()

That error (unexpected $end) is almost always related to forgotten closing curly brackets on if-else statement, while, do, for, foreach, switch, and the likes.


can I close the <?php nad the nreopen it further down and still have access to the variables?

Yes.

---
Fubar


0

Response Number 2
Name: BigShow
Date: April 3, 2008 at 06:49:01 Pacific
Reply:

Hi guys, I am getting real aggravated at this, I think it has something to do with the version of mysql I am running. I can connect to the DB no problem but I cannot retract an info nad display it. Here is some basic code that I used as a test. There is only 1 row within this database table (index) with four fields (leftdiv1, leftdiv2, leftdiv3, contentdiv1) here is the code and error-

<?php

$result = mysql_query("SELECT * FROM index")
or die(mysql_error());


$row = mysql_fetch_array( $result );


echo "Name: ".$row['leftdiv1'];
echo " Age: ".$row['leftdiv2'];
echo "Name: ".$row['leftdiv3'];
echo " Age: ".$row['contentdiv1'];
?>


error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index' at line 1

Any ideaas?


0

Response Number 3
Name: Michael J (by mjdamato)
Date: April 3, 2008 at 11:17:38 Pacific
Reply:

OK, let's think a little logically? What would the version of MySQL have to do with running a basic query? If you can't query a database - then it's not of any use.

The problem is that you picked a reserved word as your table name. 'INDEX' is a database command. You *can* use it as a table name, but I would HIGHLY discourage it.

When referencing a table or column name in a query you can avoid reserved word problems (and it's good practice) by enclosing the name in back quotes.

This query will work, but you really should change the table name (I aslo added some better error handling)

$query = "SELECT * FROM `index`";
$result = mysql_query($query)
or die("The query:[br]$query[br]Produced the error:[br]".mysql_error());

Michael J


0

Response Number 4
Name: Laler
Date: April 3, 2008 at 13:49:26 Pacific
Reply:

Another good practice to stay away from problems like this is to prefix your table names.

It'll also help when you use the database for another application (which tends to have similar table names).

app1_index
app1_users
app2_index
app2_users

--

Also, take a look inside some popular open source apps like WordPress to see how they handle it.

---
Fubar


0

Response Number 5
Name: Laler
Date: April 3, 2008 at 13:59:12 Pacific
Reply:

---
Fubar


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: error in php

Error in PHP Script www.computing.net/answers/webdevel/error-in-php-script/2599.html

mysql_numrows() error in php www.computing.net/answers/webdevel/mysqlnumrows-error-in-php/770.html

enable error reporting in PHP www.computing.net/answers/webdevel/enable-error-reporting-in-php/341.html