echo,or cuotes problem

Ask about a PHP problem here.
Post Reply
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

echo,or cuotes problem

Post by ta2shop »

hy guys, i am folowing the shoping cart tutorial alex made, and i think becouse of the € sign mi a href links do not work!
loock below, and i folowed the tutorial exactly, but it all went bad when i changed the pound sign for the euro one :)
[syntax=php]
echo $get_row['name'].' x '.$value.' @ '.number_format($get_row['price'], 2).'&euro; = '.number_format($sub, 2).'&euro;'.' <a href='cart.php?remove='.$id.''>[-]</a> <a href=''>[+]</a> <a href=''>[Delete]</a><br/>';
[/syntax]
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: echo,or cuotes problem

Post by EcazS »

You have to escape single quotes inside single quotes try this,
[syntax=php]echo $get_row['name'].' x '.$value.' @ '.number_format($get_row['price'], 2).'&euro; = '.number_format($sub, 2).'&euro;'.' <a href=\'cart.php?remove='.$id.'\'>[-]</a> <a href=\'\'>[+]</a> <a href=\'\'>[Delete]</a><br/>';[/syntax]
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: echo,or cuotes problem

Post by ta2shop »

thanks but its still error, loock:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in C:\xampp\htdocs\trabajos\shopping_cart_tutorial\cart.php on line 39
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: echo,or cuotes problem

Post by EcazS »

ta2shop wrote:thanks but its still error, loock:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in C:\xampp\htdocs\trabajos\shopping_cart_tutorial\cart.php on line 39


Can you post the full code?
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: echo,or cuotes problem

Post by ta2shop »

yep :)
[syntax=php]
<?php
session_start();

$page = "index.php";

mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("ta2cart") or die(mysql_error());

if(isset($_GET['add'])) {
$quantity = mysql_query('SELECT id, quantity FROM products WHERE id='.mysql_real_escape_string((int)$_GET['add'])) or die(mysql_error());
while($quantity_row = mysql_fetch_assoc($quantity)) {
if($quantity_row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) {
$_SESSION['cart_'.(int)$_GET['add']]+='1';
}
}
}

function products() {
$get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER BY id DESC') or die(mysql_error());
if(mysql_num_rows($get)==0) {
echo "There are no products to display!";
}
else {
while($get_row = mysql_fetch_assoc($get)) {
echo'<p><b>'.$get_row['name'].'</b><br/>'.$get_row['description'].'<br/>'.number_format($get_row['price'],2).'&euro; <a href="cart.php?add='.$get_row['id'].'">Add</a><p/>';
}
}
}

function cart() {
foreach($_SESSION as $name => $value) {
if($value>0) {
if(substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
while($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;
echo $get_row['name'].' x '.$value.' @ '.number_format($get_row['price'], 2).'&euro; = '.number_format($sub, 2).'&euro;'.' <a href=\'cart.php?remove='.$id.'\'>[-]</a> <a href=\'\'>[+]</a> <a href=\'\'>[Delete]</a><br/>'
}
}
}
else {
echo "Your cart is empty.";
}
}
}


?>
[/syntax]
it is form alex's tutorial about the mini shopping cart.
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: echo,or cuotes problem

Post by EcazS »

Missing semi-colon at this line, just add one ;)
[syntax=php]
echo $get_row['name'].' x '.$value.' @ '.number_format($get_row['price'], 2).'&euro; = '.number_format($sub, 2).'&euro;'.' <a href=\'cart.php?remove='.$id.'\'>[-]</a> <a href=\'\'>[+]</a> <a href=\'\'>[Delete]</a><br/>'
[/syntax]
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: echo,or cuotes problem

Post by GenSwat »

LOL I was lost thought he was talking about

[syntax=php]html_entity_decode('&#8364', ENT_QUOTES, 'ISO-8859-15');[/syntax]


can you use str_replace() to change symbol
Last edited by GenSwat on Mon May 09, 2011 9:53 am, edited 1 time in total.
One of my Favorites
Image
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: echo,or cuotes problem

Post by ta2shop »

no, it still prints the same error!
Parse error: syntax error, unexpected '}', expecting ',' or ';' in C:\xampp\htdocs\trabajos\shopping_cart_tutorial\cart.php on line 39
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: echo,or cuotes problem

Post by GenSwat »

maybe you need to convert the symbol?

try looking here, you said after you used euro symbol

http://php.net/manual/en/function.mb-convert-encoding.php
One of my Favorites
Image
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: echo,or cuotes problem

Post by ta2shop »

no actualy EcazS is right!!! :) i forgot about the closing ; semicolon! :lol:
somtimes i am soooo stupid! :D
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: echo,or cuotes problem

Post by GenSwat »

LOL, I can't tell you how long I've look at one line and the answer was right in front my face either '," or ; missing..
One of my Favorites
Image
Post Reply