parse error when calling a database

He has: 688 posts

Joined: Feb 2001

All I want to do is display the data from one table of one mySQL database, in a column-sortable method and I just keep running into walls. I've tries a dozen scripts and the only one that worked kept crashing. Aaaaahhhhh Mad

I used phpMyEdit to create some code which should access my mySQL data. But when I run the page it gives me this error:

Quote: Parse error: parse error, unexpected '=' in /home/pstvalu/public_html/phpMyEdit/index.php on line 22

Here's the code:

<?php
echo('xml version=\"1.0\"'.\"\n\")
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>alumni</title>
<link type=\"text/css\" href=\"alumni.css\"
rel=\"stylesheet\" />
</head>
<body>
<div class=\"main\">
<h3>alumni</h3>

// MySQL host name, user name, password, database,
and table to edit
$hn='localhost';
$un='XXXXXXXXX';
$pw='XXXXXXXXX';
$db='XXXXXXXXX';
$tb='alumni';
// Name of field which is the unique key
$key='';
// Type of key field (int/real/string/date etc)
='';
// Number of records to display on the screen
$inc = 15;
// Options you wish to give the users - A(dd) C(hange)
D(elete) F(ilter)
// I(nitial sort suppressed)
$options = 'ACDF';
// Number of lines to display on multiple selection filters
$multiple = '4';
//
// Field definitions. Fields will be displayed left to right
// on the screen in the order in which they appear in
this list.
// ['name'] is the title used for column headings, etc.;
// ['width'] is an optional display width specification for
the column,
// e.g. ['width'] = '100px';
// ['format'] is optional for date fields only to specify
sequence
// and delimiter for day, month, year; e.g. for 25 April
2001:
// ['format']='mdy/' would give '04/25/01' and
// ['format']='dmy.' would give '25.04.01'
// ['sort'] = true means the users may sort the display
on this column;
// ['URL]' is used to make a field 'clickable' in the
display,
// e.g. ['URL'] = 'mailto:' or ['URL'] = 'http://';
// ['required'] = true will generate javascript to prevent
null entries
// by users
// ['options'] is an optional parameter to control whether
a field is
// displayed in the A(dd), C(hange), D(elete), or L(ist)
views
// ['textarea']['rows'] and/or ['textarea']['cols'] specifies a
// textarea is to be used to give multi-line input,
// e.g. ['textarea']['rows'] = 5; ['textarea']['cols'] = 10
// ['values'] restricts user input to the specified
constants,
// e.g. ['values'] = array('A','B','C')
// ['values']['table'] and ['values']['column'] restricts user
// input to the values found in the specified column of
another table.
// If the optional ['values']['description'] is also specified,
// the values displayed to the user by PHPMyEdit will
be taken from the
// column specified by 'description'.
// e.g. ['values']['table']='mytable'
// ['values']['column']='key_column'
// ['values']['description']
='result_column' /*optional*/
// ['select'] = 'T/D/M' (text, drop-down, or multiple
selection for filters)
//
$fdd['Last Name']['name'] = 'Last Name';
$fdd['Last Name']['sort'] = true;
$fdd['Last Name']['select'] = 'T';
$fdd['Last Name']['required'] = true;
$fdd['Last Name']['textarea']['rows'] = 5;
$fdd['Last Name']['textarea']['cols'] = 50;
$fdd['First Name']['name'] = 'First Name';
$fdd['First Name']['sort'] = true;
$fdd['First Name']['select'] = 'T';
$fdd['First Name']['required'] = true;
$fdd['First Name']['textarea']['rows'] = 5;
$fdd['First Name']['textarea']['cols'] = 50;
$fdd['Class']['name'] = 'Class';
$fdd['Class']['sort'] = true;
$fdd['Class']['select'] = 'T';
$fdd['Class']['required'] = true;
$fdd['Position']['name'] = 'Position';
$fdd['Position']['sort'] = true;
$fdd['Position']['select'] = 'T';
$fdd['Position']['required'] = true;
$fdd['Position']['textarea']['rows'] = 5;
$fdd['Position']['textarea']['cols'] = 50;
$fdd['Employer']['name'] = 'Employer';
$fdd['Employer']['sort'] = true;
$fdd['Employer']['select'] = 'T';
$fdd['Employer']['required'] = true;
$fdd['Employer']['textarea']['rows'] = 5;
$fdd['Employer']['textarea']['cols'] = 50;
$fdd['City']['name'] = 'City';
$fdd['City']['sort'] = true;
$fdd['City']['select'] = 'T';
$fdd['City']['required'] = true;
$fdd['City']['textarea']['rows'] = 5;
$fdd['City']['textarea']['cols'] = 50;
$fdd['State']['name'] = 'State';
$fdd['State']['sort'] = true;
$fdd['State']['select'] = 'T';
$fdd['State']['required'] = true;
$fdd['State']['textarea']['rows'] = 5;
$fdd['State']['textarea']['cols'] = 50;
$fdd['E-mail']['name'] = 'E Mail';
$fdd['E-mail']['sort'] = true;
$fdd['E-mail']['select'] = 'T';
$fdd['E-mail']['required'] = true;
$fdd['E-mail']['textarea']['rows'] = 5;
$fdd['E-mail']['textarea']['cols'] = 50;
$fdd['Phone']['name'] = 'Phone';
$fdd['Phone']['sort'] = true;
$fdd['Phone']['select'] = 'T';
$fdd['Phone']['required'] = true;
$fdd['Phone']['textarea']['rows'] = 5;
$fdd['Phone']['textarea']['cols'] = 50;
$fdd['Last Updated']['name'] = 'Last Updated';
$fdd['Last Updated']['sort'] = true;
$fdd['Last Updated']['select'] = 'T';
$fdd['Last Updated']['required'] = true;
$fdd['Last Updated']['textarea']['rows'] = 5;
$fdd['Last Updated']['textarea']['cols'] = 50;
// and now the all-important call to PHPMyEdit
// warning - beware of case-sensitive operating systems!
require 'PHPMyEdit.inc';
$labels=array
('Prev','Add','Change','Delete','Next','Page','Records',
'Save','More','Cancel','record added','record
changed','record deleted','Please enter');
$MyForm = new PHPMyEdit ($hn, $un, $pw, $db, $tb,
$key, $key_type, $inc, $options,
$multiple, $fdd, $labels);
$MyForm -> execute();

</div>
</body>
</html>
?>

If I'm correct, the part of this code creating the error are as follows:

// Type of key field (int/real/string/date etc)
='';

Is there something wrong in my code?

Here are some extra notes which may help.
I don't have a unique ID or a Key because I have no idea what those are or how to add them. The phpMyEdit wizard gave me the choice to choose "no unique id" so I did.
When I created this mySQL table I uploaded data from a simple text file without really knowing what I was doing. The table does work fine in phpMyAdmin but I'm not sure if there was anything wrong with the "structure" I chose for the table attributes.

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

You have line breaks after your comment lines like this:
// displayed in the A(dd), C(hange), D(elete), or L(ist)
views

So what happens is that it doesn't see views as a comment and gives you the parse error. Put the comments on the same line or put a // in front of them and that will fix it.

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

He has: 688 posts

Joined: Feb 2001

Okay. I did what you said by adding "// " before many of the lines that looked like they were broken onto a second line. My parse error went away. Thanks.

Now I'm getting other errors. You can see the page and it's errors here. I can include that "PHPMyEdit.inc" file that the errors keep mentioning, but I thought it may be easier if somebody could tell me how I can find out where lines 793 and 952 were in that file without me counting all of them. (This is something I've wondered for a long time)

Thanks

(I'm so close to making this work...)

They have: 447 posts

Joined: Oct 1999

first off, by using the .inc extension your code is viewable to the world:
http://www.pstvalumni.com/phpMyEdit/PHPMyEdit.inc

if you have passwords or sensitive information in there anyone can see it.

second, you can get rid of the division by zero warnings by replacing line 952 with
   echo '    <td>&nbsp;'.$this->labels[5].': '.(($this->inc > 0)?(($this->fm/$this->inc)+1):0).' / '.Ceil((($this->inc > 0)?$total/$this->inc:0)).'</td>'."\n";'

that won't necessarily make it work, but it will get rid of the errors. it looks like maybe it's failing to connect to the database.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.