/    Sign up×
Community /Pin to ProfileBookmark

whats wrong with this

i am working a cart system and i want it so it displays the Item name and that is a link so when you click it you get more infomation about it.

now with this it should display ?id=ID NUMBER but instead i get this error

[QUOTE]

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:Program FilesApache GroupApache2htdocscgrproducts2.php on line 6

[/QUOTE]

[code=php]<?php
if(isset ($_REQUEST[“id”])){
mysql_pconnect(“localhost”,”root”,”password”);
mysql_select_db(“cart”);
$result = mysql_query(“select * from items where id=” . $_REQUEST[“id”]);
$r=mysql_fetch_array($result);

$name=$r[“itemName”];
$desc=$r[“itemDesc”];
$price=$r[“itemPrice”];

echo “<h1>$name</h1>”;
echo “$desc”;
echo “$price”;
echo “<p><a href=”cart.php?action=view”>Your Shopping Cart</a></p>”;
}

else {[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pnajFeb 04.2004 — All looks fine to me ...

What about the link that calls this page with the ?id= bit ... is that looking OK?

Also, try testing for null strings ...

if(isset($_REQUEST['id']) && $_REQUEST['id'] != '')

... instead of just ...

if(isset($_REQUEST['id']))

... that could [I]sometimes[/I] cause a problem.

Also, I notice that all the fields in the 'items' mysql table seem to start with item (itemName, itemPrice, itemDesc) ... it's not 'itemId' instead of just 'id'.

Apart from that ... don't know.
Copy linkTweet thisAlerts:
@chris9902authorFeb 05.2004 — when the has no ?id= it does what i want it to do but if i put ?id= i get that "damn" error

this is the full script for the products page.

it should display the products as a link then divide them with a HR. that it does but when i click on the link of the product it should them display the ?id= and display the Price, Desc, and name of that prodcuts depending on the ID. i change the id to itemId but when i click that i don't get and error all i see if the same page again but with a ?id= in the address.

i hope that makes sense :rolleyes:

[code=php]<?php
if(isset ($_REQUEST["id"])){
mysql_pconnect("localhost","root","password");
mysql_select_db("cart");
$result = mysql_query("select * from items where id=" . $_REQUEST["id"]);
$r=mysql_fetch_array($result);

$name=$r["itemName"];
$desc=$r["itemDesc"];
$price=$r["itemPrice"];

echo "<h1>$name</h1>";
echo "$desc";
echo "$price";
echo "<p><a href="cart.php?action=view">Your Shopping Cart</a></p>";
}

else {

mysql_pconnect("localhost","root","password");
mysql_select_db("cart");
$result = mysql_query("select * from items limit 2");
while($r=mysql_fetch_array($result))
{
$id=$r["itemId"];
$title=$r["itemName"];
echo "<a href="?id=$id">$title</a> <hr color="#f4f4f4" />
";
}
}
?>[/code]
Copy linkTweet thisAlerts:
@chris9902authorFeb 05.2004 — forget that!

i i had itemid in my database but i was using itemId.

got it work now.

? ? ? ? ? ? ? ? ?

Thanks for your help pnaj
×

Success!

Help @chris9902 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...