Jump to content

php / mysql beginner question


webguy

Recommended Posts

Hello all,

 

I\'m new here and hope that someone has the answer of a real beginner.

I\'ve read several tutorials but what i want isn\'t working.

 

I have a little table with some fields:

 

CREATE TABLE prod (

name varchar(100) NOT NULL default \"\",

nr int(5) NOT NULL,

descr text NOT NULL,

PRIMARY KEY (nr),

UNIQUE KEY nr (nr),

UNIQUE KEY name (name)

) TYPE=MyISAM COMMENT=\"Products\";

I have a working php program to add data to the database.

I also have a little php program to list all records in the database.

Now i need a program that can be called with a parameter to show all fields of a product like:

 

http://localhost/pdc/listprod.php?prodnr=3

 

My program looks like this:

 

<?

include \'db.php\';

?>

<html>

<head>

<title>Products/title>

</head>

<body bgcolor=\"#ffffff\" >

 

<?

# setup SQL statement

$sql = \" SELECT * FROM prod WHERE nr = \'$prodnr\'\";

# execute SQL statement

$rs = mysql_query($sql, $cid);

if (mysql_error()) { print \"Database Error: $sql \" . mysql_error(); }

# display results

print \"<p><b>Products</b><p>n\";

print \"<table border=0>\";

while ($row = mysql_fetch_array($rs))

{

$name = $row[\"name\"];

$nr = $row[\"nr\"];

$descr = $row[\"descr\"];

print \"<tr><td>$name</td><td>$nr</td><td>$descr</td><tr>\";

}

print \"</table>\";

?>

</body>

</html>

 

But, i get NO results! I\'ve made shure product nr 3 is in the database, i\'ve checked it with PHPMYADMIN.

What am i doing wrone here? Can anybody point me in the right direction?

 

Thanks in advace,

Webguy

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.