Jump to content


Photo

Parse error: syntax error, unexpected


Best Answer Ch0cu3r, 06 October 2013 - 04:51 AM

Couldn't you posted the above 4 posts into one post?  :shrug:

 

But anyway you're using the wrong logical operator in dynamic-form.php

<?php
$cat=$_REQUEST['cate'];
if($cat==1 && $cat==2 && $cat==3 && $cat==4)
{
require_once('OrderStatus.php');
}  
elseif ($cat==5 && $cat==6)
{
require_once('NoVal1.php');
}
?>

The && (and operator) should be changed to the || (or operator). 

Go to the full post


  • Please log in to reply
11 replies to this topic

#1 Nsm

Nsm

    Member

  • Members
  • PipPip
  • 12 posts

Posted 05 October 2013 - 03:07 PM

Hi,

I can't find the error in this code:
 

<?php
$cat=$_REQUEST['cate'];
if($cat==1 && $cat==2 && $cat==3 && $cat==4)
{
require_once('OrderStatus.php');
}  
elseif ($cat==5 &amp;&amp; $cat==6)
{
require_once('NoVal1.php');
}
?>

Error:Parse error: syntax error, unexpected

What am I doing wrong?


 


#2 .josh

.josh

    .josh

  • Staff Alumni
  • 14,831 posts

Posted 05 October 2013 - 03:30 PM

&amp;&amp; is that really what your code is? need to change that to &&

Did I help you? Feeling generous? Donate to me! || Donate to phpfreaks!
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 ShivaGupta

ShivaGupta

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts
  • Locationindia
  • Age:21

Posted 05 October 2013 - 03:36 PM

 

Hi,

I can't find the error in this code:
 

<?php
$cat=$_REQUEST['cate'];
if($cat==1 && $cat==2 && $cat==3 && $cat==4)
{
require_once('OrderStatus.php');
}  
elseif ($cat==5 && $cat==6)
{
require_once('NoVal1.php');
}
?>

Error:Parse error: syntax error, unexpected

What am I doing wrong?


 

 

this is a best option to post code  <>

 

 

see magic

<?php
$cat=$_REQUEST['cate'];
if($cat==1 && $cat==2 && $cat==3 && $cat==4)
{
require_once('OrderStatus.php');
}  
elseif ($cat==5 && $cat==6)
{
require_once('NoVal1.php');
}
?>

Edited by ShivaGupta, 05 October 2013 - 03:38 PM.


#4 Nsm

Nsm

    Member

  • Members
  • PipPip
  • 12 posts

Posted 05 October 2013 - 04:12 PM

Thanks for your reply but that did no do me any good.

Let me be more specific.

I use existing scripts  and try to modify them to my needs.

I started a new project and learn as a go.

 

What i want to chieve is the following:

If sales district 1 - 4 is selected Display OrderStatus.
If sales disrict  5 0r 6 is selected Display NoVal1

This Is my index page:
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dynamic field creation in PHP</title>
 
<script type="text/javascript" src="jquery.js"></script>
<script language="javascript">
function getXMLHTTP()
{
var xmlhttp=null;
try {
xmlhttp=new XMLHttpRequest();
}
catch(e)
{
try {
xmlhttp=new ActiveXobject("Microsoft.XMLHTTP");
}
catch(e)
{
try {
xmlhttp=new ActiveXObject("msxml2.XMLHTTP");
}
catch(e1)
{
xmlhttp=false;
}
}
}
return xmlhttp;
}
var strurl="dynamic-form.php?cate="+cat;
var req=getXMLHTTP();
function getCat(cat) {
//alert(cat);
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle"> loading.....');
var strurl="dynamic-form.php?cate="+cat;
//alert(strurl);
var req=getXMLHTTP();
if(req==null)
{
alert("browser error");
}
if(req)
{
req.onreadystatechange=function() {
if(req.readyState ==4 || req.readyState=="complete") {
               $("#flash").hide();
document.getElementById("ajaxresult").innerHTML=req.responseText;
}
}
req.open("GET",strurl,true);
req.send(null);
}
}
</script>
</head>
 
<body>
<div style="text-align:center;">
<div style="display:none;"><img src="ajax-loader.gif"  /></div>
  <h1 style="color:#CCC;">VAT WORKFLOW</h1></div>
 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td width="10%">TODAYS DATE</td>
        <td width="10%">
<?php
echo date("d/m/Y");
?>
</td>
        <td width="25%">&nbsp;</td>
        <td width="25%">&nbsp;</td>
    </tr>
    <tr>
        <td width="10%">SALES DISTRICT</td>
        <td width="10%"><label>
      <select name="select" id="select"  onChange="getCat(this.value)">
        <option value="" selected="selected">Select Sales District</option>
        <option value="1">IN05</option>
        <option value="2">IN02</option>
        <option value="3">IN23</option>
        <option value="4">IN13</option>
<option value="5">EDU</option>
<option value="6">EPP</option>
      </select></label></td>
        <td width="25%">&nbsp;</td>
        <td width="25%">&nbsp;</td>
    </tr>
    <tr>
        <td width="1317" colspan="4">
