Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

error when filling the variables. How to avoid it?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

error when filling the variables. How to avoid it?

Postby Tonkpils » Thu Sep 04, 2003 12:36 am

Hey, this is a part of a script that generates a page where issues from a database are displayed.
Code: Select all
print ("<p align=\"center\"><input type=\"submit\" class=\"button\" name=\"Comments\" value=\"Comments\" onClick=\"MM_openBrWindow('../windowcomments_provv.php?id=".$issno."&des=".$sdes."','','width=580,height=300')\">");

When the variables are filled in in the page, i got an error telling "expecting")"' at line:xxx char:xxx. I checked the page, and this happens on each line where the variable are filled with some ' or ". Any idea on how avoid this?
Tonkpils
New php-forum User
New php-forum User
 
Posts: 19
Joined: Tue Aug 19, 2003 6:11 am
Location: An Italian in Brusssels...

Postby Joel » Thu Sep 04, 2003 12:55 am

I ran that, putting values into the variables, and it ran perfectly. Maybe the problem is in another set of lines?
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

the complete script

Postby Tonkpils » Thu Sep 04, 2003 1:28 am

This is the complete script:
Code: Select all
<?php

$db = mysql_connect("000000000", "root", "xxxxxxxxxx");
mysql_select_db("Support",$db);

$result = mysql_query("SELECT * FROM `issuelist2` where `external_org` LIKE 'TKS' AND problem_number >'2000' AND crstatus !='Closed' AND crstatus != 'User_Informed' AND crstatus != 'Rejected' ",$db);




if ($myrow = mysql_fetch_array($result))
{
do
   {

$issno = $myrow["problem_number"];
$sdes = $myrow["synops"];
$bgcolor = (++$i & 1) ? '#F2F2F2' : '#F9F9F9';

printf ("<table width=\"700\" class=\"bodypage\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\">");
printf ("<tr>");
printf ("<td bgcolor=\"$bgcolor\">");
printf ("<strong>Customer:</strong> %s\n<br>", $myrow["external_org"]);
printf ("<strong>Issue Number:</strong> %s\n<br>", $myrow["problem_number"]);
printf ("<strong>Status:</strong> %s\n<br>", $myrow["crstatus"]);
printf ("<strong>Submitted On:</strong> %s\n<br>", $myrow["Issue_StartDate"]);
printf ("<strong>Priority:</strong> %s\n<br>", $myrow["priority"]);
printf ("<strong>Owner:</strong> %s\n<br>", $myrow["Submitted_id"]);
printf ("<br>");
printf ("<strong>Workstream:</strong> %s\n<br>",$myrow["application"]);
printf ("<strong>Description:</strong> %s\n<br>", $myrow["desc"]);
printf ("<p align=\"center\"><input type=\"submit\" class=\"button\" name=\"Comments\" value=\"Comments\" onClick=\"MM_openBrWindow('../windowcomments_provv.php?id=".$issno."&des=".$sdes."','','width=580,height=300')\">");
printf ("</td>");
printf ("</tr>");
printf ("</table>");
   }
while ($myrow = mysql_fetch_array($result));
}
else {echo "<h5><font color=\"#003066\">Sorry, there are no open issues for the moment</font></h5>";
}
?>
But did you try to fill in some characters like quotes and other that can mess up the html? For instance, a line that i got filled in is like this:
Code: Select all
<br><p align="center"><input type="submit" class="button" name="Comments" value="Comments" onClick="MM_openBrWindow('../windowcomments_provv.php?id=3817&des=Customer can'Gt answer to OTS ','','width=580,height=300')"></td></tr></table><table width="700" class="bodypage" border="0" cellspacing="2" cellpadding="3"><tr><td bgcolor="#F9F9F9"><strong>Customer:</strong> TKS
And moreover, if i delete the line that display the button to open the window from the script, i get the full table result without errors... :? :? :? :?
Tonkpils
New php-forum User
New php-forum User
 
