duanjing7651 2013-06-29 07:15 采纳率: 0%
浏览 9
已采纳

只有产品的第一个id被添加到mysql表中[关闭]

first time am using this, so i hope to have as much help as needed

hi guys, i have 2 tables - tblproduct and tblretprod. i insert my product details to tbl product with prod_id being auto increment other fields are prod_name, prod_brand, prod_desc, prod_photo, cat, subcat

i hv another table tblretprod with fields id, user_id, prod_id, prod_price

i can add my products successfully

i am displaying all the products i added in a table i echo along with a textfield to enter the product price and an add button

on clicking the add button, user_id for the session, prod_id and prod_price should be inserted in the tblretprod

user_id and prod_price are being inserted correctly, but the prod_id which is unique to each product is not being added. only the first prod_id i.e 1 is being added everywhere

here are my codes to add the product when i click on add

<?php
    session_start();
    include('db_connect.php');
    $username = $_SESSION['username'];
    $prod_price = $_POST['prod_price'];
    $url='retprod.php';
    $sql=mysql_query("select user_id from tbllogin where username = '$username'");
    $row = mysql_fetch_array($sql);
    $sql1 = mysql_query("select * from tblproduct");
    $row1 = mysql_fetch_array($sql1);
    $sql2 = mysql_query("insert into tblretprod (user_id, prod_id, prod_price) values   ('$row[user_id]', '$row1[prod_id]', '$prod_price')");
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    echo "<script>alert('This product has been added successfully.')</script>";
?>

i tried this:-

$prod_id = $_POST['prod_id'];
// or
$prod_id = $_GET['prod_id'];
$sql1 = mysql_query("select * from tblproduct where prod_id='$prod_id'");

this didn't work either

what i want to do in short is that when the user fills in the text field with the product price and clicks on the add button, the relative user_id, prod_id of the product and the price entered are stored in tblretprod. user_id and price are being saved but not the relative prod_id


i am trying the below code and i know it can work but i don't know where there is an error in the code. Can anyone help me out please? I know am using a deprecated mysql codes but my project is nearly complete.

while($row = mysql_fetch_assoc($sql)){
 extract($row); 

 echo "<tr>";
 echo '<td style="text-align:center;"><img height="100" width="100"   src="Images/Products/'.$row['prod_photo'].'" alt="'.$row['prod
  _name'].'" /></td>';
  echo "<td style="text-align: center;">".$row['prod_name']."</td>";
  echo "<td style="text-align: center;">".$row['prod_brand']."</td>";
  echo "<td>"."<form name=\"price\" method=\"post\" action=\"ret_addprod.php\">".
    "<input type=\"hidden\" name=\"prod_id\" value=\"'.$row['prod_id'].'\" />.
    "<center><input type=\"text\" name=\"prod_price\" />.
    "<input type=\"submit\" value=\"Add\" /></form>"."</td>";


}
  • 写回答

2条回答 默认 最新

  • duanlang1531 2013-06-29 07:22
    关注

    your not putting a filter on your tblproduct query. So it will always be the first row of that table that will be inserted.

    change $sql1 = mysql_query("select * from tblproduct");

    to something like $sql1 = mysql_query("select * from tblproduct WHERE id = '$filter'");

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题