<div id="flash"></div>
        <div id="ajaxresult"></div></td>
    </tr>
</table>
 
 
</body>

</html>

 

 

I edit the dynamic-form.php file to:

 

 

<?php

$cat=$_REQUEST['cate'];
if($cat==1 && $cat==2 && $cat==3 && $cat==4)
{
require_once('OrderStatus.php');
}  
elseif ($cat==5 && $cat==6)
{
require_once('NoVal1.php');
}
?>

OrderStatus.php File:
 

<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th width="10%" align="left" valign="middle"><strong>ORDER STATUS</strong></td>
<th width="10%" align="left" valign="middle"><label>
      <select name="select" id="select">
        <option value="" selected="selected">Select Order Status</option>
        <option value="1">Open</option>
        <option value="2">Shipped</option>
        <option value="3">Open &amp; Shipped</option>
        </select>
    </label></td>
<th width="25%">&nbsp;</td>
<th width="25%">&nbsp;</td>
</tr>
</table>
 
 
NoVal1.php File:

<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th>DO NOT VALIDATE<br> STICKEY:</td>
<th width="25%">&nbsp;</td>
<th width="25%">&nbsp;</td>
</tr>
</table>  
 
I appreciate your help.

Thanks
 


#5 cyberRobot

cyberRobot

    Advanced Member

  • Gurus
  • 1,811 posts

Posted 05 October 2013 - 07:22 PM

Are we still talking about a parse error...or is this a new question?

 

Also, please surround your code blocks with [code][/code] tags. It makes the post (and code) easier to read.  :happy-04:


Blogging about PHP and other web-related topics at ScorpBytes.com


#6 Nsm

Nsm

    Member

  • Members
  • PipPip
  • 12 posts

Posted 06 October 2013 - 04:32 AM

When option 1 , 2, 3 or 4 in the following dropdownlist:

<label>
      <select name="select" id="select"  onChange="getCat(this.value)">
        <option value="" selected="selected">Select Sales District</option>
        <option value="1">IN05</option>
        <option value="2">IN02</option>
        <option value="3">IN23</option>
        <option value="4">IN13</option>
<option value="5">EDU</option>
<option value="6">EPP</option>
      </select></label>


#7 Nsm

Nsm

    Member

  • Members
  • PipPip
  • 12 posts

Posted 06 October 2013 - 04:34 AM

is selected I want it to display:

 

OrderStatus.php File:

<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th width="10%" align="left" valign="middle"><strong>ORDER STATUS</strong></td>
<th width="10%" align="left" valign="middle"><label>
      <select name="select" id="select">
        <option value="" selected="selected">Select Order Status</option>
        <option value="1">Open</option>
        <option value="2">Shipped</option>
        <option value="3">Open &amp; Shipped</option>
        </select>
    </label></td>
<th width="25%">&nbsp;</td>
<th width="25%">&nbsp;</td>
</tr>
</table>


#8 Nsm

Nsm

    Member

  • Members
  • PipPip
  • 12 posts

Posted 06 October 2013 - 04:36 AM

When option 5 or 6 is selected i want it to display:

NoVal1.php File:
 

[code=auto:0]
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th>DO NOT VALIDATE<br> STICKEY:</td>
<th width="25%">&nbsp;</td>
<th width="25%">&nbsp;</td>
</tr>
</table>
[/code ]


#9 Nsm

Nsm

    Member

  • Members
  • PipPip
  • 12 posts

Posted 06 October 2013 - 04:38 AM

The way the code is now it does not display anything no matter what is selected.

It seems like the code misses something. I see the loading image for a second but nothing is displayed.

What am i doing wrong?

Thanks



#10 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,539 posts

Posted 06 October 2013 - 04:51 AM   Best Answer

Couldn't you posted the above 4 posts into one post?  :shrug:

 

But anyway you're using the wrong logical operator in dynamic-form.php

<?php
$cat=$_REQUEST['cate'];
if($cat==1 && $cat==2 && $cat==3 && $cat==4)
{
require_once('OrderStatus.php');
}  
elseif ($cat==5 && $cat==6)
{
require_once('NoVal1.php');
}
?>

The && (and operator) should be changed to the || (or operator). 


Edited by Ch0cu3r, 06 October 2013 - 04:51 AM.


#11 Nsm

Nsm

    Member

  • Members
  • PipPip
  • 12 posts

Posted 06 October 2013 - 05:08 AM

Thanks Ch0cu3r,

That did the trick.

I did try to post the above in one post but after typing all it only posted the first part. In order not do keep doing it over i posted it again in 4 parts. sorry for the inconvenience and thanks for your help.



 



#12 jcbones

jcbones

    Advanced Member

  • Gurus
  • 2,573 posts
  • LocationNorth Carolina

Posted 06 October 2013 - 07:15 AM

You must be using Chromium.  This forum hates Chromium.  Once you post a BBCode, it won't post anything else.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com