Forum Moderators: coopster
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]
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. :)
If anyone has any insight to help illuminate my precarious situation then please share your thoughts or opinions.
$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.
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> 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> ¦ <a href='http://www.whsmith.co.uk/' target='_blank'>WHSmith.co.uk</a> ¦ <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?
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. :)