Page 1 of 2
Parse Error
Posted: Fri Aug 12, 2005 3:21 am
by crazycaddy
I'm stumped with this code:
Code: Select all
$delete = if($_SESSION['permission']==yes){ echo '<a href=\"proe/info/delete.php?name=$name\">-Delete</a>'; } else { };
I keep getting a parse error and i'm not sure why, ive tried playing around with the ' and " and also using \ in different places but no luck
Anyone have a suggestion? Or even better an answer to this problem

Posted: Fri Aug 12, 2005 4:32 am
by shiznatix
i dont think you can assign a variable to a if conditional
Code: Select all
$delete = ($_SESSION['permission']==yes) ? '<a href=\"proe/info/delete.php?name=$name\">-Delete</a>' : '');
echo $delete;
try that
Posted: Fri Aug 12, 2005 4:47 am
by crazycaddy
nope still a parse error. I should of really mentioned that it is posting to a file, and I want it to check for the sessions when the file is displayed, ive got this work with this code:
Code: Select all
$delete = "if ($ad){";
$del1 = "}";
$content = "<TR><TD><font face=verdana size=1px>$utilid</font></TD><TD><font face=verdana size=1px>$utilname</font></TD><TD><font face=verdana size=1px>$utildes</font></TD><TD><font face=verdana size=1px><a href='$utilurl' target='blank'>$utilurl</a></font></TD><? $delete ?><TD border='0'><font face=verdana size=1px><a href=\"util.php?action=del&ID=$utilid&URL=$utilurl\">delete</a></TD></TR><? $del1?>
";
Now that works fine, its just when i check for sessions I get the parse errors

Posted: Fri Aug 12, 2005 5:14 am
by shiznatix
crazycaddy wrote:
Code: Select all
$delete = "if ($ad){";
$del1 = "}";
$content = "<TR><TD><font face=verdana size=1px>$utilid</font></TD><TD><font face=verdana size=1px>$utilname</font></TD><TD><font face=verdana size=1px>$utildes</font></TD><TD><font face=verdana size=1px><a href='$utilurl' target='blank'>$utilurl</a></font></TD><? $delete ?><TD border='0'><font face=verdana size=1px><a href="util.php?action=del&ID=$utilid&URL=$utilurl">delete</a></TD></TR><? $del1?>
";
i have no idea what you are doing there. if you want to check for a session do somtin like
Code: Select all
echo (false !== isset($_SESSION['permission']) ? '<a href="delete.php">Delete</a>' : '');
dont assign that to a variable or anything just put that code in.
but the code you said works...what are you doing with that? that really does not much any sence.
Posted: Fri Aug 12, 2005 5:19 am
by crazycaddy
its an odd way of doing things but, what it does is add a table row html code (<tr> etc) to utillist.php and another page displays it. I dont want the session to be checked in that code, but rather in utillist.php.
Posted: Fri Aug 12, 2005 5:22 am
by shiznatix
Code: Select all
$delete = ($_SESSION['permission'] == 'yes' ? '<a href="proe/info/delete.php?name=$name">-Delete</a>' : '');
sorry the original code was missing the '' around the yes
Posted: Fri Aug 12, 2005 5:54 am
by crazycaddy
well that works (writes to the file successfully) but it parses during the 'writing to the file' so the delete link will ALWAYS show as it was posted by someone whos session was authenticated.
Posted: Fri Aug 12, 2005 5:56 am
by feyd
why dynamically create a file when you could dynamically be the file?
Posted: Fri Aug 12, 2005 6:07 am
by crazycaddy
Ive done that on some of the scripts, you see ive had the task of creating a whole intranet without the aid of mysql. This way seemed to be the simplest, but I guess I was wrong

. Ill try now just exploding text files with a similar format to : bob | jim etc.
Posted: Fri Aug 12, 2005 7:23 am
by crazycaddy
OK I came up with this:
Code: Select all
<?php
$data = file('downloads/util/utillist.php');
$data = array_reverse($data);
foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
echo '<tr><td><a href=\"$pieces[2]\">$pieces[0]</a></td><td>$pieces[1]</td><td>Delete</td>';
}
?>
But it justs prints $pieces[2] etc rather than parsing. Ive tried using the php tags around them but I just get parse errors

Posted: Fri Aug 12, 2005 7:41 am
by feyd
you're using a single quote string. Single quote strings do not parse any variables contained inside them.
Posted: Fri Aug 12, 2005 8:02 am
by crazycaddy
Thanks that worked (but im sure I tried using " " earlier), but this just keeps getting better

. How can I check for the session in here without causing a parse error:
Code: Select all
echo "<tr><td><a href=\"$pieces[2]\">$pieces[0]</a></td><td>$pieces[1]</td><td>--Here--</td>";
heres the code i want to 'impliment' :
Code: Select all
if($_SESSION['permission']==yes){
echo'<a href=\"downloads/util/delete.php?name=$pieces[0]\">';
}
else {}
Posted: Fri Aug 12, 2005 8:11 am
by feyd
options:
- check to see if $pieces is empty, if so, fill it with enough empty elements
- check if $pieces is empty inside the if, if so, output something different.
you may need to check the individual elements of $pieces too, so be careful..
Posted: Fri Aug 12, 2005 9:05 am
by crazycaddy
I found a workaround,
but guess what?
more problems

.
before I used to write to the file very 'dodgeleleley' as i opened it with W but it didnt wipe the whole file each time, it just added it at the end. But now its decided to work

. I tried changing the variable to 'a' but it doesnt write anymore.
Code: Select all
<?php
$name = $_POST['name'];
$des = $_POST['des'];
$url = $_POST['url'];
$content = "$name|$des|$url";
$file = fopen("utillist.php", "r");
$read = fread($file, filesize("utillist.php"));
fclose($file);
$blah = fopen("utillist.php", "a");
fwrite($blah, "$content $read");
fclose ($blah);
print'<META HTTP-EQUIV="Refresh" CONTENT="2; URL=../../index.php?id=1">';
?>
Posted: Fri Aug 12, 2005 9:18 am
by feyd
your code reads the entire file and prepends the addition.. why not continue using 'w' ?