Forum Moderators: coopster

Message Too Old, No Replies

unexpected T_CHARACTER, expecting T_STRING or T_VARIABLE or T_NUM_....

help please dying here cracking up BIG TIME

         

urbley

11:00 am on Oct 29, 2004 (gmt 0)

10+ Year Member



ok here's the deal.. i've been creating this little shopping cart area for a website and i'm passing book details from my bookstore to cart.php using a switch i.e. cart.php?action=addBook&title=\"$title"&...... etc.

here's the link sending the data to the cart.

<a href=\"cart.php?action=addBook&title='$title'&author='$author'&price=$price&cat='$cat'&stock=$stock\"><p>Buy</p></a>

everything's fine here i think

the processing it...

//the addBook switch
case "addBook": {

$title = $_GET["title"];
$author = $_GET["author"];
$price = $_GET[price];
$cat = $_GET["cat"];
$stock = $_GET[stock];

$db = mysql_connect("php.example.uk", "user", "password");
mysql_select_db("b01sn_db",$db);

$dbQuery="INSERT INTO cart VALUES cartId='$REMOTE_ADDR', title='$title', $author='author', price='$price', cat='$cat'";
$result = mysql_query($dbQuery,$db);

showCart();

break;

}

//the showCart() function lines producing the error!

while ($arrayVar = mysql_fetch_array($result)){

$title=$arrayVar[\"title\"];
$author=$arrayVar[\"author\"];
$price=$arrayVar[price];
$cat=$arrayVar[\"cat\"];
$totalPrice += $price;

---------------------------------------------
it isn't getting past $title=$arrayVar[`title`];
any help here leading to a solution would be really really helpful.

[edited by: coopster at 12:58 pm (utc) on Oct. 29, 2004]
[edit reason] generalized mysql connection info [/edit]

dreamcatcher

12:58 pm on Oct 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi urbley,

Welcome to Webmaster World.

I can see a couple of things. Firstly, your INSERT syntax is wrong. You are using the UPDATE syntax by mistake. Should be:

INSERT INTO cart (cartId,title,$author,price,cat) VALUES ('$REMOTE_ADDR','$title','author','$price','$cat');

or if you do want to update, it should be UPDATE cart SET...

Secondly, you don`t need to escape slashes when using mysql_fetch_array().

$title=$arrayVar['title'];
$author=$arrayVar['author'];
$price=$arrayVar['price'];
$cat=$arrayVar['cat'];

One final thing about your switch statement. I assume you are using the switch() function?

switch ($_GET['action'])
{
case "addBook":
//rest of code
break;
}

This is probably whats causing your error.

Hope that helps. :)

urbley

3:20 pm on Oct 30, 2004 (gmt 0)

10+ Year Member



sincerest thanks for your help. Still receiving an error regarding variable type i think. shouting about T_STRING or T_NUM expected.. i'm passing the $REMOTE_ADDR as a unique way of identifying a customer and ending their session when they've disconnected.
I'm passing it, and trying to put it into the database as a VARCHAR i think possibly cos of the dots there might be a problem with this?

If anyone has any insight to help illuminate my precarious situation then please share your thoughts or opinions.

JamesRock

4:07 pm on Oct 30, 2004 (gmt 0)

10+ Year Member



generally when i get an error message like this it is because I have left off a semi-colon or done something like this

$var["field];

look for basic syntax errors in your code and most likely you'll find something

whatever line it says the error is on, look at the line above it and that will probably be where the error is.

dreamcatcher

5:16 pm on Oct 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One thing about $REMOTE_ADDR is if you have register globals off on your server, this will echo nothing. You should use $_SERVER['REMOTE_ADDR'].

What line is the error pointing to. JamesRock offers some good advice. :)

urbley

6:12 pm on Oct 31, 2004 (gmt 0)

10+ Year Member



All excellent advice and very greatly appreciated. Unfortunately the database and web server are down for the weekend so i can't get back at it! talk about frustrating. i'll try and show you what my worry was. This is my showCart() function

function showCart(){

echo "

<HTML>

<HEAD>

<TITLE> Bookworms Online :: Your Shopping Cart </TITLE>
<link rel='stylesheet' type='text/css' href='style.css'

<HEAD>

<BODY topmargin='0' leftmargin='0' onload='window.status=\"BookwormsOnline.com\"'>
<center>
<table width='750' cellpadding='0' cellspacing='0' border='0'>
<tr valign='bottom'>
<td><h1>&nbsp;BookWormsOnline.com</h1></td>
<td width='60%'></td>
<td><img src='images/bookworm2.jpg' alt='Book Store Logo' border='0' width='94' height='80'></td>
</tr>
<tr>
<td colspan='3'>
<input type='button' value='Home' onMouseOver='window.status=\"Click here to go to the Homepage\"' onMouseOut='window.status=\"BookwormsOnline.com\"' onClick='parent.location=\"index.html\"' />
<input type='button' value='About Us' onMouseOver='window.status=\"Click here to learn more about us\"' onMouseOut='window.status=\"BookwormsOnline.com\"' onClick='parent.location=\"about.html\"' />
<input type='button' value='Bestsellers' onMouseOver='window.status=\"Click here for most popular books\"' onMouseOut='window.status=\"BookwormsOnline.com\"' onClick='parent.location=\"Bestsellers.html\"' />
<input type='button' value='Book Store' onMouseOver='window.status=\"Click here to view our book selection\"' onMouseOut='\"window.status=BookwormsOnline.com\"' onClick='parent.location=\"Bookstore.php\"' />
<input type='button' value='Contact' onMouseOver='window.status=\"Click here to contact us\"' onMouseOut='window.status=\"BookwormsOnline.com\"' onClick='parent.location=\"Contact.html\"' />
<input type='button' value='Search' onMouseOver='window.status=\"Click here to search our store\"' onMouseOut='window.status=\"BookwormsOnline.com\"' onClick='parent.location=\"Search.html\"' />
<hr width='100%'>
</td>
</tr>
<tr>
<td colspan='3' align='center'>

<br/><br/>
<table width='100%' class='border'>
<tr>
<th colspan='4'>Your Shopping Cart Contents</th>
</tr>
<tr>
<th width='325'>Title</th>
<th width='325'>Author</th>
<th width='50'>Price</th>
<th width='50'>Delete</th>
</tr>

<?php

$db = mysql_connect(\"server\", \"username\", \"password\");
mysql_select_db(\"b01sn_db\",$db);

$dbQuery=\"SELECT * FROM cart order by title asc\";
$result = mysql_query($dbQuery,$db);

while ($arrayVar = mysql_fetch_array($result)){
$title=$arrayVar["title"];
$author=$arrayVar["author"];
$price=$arrayVar[price];
$cat=$arrayVar["cat"];
$totalPrice += $price;

echo \"<tr><td><p>$title</p></td>\" .
\" <td><p>$author</p></td>\" .
\" <td><p>$price</p></td>\".
\" <td><input type='button' value='Delete' onClick='deleteBook();'</td></tr>\";
}
echo \"<tr><td>Total Price: $totalPrice</td><td></td><td></td><td></td></tr>\";
}

?>

</table>

<br/><br/>
</td>
</tr>
<tr>
<td colspan='3'><hr width='100%'></td>
</tr>
<tr valign='bottom'>
<td colspan='3'><p>Useful Links: <a href='http://www.amazon.co.uk/' target='_blank'>Amazon.co.uk</a>&nbsp;¦&nbsp;<a href='http://www.whsmith.co.uk/' target='_blank'>WHSmith.co.uk</a>&nbsp;¦&nbsp;<a href='http://www.easons.com/' target='_blank'>Easons.com</a></p>
</td>
</tr>
</table>

</BODY>

</HTML>
";

}

as you can see i'm trying to display an entire webpage including more php code and in the little chunk of php code i have my while($arrayVar=mysql_fetch_array etc. etc.

i'm needing to use $title=$arrayVar["title"]; but won't the " "'s call the end of the echo from the start of the function?

Also as soon as the server is back up i'll try and use the $_SERVER["$REMOTE_ADDR"]. Like i asked before you don't think i'll have any problems passing $REMOTE_ADDR as a string?

dreamcatcher

7:13 pm on Oct 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are echoing between double quotes, use apostrophes in your data, this will help to avoid any problems. If your header data is used more than once, you might want to think about moving it in to an include file. Same as your footer data.

You should have no problem getting the IP address, but if you are including it in a function, you may need to declare the $_GLOBALS array as...well, global. :)

urbley

10:11 pm on Oct 31, 2004 (gmt 0)

10+ Year Member



Believe it or not this is the first time i've used php so i'm still getting used to basics. Havent read much on globals yet but if you think it will work then I'm sure its worth a read. As always. many thanks.

urbley

10:13 pm on Oct 31, 2004 (gmt 0)

10+ Year Member



oh yeah if you ever have any questions about flash, photoshop or 3DSM, don't hesitate to gimme a shout! :P