Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL probelm with PHP

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
When I do this action, I get a parse error:

Code:
if ($action == 'do_display') {

include 'data/config.php';

$dbh = mysql_connect($server,$dbusername,$dbpassword);
mysql_select_db($dbase,$dbh);
$err = mysql_error();
if ($err){
   echo CPMessage("Error in database: $err");
   exit;
};

DROP TABLE IF EXISTS guestbook_display;
CREATE TABLE guestbook_display (
  displayid int(1) unsigned NOT NULL default '1',
  status varchar(6) NOT NULL default '',
  email varchar(150) NOT NULL default '',
  name varchar(150) NOT NULL default '',
  link1name varchar(150) NOT NULL default '',
  link1url varchar(150) NOT NULL default '',
  link2name varchar(150) NOT NULL default '',
  link2url varchar(150) NOT NULL default '',
  entriesperpage varchar(150) NOT NULL default '',
  ipdisplay varchar(8) NOT NULL default '',
  PRIMARY KEY (displayid)
) TYPE=MyISAM;

INSERT INTO guestbook_display VALUES 
(1,$GBStatus,'$GuestbookEmail','$GuestbookName','$Link1Name'
,'$Link1URL','$Link2Name','$Link2URL','$MaxPerPage','$IPDisp
lay');

echo CPMessage("Display setting updated!");

exit;

}

What's wrong? I've tried to get it to work, but no luck.
 
where is the parse error?

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Why do you drop and re-create the tables, you can use:
DELETE FROM guestbook_display;

this will delete everything and leave the table intact. ***************************************
Party on, dudes!
[cannon]
 
k, thanks. I'll do that after. I'm just trying to find out why I'm getting that error first.
 
try this for size:

$dbh = mysql_connect($server,$dbusername,$dbpassword) or die ('cannot connect to database');
mysql_select_db($dbase,$dbh) or die ('cannot select database');
$err = mysql_error();
if ($err){
echo "Error in database: $err";

} ***************************************
Party on, dudes!
[cannon]
 
Parse error: parse error in /home/puremadnezz/php/cal/data/admin_updating.php on line 42

Same line as before. :-(
 
post the whole page of code please :) ***************************************
Party on, dudes!
[cannon]
 
HOW ABOUT running actual queries?

$query="DROP TABLE IF EXISTS guestbook_display";
mysql_query($query);

CREATE TABLE guestbook_display (
displayid int(1) unsigned NOT NULL default '1',
status varchar(6) NOT NULL default '',
email varchar(150) NOT NULL default '',
name varchar(150) NOT NULL default '',
Link1name varchar(150) NOT NULL default '',
Link1url varchar(150) NOT NULL default '',
Link2name varchar(150) NOT NULL default '',
Link2url varchar(150) NOT NULL default '',
entriesperpage varchar(150) NOT NULL default '',
ipdisplay varchar(8) NOT NULL default '',
PRIMARY KEY (displayid)
) TYPE=MyISAM";
mysql_query($query);

$query="
INSERT INTO guestbook_display VALUES
(1,$GBStatus,'$GuestbookEmail','$GuestbookName','$Link1Name'
,'$Link1URL','$Link2Name','$Link2URL','$MaxPerPage','$IPDisp
lay')";
mysql_query($query);
 
Okay: here's me code this far:

Code:
if ($action == 'do_display') {

include 'data/config.php';

$dbh = mysql_connect($server,$dbusername,$dbpassword) or die ('cannot connect to database');
mysql_select_db($dbase,$dbh) or die ('cannot select database');
$err = mysql_error();
if ($err){
   echo "Error in database: $err";

}

$query="DROP TABLE IF EXISTS guestbook_display";
mysql_query($query);

$query="CREATE TABLE guestbook_display (
  displayid int(1) unsigned NOT NULL default '1',
  status varchar(6) NOT NULL default '',
  email varchar(150) NOT NULL default '',
  name varchar(150) NOT NULL default '',
  Link1name varchar(150) NOT NULL default '',
  Link1url varchar(150) NOT NULL default '',
  Link2name varchar(150) NOT NULL default '',
  Link2url varchar(150) NOT NULL default '',
  entriesperpage varchar(150) NOT NULL default '',
  ipdisplay varchar(8) NOT NULL default '',
  PRIMARY KEY (displayid)
) TYPE=MyISAM";
mysql_query($query);

$query="
INSERT INTO guestbook_display VALUES 
(1,$GBStatus,'$GuestbookEmail','$GuestbookName','$Link1Name'
,'$Link1URL','$Link2Name','$Link2URL','$MaxPerPage','$IPDisp
lay')";
mysql_query($query);

echo CPMessage("Display setting updated!");

exit;

}

Okay, I have a problem. I think it does the first part by dropping the table, then recreating it, but it doesn't do the INSERT INTO command. It says 'this table contains no data'. How do I fix this? :)
 
Thanks, everyone for the replies. I fixed it!

Code:
$query="
INSERT INTO guestbook_display VALUES 
(1,$GBStatus,'$GuestbookEmail','$GuestbookName','$Link1Name'
,'$Link1URL','$Link2Name','$Link2URL','$MaxPerPage','$IPDisp
lay')";
mysql_query($query);

I just forgot some '' around $GBStatus. *slaps head*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top