Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: error in php

Original Message
Name: BigShow
Date: April 2, 2008 at 14:08:46 Pacific
Subject: error in php
OS: xm
CPU/Ram: pentium
Model/Manufacturer: 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



Report Offensive Message For Removal

Response Number 1
Name: Laler
Date: April 2, 2008 at 15:17:08 Pacific
Subject: error in php
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 2
Name: BigShow
Date: April 3, 2008 at 06:49:01 Pacific
Subject: error in php
Reply: (edit)
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?


Report Offensive Follow Up For Removal

Response Number 3
Name: Michael J (by mjdamato)
Date: April 3, 2008 at 11:17:38 Pacific
Subject: error in php
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 4
Name: Laler
Date: April 3, 2008 at 13:49:26 Pacific
Subject: error in php
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 5
Name: Laler
Date: April 3, 2008 at 13:59:12 Pacific
Subject: error in php
Reply: (edit)
---
Fubar


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: error in php

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC