プロが教える店舗&オフィスのセキュリティ対策術

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitio …
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>通販サイト</title>
<link href="common/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="common/js/base.js"></script>
</head>
<body onload="MM_preloadImages('common/img/bt1_f2.gif','common/img/bt2_f2.gif','common/img/bt3_f2.gif','common/img/bt3_2_f2.gif','common/img/bt_login_f2.gif')">

<?php
// データベースに接続する処理。
// 環境に応じて以下の変数を書き換えます。
$host = "localhost";// 接続先ホスト名
$user = "root";// 接続ユーザ名
$pass = "";// 接続パスワード
$dbname = "ec";// データベース名
if( !$conn = mysql_connect( $host, $user, $pass ) )
{
die("MySQL 接続エラー");
}
mysql_select_db( $dbname );
mysql_set_charset("utf8");// 文字コードを指定します。
?>

<div id="wrap">
<div id="contents">
<!-- 右コンテンツ -->
<div id="rightbox">
<div id="main">
<div id="main2">
<!-- ↑↑タイトル以外共通部分↑↑ -->
<?php
$sql = "select * form m_items where item_code=" .$_GET["code"];
$res = mysql_query($sql);
→ココif( $sql = mysql_fetch_assoc($item["item_code"]) )
{
?>
<form name="detail_form" action="cart.php" method="get">
<input type="hidden" name="cmd" value="add_cart"/>
<input type="hidden" name="code" value="<?php print( $item["item_code"] ); ?>"/>
<!-- メイン部分 各ページごとに作成-->
<div id="mainbox" class="clearfix">
<h2>商品詳細</h2>
<div class="list clearfix">
<h3><?php print( $item["item_name"] ); ?></h3>
<p class="photo"><img src="img/<?php print( $item["image"] ); ?>" width="400" height="400"/></p>
<p class="text"><?php print( $item["detail"] ); ?></p>
<div class="buy">
<p class="price">価格:<strong>&yen;<?php print( $item["price"] ); ?></strong></p>
個数:
<select name="num">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
</select>
<input type="button" value="カートにいれる" onclick="location.href='cart.php'"/>
<input type="button" value="前の画面へ戻る" onclick="history.back()"/>
</div>
</div>
</div>
</form>
<!-- /メイン部分 各ページごとに作成-->
<?php
}

→ココmysql_free_result($item["code"]);
?>

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in
上のIF文
Warning: mysql_free_result() expects parameter 1 to be resource, null given in
mysql_free_result
に上記のようなエラーが出ています。
どう直したらいいのかわかりません。
宜しくお願い致します。

A 回答 (1件)

mysql_fetch_assocもmysql_free_resultもパラメータが間違っています。



エラーが出たなら、まずは関数の使い方を見ましょう。
http://php.net/manual/ja/function.mysql-fetch-as …
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!