最近在做PHP课程设计,最购物网站,本人菜鸟,所以回答的时候能详细点吗?最好带代码的,谢谢。
这个界面代码是这样:
<?php
$conn=mysql_connect('localhost','root','123')or die('连接失败');
mysql_select_db('mysql',$conn)or die('连接失败');
mysql_query("SET NAMES utf8");
$sql="select * from goods";
$result=mysql_query($sql);echo "<html>";
echo "<head>";
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
echo "<body>";
echo "<form name='form1' method='post' >";
echo "<table border=3 align='center'>";echo "<tr><td>商品编号</td><td>商品名称</td><td>商品价格(元)</td><td>数量</td><td>购物篮</td></tr>";
while($row=mysql_fetch_row($result))
{
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td><input type='text' name='text' ></td><td><input type='checkbox' name='checkbox'></td></tr>";
}echo "</table>";
echo "<input type='submit' value='确定订购'>";
echo "</form>";
echo "</body>";
echo "</head>";
echo "</html>";
?>-----------------------
我想问的是:怎样把打钩的选项,放入数据库,包括数量。
最好能给出代码,谢谢你们,本人菜鸟啊!!!
这个界面代码是这样:
<?php
$conn=mysql_connect('localhost','root','123')or die('连接失败');
mysql_select_db('mysql',$conn)or die('连接失败');
mysql_query("SET NAMES utf8");
$sql="select * from goods";
$result=mysql_query($sql);echo "<html>";
echo "<head>";
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
echo "<body>";
echo "<form name='form1' method='post' >";
echo "<table border=3 align='center'>";echo "<tr><td>商品编号</td><td>商品名称</td><td>商品价格(元)</td><td>数量</td><td>购物篮</td></tr>";
while($row=mysql_fetch_row($result))
{
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td><input type='text' name='text' ></td><td><input type='checkbox' name='checkbox'></td></tr>";
}echo "</table>";
echo "<input type='submit' value='确定订购'>";
echo "</form>";
echo "</body>";
echo "</head>";
echo "</html>";
?>-----------------------
我想问的是:怎样把打钩的选项,放入数据库,包括数量。
最好能给出代码,谢谢你们,本人菜鸟啊!!!
遍历所有checked状态的 checkbox 通过checkbox 的id 关联取得商品的名称和数量
onclick 里触发ajax后台根据id 得到商品的 title,num 入库.
checkbook的name改成数组,value改成对应的商品id
在处理页面
可以用$_GET['checkbox']或者$_POST['checkbox']获取选中的商品
foreach($_POST['checkbox'] as $key => $id)
{
$_POST[$key]['text']就是 商品 $id 的数量
}
2.使用ajax,把text的值拼成字符串,如:1,1,2
checkbox也是如此
最后ajax提交,php做处理
现在在看相关的书看例子和找代码。本人是新手+菜鸟
PHP组队没人要我所以自己做阿~~
改为
<input type='checkbox' name='checkbox[]' value='$row[0]'>然后套用#2的代码
value='$row[0]'?????他在循环哦,一直都是0吗?第一个对应的是row[0]
第二个对应的应该是row[1]吧?
难道不对吗?
$_POST['checkbox'] as $key => $id
你说是打勾的意思? $_POST[$key]['text']是商品的数量?
那现在如果要把打勾项放入数据库表,我的意思是:
怎样得到打勾项的商品编号,商品名称和价格?
就是insert into goodsave value("?","?","?")
这三个问号怎么搞?
这三个问号怎么搞?
{
$r=mysql_query("select * from goods where id=$id");
$rows= mysql_fetch_row($r);
mysql_query("insert into goodsave values($rows[0],'$rows[1]','$rows[2]')");
}