Jump to content

Recommended Posts

[code]
<?php
$image = "<a href=\"test.php\"><img src=\"images/standards/\"{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";
?>
[/code]
I am not totally sure why it doesn't go through it tells me expected ] but I have went over it about 4 times.  I normally don't have a problem setting up url's sometimes even 3-4 times longer than this.

Here is the full code.

[code]<?php
session_start();
include 'db.inc'; // include here
/* Below here I reformatted slightly so I could read it better, change what you need */
$sql = 'SELECT * FROM `fyswilson_art` WHERE 1 LIMIT 0, 300 ';
if (!($connection = @ mysql_pconnect("localhost",
"#####", "######"))) {
    showerror();
}// added quotes and brackets
// added quotes and brackets for the 2 below
if (!mysql_select_db("db162100635", $connection)) {
    showerror();
}
       
if (!($result = @ mysql_query ($sql, $connection))) {
    showerror();
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Wilson Art</title>
</head>
<body>
<div style="width:200px;"><!-- Contains left view -->
<?php
// because of the nature of this program, it might take a lot of tweaking, so I
// prepared the ground work slightly different.  Here I am starting by
// trapping each individual section of the program in a variable, and combining
// them in a master variable to allow me to display everything that goes on the left
// with one variable.  This allows me to single out broken code, or what's causing
// problems, or make changes, it also saves a little server load with performance.
while ($row = mysql_fetch_array($result)) {
$image = "<a href=\"test.php\"><img src=\"images/standards/\"{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";
echo $image;
}
?>

</div><!-- Ends Left View -->
<div><!-- Contains right view -->
</div><!-- Ends right view -->
</body>
</html>[/code]
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/
Share on other sites

What is the exact error?

I can see one problem:
$image = "<a href=\"test.php\"><img src=\"images/standards/[b]\"[/b]{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";

The bit in bold closes the src attribute but it looks to be like the following part should be apart of it.
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76171
Share on other sites

[code]
<?php
$image = "<a href=\"test.php\"><img src=\"images/standards/{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";
?>
[/code]
That is my modified code by the way I found 1 issue in it earlier, but the only thing is, it's giving me the same error,  It seems to be telling me it's around the alt somewhere, when I cut up the url into 3 different variables it singles out the one that starts the alt, but I want them all together either way.
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76172
Share on other sites

Yes, I had just caught that one, and I also split up the url in 3 sections to single out that area, but for some reason it's still telling me

[quote]Parse error: parse error, unexpected T_STRING, expecting ']' in /homepages/30/d162063315/htdocs/zcart/fys/test.php on line 35[/quote]
I just don't understand why it's not working.
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76174
Share on other sites

How the hell.  I have been taught this whole time

[quote]"when Extrapolation variables, you DO NOT need the single quotes around the name of the variable."[/quote]
Can someone please explain this too me I am confused, it worked, atleast the code works, where I can start making the pictures display, no errors, I always used {$_POST[variable]} when I am extrapolating, why did this happen, this makes me confused.
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76180
Share on other sites

[code]
<?php
$image = "<a href='test.php'><img src='images/standards/".$row[lam_number]-$row[lam_name]."_40.gif' alt='$row[1am_name]' /></a>";
?>
[/code]

Give that a try, im not quite sure if your use of {} was causing a problem. I also replaced the escaped double quotes with singles to make it a bit easier to see if there was a problem
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76184
Share on other sites

[quote author=businessman332211 link=topic=104619.msg417367#msg417367 date=1155822170]
How the hell.  I have been taught this whole time

[quote]"when Extrapolation variables, you DO NOT need the single quotes around the name of the variable."[/quote]
Can someone please explain this too me I am confused, it worked, atleast the code works, where I can start making the pictures display, no errors, I always used {$_POST[variable]} when I am extrapolating, why did this happen, this makes me confused.
[/quote]

array?
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76185
Share on other sites

It worked after that, I know it wouldnt have been the { } those are suppose to be used based on the manual, but the $row[variable] was suppose to be used when extrapolating, can someone explain this too me, this has almost knocked me off of my chair, this whole time I have been programming like that, getting into a bad habit, I was told, and read it's best and recommended to use this format when extrapolation

[code]
<?php
{$_POST[variable]}
{$_GET[variable]}
{$row[variable]} // or whatever variable your array was set too?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76187
Share on other sites

Your own post shows pretty much why :)

you have to specify indices by type and when you use braces, you are extrapolating the variable they encompass. Whe using braces, this reverts back to how you must use them on the php scope, as you should be able to see in your example, all three will throw a notice error because PHP will think you are specifying the Constant called 'variable' and not specifying the string value of 'variable'

e.g.:
[code]<?php

$array['var'] = 'foo'; //indice is a String, as denoted by the apostrophies.

$string = "blah $array[var] blah"; //works - 'var' is still a string here, because the variable is within a string.

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76190
Share on other sites

[code]
<?php
$image = "<a href=\"test.php\"><img src=\"images/standards/{$row['lam_number']}-{$row['lam_name']}_40.gif\" alt=\"{$row['1am_name']}\" /></a>";
?>
[/code]

So pretty much what Jenk said, was that $row['lam_number'] is looking for the field name called lam_number

If you want to see the array of $row[]  then use [code=php:0] print_f($row); [/code] and it will show you the names and their values :)

Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76198
Share on other sites

[quote]Ok, so when you use brackets, you need the ' '[/quote]

No... When you use $foo['bar'] within a string you need the brackets, not the other way around.

And [b]all[/b] non numerical array indexes should [b]allways[/b] have quotes around them, they are string indexes so it makes perfect sense. Php howver is pretty forgiving in this area wich means they will work weither way most of the time. This is IMP a design floor.
Link to comment
https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76203
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.