quick syntax annoyancy

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toms100
Forum Contributor
Posts: 119
Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK

quick syntax annoyancy

Post by toms100 »

:oops: :twisted: bah i cant work this one out!
Parse error: parse error in /home/toms100/public_html/dl/admin/action/addmirror.php on line 50

offending article:

Code: Select all

<?php
		$db = new DbClass();
		$db->connectdb();
		$sql = "INSERT INTO " . $config['dbprefix'] . "mirrors (`name`,`weburl`,`ftp`,`password`,`username`,`path`) VALUES ('" . $name . "','" . $weburl ."','" . $ftp['host'] . "','" . $ftp['pass'] . "','" . ftp['name'] . "','" . $ftp['path'] . "')" ; /// <---- Line 50
		$db->exe($sql);

?>
probably something obvious!
but ive been workin for hour or two and im tired and cant see what it is!

thanks for help:)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

If you use heredocs, it drastically cuts down on the number of times you have to concatenate strings:

Code: Select all

$sql = <<<SQL
INSERT INTO
  $config['dbprefix']mirrors
(
  'name',
  'weburl',
  'ftp',
  'password',
  'username',
  'path'
 )
VALUES
 (
  '$name',
  '$weburl',
  '$ftp[host]',
  '$ftp[pass]',
  '$ftp[name]',
  '$ftp[path]'
 )
SQL;
I've never personally used backticks to delineate elements in SQL queries. I always thought the only use for the backtick was as an operator to execute a shell command. Try removing the backticks and replacing them with single quotes.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

backticks represent db vars, single quotes represent page vars/text
User avatar
llanitedave
Forum Commoner
Posts: 78
Joined: Thu Jan 15, 2004 11:24 am
Location: Las Vegas, NV.

Post by llanitedave »

I may be off the wall on this, but shouldn't:

$sql = "INSERT INTO " . $config['dbprefix'] . "mirrors ...

be

$sql = "INSERT INTO ".$config['dbprefix']." mirrors ...

?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

nope, spaces don't matter
Post Reply