Posts: 19
Joined: Tue Aug 19, 2003 6:11 am
Location: An Italian in Brusssels...

Postby Redcircle » Fri Sep 05, 2003 3:27 pm

I would reccomend using echo for one. It's faster. Also it is better to use single ' . also faster. Only need to use " when displaying a far like "I went to $location"; even that gives me quirks. I usually just use 'I went to '.$location;
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby Joel » Fri Sep 05, 2003 6:20 pm

One thing I noticed about your code was your printfs.

This is how your code should be.

Code: Select all
echo '<strong>Status:</strong> '.$myrow["crstatus"].'\n<br>'.
       '<strong>Submitted On:</strong> '.$myrow['Issue_StartDate']'.\n<br>';


printf() is used for outputting formatted things like

Code: Select all
printf("%.0f", $var);


Which would output $var as a float with 0 dp.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Thanks for the clarifications...

Postby Tonkpils » Sat Sep 06, 2003 3:34 am

But in the meantime, checking our UI guidelines, it was suggesting for this kind of operation to use a link instead of a button. The problem here was that to have a pop up window i was not able to use a sintax to pass the necessary values without messing up the codes. Now i see what i can do, and i'll try to link a pop up window to this link. Thanks all, and... God Bless PHP... :wink:
Tonkpils
New php-forum User
New php-forum User
 
Posts: 19
Joined: Tue Aug 19, 2003 6:11 am
Location: An Italian in Brusssels...

Postby Redcircle » Sat Sep 06, 2003 11:13 am

Try this

Code: Select all
<?php

$db = mysql_connect("000000000", "root", "xxxxxxxxxx");
mysql_select_db("Support",$db);

$result = mysql_query('SELECT * FROM `issuelist2` where `external_org` LIKE "TKS" AND problem_number >"2000" AND crstatus !="Closed" AND crstatus != "User_Informed" AND crstatus != "Rejected"',$db);

if(mysql_num_rows($result))
{
//avoid do while statements.
while ($myrow = mysql_fetch_array($result))
{
   $issno = $myrow["problem_number"]; 
   $sdes = $myrow["synops"]; 
   $bgcolor = (++$i & 1) ? '#F2F2F2' : '#F9F9F9';
echo '
<table width="700" class="bodypage" border="0" cellspacing="2" cellpadding="3">
   <tr>
      <td bgcolor="'.$bgcolor.'">
         <strong>Customer:</strong> '.$myrow['external_org'].'
         <br>
         <strong>Issue Number:</strong> '.$myrow['problem_number'].'
         <br>
         <strong>Status:</strong> '.$myrow['crstatus'].'
         <br>
         <strong>Submitted On:</strong> '.$myrow['Issue_StartDate'].'
         <br>
         <strong>Priority:</strong> '.$myrow['priority'].'
         <br>
         <strong>Owner:</strong> '.$myrow['Submitted_id'].'
         <br> 
         <br>
         <strong>Workstream:</strong> '.$myrow['application'].'
         <br>
         <strong>Description:</strong> '.$myrow['desc'].'
         <br> 
         <p align="center">
         <input type="submit" class="button" name="Comments" value="Comments" onClick="MM_openBrWindow(\'../windowcomments_provv.php?id='.$issno.'&des='.$sdes.'\',\'\',\'width=580,height=300\');">
      </td>
   </tr>
</table>';
   }
 
}
else {
echo '<h5><font color="#003066">Sorry, there are no open issues for the moment</font></h5>';
}
?>
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby Tonkpils » Mon Sep 08, 2003 12:33 am

Thanks, it was better... Now only some of them were giving errors... so i checked out the magic quotes in the INI file, and i change to ON for "magic_quotes_runtime". No more errors... Thanks again guys !!
Tonkpils
New php-forum User
New php-forum User
 
Posts: 19
Joined: Tue Aug 19, 2003 6:11 am
Location: An Italian in Brusssels...


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.