duanpoqiu0919 2013-04-03 04:15
浏览 12

PHP从无线电选择数据中获取输入并插入到MySQL表中

I need a little help here with grabbing data from radio buttons selected by the user and entering the info to a table in my database.

My purpose is trying to create a dynamic website that grabs new tables entered in with data on it and posting it on the home page automatically. It will be a type of bidding/auction type of website.

First problem is I'm trying to get it to check if there are errors (entered in purposely or not purposely by the user)

If possible can the info below be entered into an array for storage as well? (not sure if I'm asking this right)

<form action="" method="post">
<ul>
<li>
Assault Ships:<br>
<input type="radio" name="item_ship" value="item_cruiser">Cruiser<br>
<input type="radio" name="item_ship" value="item_carrier">Carrier<br>
</li>
<li>
Pick a ticket:<br>
<input type="radio" name="item_tickets" value="ticket_one">One<br>
<input type="radio" name="item_tickets" value="ticket_two">Two<br>
<input type="radio" name="item_tickets" value="ticket_three">Three<br>
<input type="radio" name="item_tickets" value="ticket_four">Four<br>
<input type="radio" name="item_tickets" value="ticket_five">Five<br>
<input type="radio" name="item_tickets" value="ticket_six">Six<br>
<input type="radio" name="item_tickets" value="ticket_seven">Seven<br>
<input type="radio" name="item_tickets" value="ticket_eight">Eight<br>
</li>
<li>
<input type="submit" value="List Item">
</li>
</ul>
</form>

So what will happen when finished, is the user will select what item they want to list, and then choose what ticket they would like to purchase, this data is entered into my db_table and then my other script will display it on the home page where other people will buy the remaining tickets.

If I'm missing anything, please ask... kinda new to this. Looking forward to some great minds on these boards!!

  • 写回答

1条回答 默认 最新

  • dongmacheng3222 2013-04-03 04:20
    关注

    Here is an example considering you have a radio button with a name attribute of radio_name -

    HTML:

    <input type="radio" checked="checked" name="radio_name" />
    

    Get POST value:

    if(isset($_POST['radio_name']) && !empty($_POST['radio_name'])){
        $radioContent= $_POST['radio_name'];
    }
    

    Insert into database (using mysqli prepared statements):

    $sql = "INSERT INTO yourTable(
            rowName
            ) 
            VALUES (?)";
    
    if($stmt = $mysqli->prepare($sql)){
        $stmt->bind_param("i", $radioContent);
        $stmt->execute();
        $stmt->close();
    }
    else{
        error_log($mysqli->error);
    }
    

    Resources to use:

    Insert into (MYSQL)

    Radio button POST

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制