Parse error: parse error, unexpected T_ENCAPSED etc etc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Parse error: parse error, unexpected T_ENCAPSED etc etc

Post by NiGHTFiRE »

Hey,
I get this error in my script and i guess it's from these three lines i get it from:

Code: Select all

$item_array = mysql_fetch_array($result); 
		 $sql2 = "SELECT * FROM bud WHERE item=$item_array['item']";
		 $result2 = mysql_query($sql2) or die(mysql_error());
Do you see anything wrong? Thanks.

I'm also wondering why I get: Resource id #4 etc etc when I do this:

Code: Select all

$sql = "SELECT COUNT(*) from auction WHERE status='ny'";
	$result = mysql_query($sql) or die(mysql_error());
I echo it like this:

Code: Select all

$nummer1 = "Antalet auktioner som är igång: ";
	$nummer1 .= "$result";
	echo "$nummer1";
I know it's not neccessary to do like above but i didn't at the beginning but i got the same error so i tryed with a diffrent setup on it but I still got the same error.

Thanks.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Parse error: parse error, unexpected T_ENCAPSED etc etc

Post by Benjamin »

Try this, I didn't test it.

Code: Select all

$item_array = mysql_fetch_array($result); 
$sql2 = "SELECT * FROM bud WHERE item='" . $item_array['item'] . "'";
$result2 = mysql_query($sql2) or die(mysql_error());

Code: Select all

$sql = "SELECT COUNT(*) as CounterName from `auction` WHERE status='ny'";
$result = mysql_query($sql) or die(mysql_error());
$Data = mysql_fetch_assoc($result);
$Count = $Data['CounterName'];

Code: Select all

$nummer1 = "Antalet auktioner som är igång: ";
$nummer1 .= $Count;
echo "$nummer1";
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Thanks, that works. I've also got this problem:

Code: Select all

echo " Ja&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tabort_ja' value='' . $row['auktionnamn'] . ''>";
I get the error Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING.
Thanks
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

echo " Ja&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tabort_ja' value='' . $row['auktionnamn'] . ">";
One of your " was actually two '
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Oh, dumb me :P
Thanks. I'll try it
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Code: Select all

echo " Ja&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tabort_ja' value='' . $row['auktionnamn'] . ">";
Doesn't work. I get the same error
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

echo ' Ja&nbsp;&nbsp;&nbsp;<input type="checkbox" name="tabort_ja" value="' . $row['auktionnamn'] . '">';
Now it should work.
Last edited by Benjamin on Mon Jun 19, 2006 2:15 pm, edited 1 time in total.
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Works. But the idea I wanted doesn't work.
This is my code:

Code: Select all

<?php
$mysql_server = "xxx";
$mysql_user = "xxx";
$mysql_password = "xxx";
$mysql_database = "xxx";
 
$conn = mysql_connect($mysql_server, $mysql_user, $mysql_password);
mysql_select_db($mysql_database, $conn);
$sql = "SELECT * 
                FROM auction 
                ORDER BY id DESC"; 
if (!$result = mysql_query($sql)) 
{ 
        die("Could not get the item list: " . mysql_error()); 
} 

echo '<form method="post" action="tabortauktion.php">'; 
echo '<select name="auction">'; 
while ($row = mysql_fetch_array($result)) 
{ 
        echo '<option value="' . $row['id'] . '">' . $row['auktionnamn'] . '</option>'; 
} 
echo '</select>'; 
echo "<input type='submit' name='submit' value='Få fram auktion'>";
echo '</form>'; 
?>
<?php
include "connect.php";
error_reporting(E_ALL);

if (isset($_POST['auction'])) 
{ 
        // You would really want to validate this here, 
        // But I am keeping this intentionally simple 
       $item_id = $_POST['auction']; 

        $sql = "SELECT * 
                        FROM auction
                        WHERE id = $item_id ORDER BY id DESC"; 
        if (!$result = mysql_query($sql)) 
        { 
                die("Could not get the selected item: " . mysql_error()); 
        } 
		
        $item_array = mysql_fetch_array($result); 
        $sql2 = "SELECT * FROM bud WHERE item = $item_id"; 
		    if (!$result2 = mysql_query($sql2)) 
        { 
                die("Could not get the selected item: " . mysql_error()); 
        }
		
		
        echo '<form method="post" action="tabortauktion.php">'; 
		echo 'Ta bort denna auktion: ';
		echo "<br>";
echo " Ja&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tabort_ja' value=''" . $row['auktionnamn'] . ">";
		echo "<br>";
        echo '</form>'; 
		echo "<br>";
				echo "<input type='submit' name='submit' value='Få fram fakta'>";
		
//if($_POST['tabort_ja']) {
//$sql2 = "DELETE * FROM auction WHERE id = $item_id LIMIT 1";
//$result2 = mysql_query($sql2) or die(mysql_error());
//echo "Auktionen har blivit raderat";
//echo "<a href='admin.php'>Tillbaka till Admin Panelen</a>";
//break;
//}
	if($_POST['tabort_ja'])
	{
	  $tabort=addslashes($_POST['tabort_ja']);
	  mysql_unbuffered_query("DELETE FROM auction WHERE id=$tabort");
    }
	if(!$result=mysql_query("SELECT id,auktionnamn,item,datum_borja,maxantalbud,antalbud,bild,marknadsvarde,info,status FROM `auction` ORDER BY `id`"))echo(mysql_error());
}
?>
The checkbox got the value zero so none gets deleted. How should i solve it?
Thanks
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

echo ' Ja&nbsp;&nbsp;&nbsp;<input type="checkbox" name="tabort_ja" value="' . $row['auktionnamn'] . '">';
Now it should work, I moved the quotes around a bit.
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

I still get the value o zero. Am I using the right variable for the value in the checkbox?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Without looking closely, it looks like you have 2 forms. Each form should have a unique name I believe. Add name="something" to each <form .... > tag and try it again. Also add this right under <?php

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
That will show you what is being posted to the form. It's possible your value='' isn't being populated. You may want to right click view source to double check that.
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

my value isn't being populated in the checkbox.
Post Reply