Reply
isset & fwrite
Old 08-06-2008, 06:49 PM isset & fwrite
Korzonek's Avatar
Skilled Talker

Posts: 60
Name: Michael
Location: Warsaw
Simple problem. I have a form where I fill in the value of $ing1 & $ing2. Then it's sent to page witch creates another page but containig the values from the form page.
This part of the script should check if I entered $ing1 and when I would, it should write all dose thing.(fwrite and all)...if not it should leave out the fwrite things and go to the second if(ing2),or fwrite all those thing and go to the second $ing2...can any one tell me what I'm doing wrong??because it's not working

if (isset($ing1))
{
fwrite($file,'$ing1');fwrite($file,'<br></br>');fwrite($file,'<br></br>');
}
else {break;}

if (isset($ing2))
{
fwrite($file,'$ing2');fwrite($file,'<br></br>');fwrite($file,'<br></br>');
}
else {break;}
Korzonek is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 08-06-2008, 07:15 PM Re: isset & fwrite
Extreme Talker

Posts: 153
I think you might need....

if(isset($_POST['$ing1']))
{

}

since the data is coming form a form, you need to grab at it with the $_POST
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 08-07-2008, 03:35 AM Re: isset & fwrite
Korzonek's Avatar
Skilled Talker

Posts: 60
Name: Michael
Location: Warsaw
dont think so cause I have
$ing1=$_POST[ingredient1];

at the top of the script...I think it's something to do with the break or so...
I've tried if(isset($_POST['$ing1'])) but I get:

Fatal error: Cannot break/continue 1 level in /home/muddler/ftp/admin_add_drink.php on line 126
Korzonek is offline
Reply With Quote
View Public Profile
 
Old 08-07-2008, 09:11 AM Re: isset & fwrite
wayfarer07's Avatar
Power Hungry Seamonkey

Posts: 2,630
Name: Abel Mohler
Location: Asheville, North Carolina USA
There is nothing wrong with your if() statement or your fwrite(). We will have to see the rest of the script to know what is wrong.

Try echoing data in the various steps of the script to see if it is being returned correctly.

BTW, what is <br></br> supposed to mean? That is a self-closing tag.

Last edited by wayfarer07 : 08-07-2008 at 09:12 AM.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 08-07-2008, 09:37 AM Re: isset & fwrite
tripy's Avatar
Do not try this at home!

Posts: 2,818
Name: Thierry
Location: Latitude 46.79057 :: Longitude 7.119377
Quote:
Fatal error: Cannot break/continue
The problem is that "break;" is valid only in a "switch" statement.
http://php.net/switch
You have to either replace your if/elseif/else with a switch(), or to write it in a way that you can break out of the function at those point.

But I'm 80% confident that you can simply remove the "else" part, and that it will work.
You surely copied this bit of code from a switch statement.
__________________
Trust me, I know what's good for you...

tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-07-2008, 12:17 PM Re: isset & fwrite
Korzonek's Avatar
Skilled Talker

Posts: 60
Name: Michael
Location: Warsaw
still not working I've tried the switch and without else but still nothing. I would paste the whole code but there's really no need.

switch(isset($ing1)){
fwrite($file,'<a class="menu" href="http://www.websitte.eu/alkohole/');
fwrite($file,$ing1);
fwrite($file,'.php">');
fwrite($file,$ing1);
fwrite($file,'</a>');
fwrite($file,'&nbsp;&nbsp;');
fwrite($file,$ml1);
fwrite($file,'<br/>');
}else
{break;}

switch(isset($ing2)){
fwrite($file,'<a class="menu" href="http://www.websitte.eu/alkohole/');fwrite($file,$ing2);fwrite($file,'.php">');
fwrite($file,$ing2);fwrite($file,'</a>');fwrite($file,'&nbsp;');fwrite($file,$ml2);
c}else
{break;}

(...)

as you can see it's just a "writing script". The only wrong thing is fwrite($file,'<br/>');. This script writes ingidients and after every ingridient there is a <br/>.The problem is that sometimes the number of ing. varies and it looks awful when the script leaves blanks spaces when nothing is entered(from form).So i wanted it to check if something is writen and write or just dont write anything...but I'm still no where near.
Korzonek is offline
Reply With Quote
View Public Profile
 
Old 08-07-2008, 01:11 PM Re: isset & fwrite
tripy's Avatar
Do not try this at home!

Posts: 2,818
Name: Thierry
Location: Latitude 46.79057 :: Longitude 7.119377
You did not read the documentation page...
You use switch the wrong way.
PHP Code:
switch(isset($ing1)){
  case 
true:
    
fwrite($file,'<a class="menu" href="http://www.websitte.eu/alkohole/');
     
fwrite($file,$ing1);
     
fwrite($file,'.php">');
    
fwrite($file,$ing1);
     
fwrite($file,'</a>');
     
fwrite($file,'&nbsp;&nbsp;');
     
fwrite($file,$ml1);
     
fwrite($file,'<br/>');
    break;
default:
    break;

But it does little sense to put a switch where there are not several case possible...
Or, using an if:
PHP Code:
if(isset($ing1)){
  
fwrite($file,'<a class="menu" href="http://www.websitte.eu/alkohole/');
   
fwrite($file,$ing1);
   
fwrite($file,'.php">');
   
fwrite($file,$ing1);
   
fwrite($file,'</a>');
   
fwrite($file,'&nbsp;&nbsp;');
   
fwrite($file,$ml1);
   
fwrite($file,'<br/>');

__________________
Trust me, I know what's good for you...

tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-07-2008, 02:51 PM Re: isset & fwrite
Korzonek's Avatar
Skilled Talker

Posts: 60
Name: Michael
Location: Warsaw
yes I know...it dosen't make a lot of sens ...but still, I've tried just "if" ealier(didn't work) and now your idea with switch and it dosent work also...((and I dont understand why....
I ve got it working!!!!)) if it would help any one and thx for help!!!

if(!empty($ing1))
{
fwrite($file,'<a class="menu" href="http://www.mysite.eu/alkohole/');
fwrite($file,$ing1);
fwrite($file,'.php">');
fwrite($file,$ing1);
fwrite($file,'</a>');
fwrite($file,'&nbsp;&nbsp;');
fwrite($file,$ml1);
fwrite($file,'<br/>');
}

Last edited by Korzonek : 08-08-2008 at 07:07 AM.
Korzonek is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to isset & fwrite
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.11947 seconds with 12 queries