Page 1 of 1

quick syntax annoyancy

Posted: Thu Feb 26, 2004 3:18 pm
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:)

Posted: Thu Feb 26, 2004 3:50 pm
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.

Posted: Thu Feb 26, 2004 5:54 pm
by d3ad1ysp0rk
backticks represent db vars, single quotes represent page vars/text

Posted: Thu Feb 26, 2004 6:45 pm
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 ...

?

Posted: Thu Feb 26, 2004 6:50 pm
by d3ad1ysp0rk
nope, spaces don't matter