Jump to content

unexpected T_IF


MasterACE14

Recommended Posts

Morning PHPFreaks,

 

I am recieving a unexpected T_IF parse error on my encyclopedia script I was working on alittle while back(some of you might of seen my post  :))

 

here's the error:

Parse error: syntax error, unexpected T_IF in /home/ace/public_html/conflictingforces/lib/encyclopedia_search.php on line 34

 

and here's the complete script:

<?php
$item_cr = $_POST["cat"]; // this gets the checkbox value
$item_search = $_POST["item"]; // this gets the search box value
$item_type = $_POST["type"]; // this gets the drop down box value

foreach($item_type as $key => $val){
if($item_search == $val[$item_cr]){
	$search = 1;
		echo '<table class="fix"><tr>';
		echo '<td colspan="2">' . if($item_type == "weapon"){echo "WEAPON";};elseif($item_type == "armor"){echo "ARMOR";};elseif($item_type == "vehicle"){echo "VEHICLE";}; . '</td></tr>';
		echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>';
		echo '<tr><td>weapon</td><td>' . $item_type[$key]if($item_type == "weapon"){['weapon']}elseif($item_type == "armor"){['armor']}elseif($item_type == "vehicle"){['vehicle']} . '</td></tr>';

		echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>';
		echo '<tr><td>damage</td><td>' . $item_type[$key]if($item_type == "weapon"){['damage']}elseif($item_type == "armor"){['defence']}elseif($item_type == "vehicle"){['power']} . '</td></tr>';
		echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>';
		echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>';
		echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>';
		echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>';
		echo '</table><br />';
}

}
if(!isset($search) || $search != 1){
echo "not found<br><br>";
}

?>

 

Regards ACE

Link to comment
Share on other sites

echo '<tr><td>weapon</td><td>' . $item_type[$key]if($item_type == "weapon"){['weapon']}elseif($item_type == "armor"){['armor']}elseif($item_type == "vehicle"){['vehicle']} . '</td></tr>';

 

Makes no sense. There's the source of the mistake.

Link to comment
Share on other sites

that fixed that error, now I got another:

Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /home/ace/public_html/conflictingforces/lib/encyclopedia_search.php on line 34

 

I dont understand where it is expecting a , or ; after each if statement?

Link to comment
Share on other sites

that fixed that error, now I got another:

Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /home/ace/public_html/conflictingforces/lib/encyclopedia_search.php on line 34

 

Why don't you post the revised code so we can see just what you fixed.  With all those statements stuffed into one line, it's near impossible to see the logic and/or spot the mistake.

Link to comment
Share on other sites

I agree, it was much neater before I made the adjustments  :-\ :

<?php
$item_cr = $_POST["cat"]; // this gets the checkbox value
$item_search = $_POST["item"]; // this gets the search box value
$item_type = $_POST["type"]; // this gets the drop down box value

foreach($item_type as $key => $val){
if($item_search == $val[$item_cr]){
	$search = 1;
		echo '<table class="fix"><tr>';
		echo '<td colspan="2">' . $item_type[$key]if($item_type == "weapons"){['weapon']}elseif($item_type == "armors"){['armor']}elseif($item_type == "vehicles"){['vehicle']} . '</td></tr>';
		echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>';
		echo '<tr><td>weapon</td><td>' . $item_type[$key]if($item_type == "weapons"){['weapon']}elseif($item_type == "armor"){['armors']}elseif($item_type == "vehicles"){['vehicle']} . '</td></tr>';
		echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>';
		echo '<tr><td>damage</td><td>' . $item_type[$key]if($item_type == "weapons"){['damage']}elseif($item_type == "armors"){['defence']}elseif($item_type == "vehicles"){['power']} . '</td></tr>';
		echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>';
		echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>';
		echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>';
		echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>';
		echo '</table><br />';
}

}
if(!isset($search) || $search != 1){
echo "not found<br><br>";
}

?>

Link to comment
Share on other sites

what are this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

echo '<tr><td>weapon</td><td>' . $item_type[$key]if($item_type == "weapons"){['weapon']}elseif($item_type == "armor"){['armors']}elseif($item_type == "vehicles"){['vehicle']} . '</td></tr>';

 

that an error

 

Link to comment
Share on other sites

		echo '<table class="fix"><tr>';
		if($item_type == "weapons"){
			$x= 'weapon';
		}
		elseif($item_type == "armors"){
			$x= 'armor';
		}
		elseif($item_type == "vehicles"){
			$x= 'vehicle';
		}
		echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>';

 

do it that way thats the write way you seems to obtain your own ternary design LOL

Link to comment
Share on other sites

Im not getting anymore parse errors now, the table comes up, but isnt showing anything in the second column, or in the column that spans 2 columns. It doesnt seem to be selecting the array.

 

here's the part I added to select the array:

<?php
$item_type = $_POST["type"]; // this gets the drop down box value

