Page 1 of 1
Parse error: parse error, unexpected T_ENCAPSED etc etc
Posted: Mon Jun 19, 2006 12:15 pm
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.
Re: Parse error: parse error, unexpected T_ENCAPSED etc etc
Posted: Mon Jun 19, 2006 12:38 pm
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";
Posted: Mon Jun 19, 2006 1:41 pm
by NiGHTFiRE
Thanks, that works. I've also got this problem:
Code: Select all
echo " Ja <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
Posted: Mon Jun 19, 2006 1:46 pm
by Benjamin
Code: Select all
echo " Ja <input type='checkbox' name='tabort_ja' value='' . $row['auktionnamn'] . ">";
One of your " was actually two '
Posted: Mon Jun 19, 2006 1:49 pm
by NiGHTFiRE
Oh, dumb me

Thanks. I'll try it
Posted: Mon Jun 19, 2006 1:53 pm
by NiGHTFiRE
Code: Select all
echo " Ja <input type='checkbox' name='tabort_ja' value='' . $row['auktionnamn'] . ">";
Doesn't work. I get the same error
Posted: Mon Jun 19, 2006 1:55 pm
by Benjamin
Code: Select all
echo ' Ja <input type="checkbox" name="tabort_ja" value="' . $row['auktionnamn'] . '">';
Now it should work.
Posted: Mon Jun 19, 2006 2:02 pm
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 <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
Posted: Mon Jun 19, 2006 2:15 pm
by Benjamin
Code: Select all
echo ' Ja <input type="checkbox" name="tabort_ja" value="' . $row['auktionnamn'] . '">';
Now it should work, I moved the quotes around a bit.
Posted: Mon Jun 19, 2006 2:32 pm
by NiGHTFiRE
I still get the value o zero. Am I using the right variable for the value in the checkbox?
Posted: Mon Jun 19, 2006 2:39 pm
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.
Posted: Mon Jun 19, 2006 5:05 pm
by NiGHTFiRE
my value isn't being populated in the checkbox.