douduiti3040 2014-01-17 17:28
浏览 21
已采纳

向用户配置文件添加详细信息(将登录用户和当前gig插入新表的查询)

Ok guys, I am building a prototype ticket system where I have user profiles

<li><a href="profile.php?user=<?php echo escape($user->data()->username); ?>">Profile</a></li>

a users details are stored in `users table in my database.

I also have a gig table called bands. I show the bands with this code

Band code

    <?php
require 'core/init.php';


$Band_id = $_GET['id'];
$result = mysql_query("SELECT * FROM bands WHERE Band_id = $Band_id");

echo "<table border = '1'>
<tr>
    <th>Band Name</th>
    <th>Venue</th>
    <th>Category</th>
    <th>Stock</th>
    <th>Add</th>
</tr>";

    while($row = mysql_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>" .$row['Name']. "</td>";
        echo "<td>" .$row['Venue']. "</td>";
        echo "<td>" .$row['Category']. "</td>";
        echo "<td>" .$row['Stock']. "</td>";
        echo "<td><button>Buy Ticket</button></td>";
        echo "</tr>";
    }
echo "</table>";


?>

I have just made a new table called orders. with two rows, band_id and user_id.

question

how can I build a query that would insert the band id from the current band and the current logged in user to the table order so I can use it later? (insert on button click)

Any help will be fantastic as I am rather stuck, Thank you.

Im thinking Insert `$Band_id` and `$user` in to `order` table.
  • 写回答

2条回答 默认 最新

  • douzhong1730 2014-01-17 17:44
    关注

    use hidden field for brand id in your form like this: you should use form for this.

    while($row = mysql_fetch_array($result))
        {
            echo "<tr><form name=\"myform\" action=\" something.php\"  method=\"post\">";
           echo "<td> <input name=\"brand\" type=\"hidden\" value=\"". $Band_id."\" ></td>";
            echo "<td>" .$row['Name']. "</td>";
            echo "<td>" .$row['Venue']. "</td>";
            echo "<td>" .$row['Category']. "</td>";
            echo "<td>" .$row['Stock']. "</td>";
            echo "<td><button>Buy Ticket</button></td>";
            echo "<td><input type=\" submit\" value=\"Buy Ticket\"></td>";
            echo "</tr> </form>";
        }
    

    and use session for saving user id. after submitting the form get values from form and insert it your order table.

    in your something.php

    session_start();
    $brand_id = $_REQUEST['brand'];
    $user_id = $_SESSION['user_id'];
    
     $sql = "insert into order (brand_id,user_id) values($brand_id,$user_id)";
    // then execute this query
    

    i think it will work :)

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

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?