if($item_type == "weapons") {
$array = $weapons;
}
elseif($item_type == "armors") {
$array = $armors;
}
elseif($item_type == "vehicles") {
$array = $vehicles;
}

foreach($array as $key => $val){

Link to comment
Share on other sites

I see a potentially serious problem here.

 

<?php

$item_type = $_POST["type"]; // this gets the drop down box value

foreach($item_type as $key => $val){

?>

 

The $_POST array is going to contain strings.  Essentially, you're taking a string and trying to use it as if it is an array.  I don't think this will do what you think it will.  It will treat the string as an array of characters.

 

As far as the error with the if statement, you're using the if statement as if it returns a value, which it does not.

Link to comment
Share on other sites

I dunno, their must be a way to put an array into a variable for the foreach statement.
[code]<?php
if($item_type == "weapons") {
$array = $weapons;

}

elseif($item_type == "armors") {

$array = $armors;

}

elseif($item_type == "vehicles") {

$array = $vehicles;

}

 

foreach($array as $key => $val)[/code]

 

:-\

Link to comment
Share on other sites

Don't think of it like that.  You need to think in terms of the submission form.  

 

What are all the different pieces of data that are being submitted?  Remember, these are all strings.  No arrays.

 

Given those pieces of data, how do you process them to accomplish your task?

Link to comment
Share on other sites

yeah, I understand its all strings. But thats just works the IF statements. Its the first part of the foreach statement that needs an Array specified which is where the IF statements come in.

 

here's the complete code:

<?php // encyclopedia for the game

/* includes */
include_once '/home/ace/public_html/conflictingforces/vehicles.php';
include_once '/home/ace/public_html/conflictingforces/armors.php';
include_once '/home/ace/public_html/conflictingforces/weapons.php';
include_once '/home/ace/public_html/conflictingforces/variables.php';

/* javascript alert if nothing was entered into the text box */
if($_POST["item"] == '' || $_POST["item"] == ' '){

echo "<script language=\"javascript\"> 
	alert('You must enter a Weapon, Armor, or Vehicle into the Search box!')
  </script>";
  
}

?>

<div id = "encyclopedia">

<center><b><u>Encyclopedia - Beta - Version <?php echo $encyclopedia_version; ?></u></b><br></center><br>

<fieldset><legend>Search Results</legend>
<center>
<?php
$item_cr = $_POST["cat"]; // this gets the checkbox value
$item_search = $_POST["item"]; // this gets the search box value
$item_type = $_POST["type"]; // this gets the drop down box value

if($item_type == "weapons") {
$array = $weapons;
}
elseif($item_type == "armors") {
$array = $armors;
}
elseif($item_type == "vehicles") {
$array = $vehicles;
}

foreach($array as $key => $val){
if($item_search == $val[$item_cr]){
	$search = 1;
		echo '<table class="fix"><tr>';
		if($item_type == "weapons"){
			$x= 'weapon';
		}
		elseif($item_type == "armors"){
			$x= 'armor';
		}
		elseif($item_type == "vehicles"){
			$x= 'vehicle';
		}
		echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>';
		echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>';
		if($item_type == "weapons"){
			$y= 'damage';
		}
		elseif($item_type == "armors"){
			$y= 'defence';
		}
		elseif($item_type == "vehicles"){
			$y= 'power';
		}
		echo '<tr><td>' . $x . '</td><td>' . $item_type[$key][$x] . '</td></tr>';
		echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>';
		echo '<tr><td>' . $y . '</td><td>' . $item_type[$key][$y] . '</td></tr>';
		echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>';
		echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>';
		echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>';
		echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>';
		echo '</table><br />';
}

}
if(!isset($search) || $search != 1){
echo "not found<br><br>";
}

?>

<?php if($_POST["item"] == '' || $_POST["item"] == ' ' ){

echo "Click <b>back</b> and type in a Weapon, Armor or Vehicle.<br><br>";

} ?>
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<input type=button value="Back" onClick="history.go(-1)">

<!-- Change the value of -1 to any number of pages you would like to send your visitors back -->

<!-- Script Size:  0.60 KB -->

</center>
</fieldset>


<br>



</div>

 

I'm not getting any parse errors. Its showing the table but with only the left column displaying anything. The right column, and the top column spanning 2 rows are both blank.

Link to comment
Share on other sites

i dont know how dimensional your array is byt his code

foreach($array as $key => $val){

if($item_search == $val[$item_cr]){

for me that means your having this arrray

 

array(array('teng'=>array('astig'=>'item')))

the way you code your if and forech your multi dimensional array consist of 3 index?

Link to comment
Share on other sites

BTW

if($item_type == "weapons") {
$array = $weapons;
}
elseif($item_type == "armors") {
$array = $armors;
}
elseif($item_type == "vehicles") {
$array = $vehicles;
}

 

wher do you get $armors,$vehicles,$weapons

can we see the structure of those variables being an array?

 

Link to comment
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.