Re: [請益] 真的沒辦法了..

看板PHP作者 (諾蘭德)時間19年前 (2007/01/12 23:14), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/6 (看更多)
經過又試了四五個小時以後 總算可以新增資料 這是用戶端的程式 <html> <head> <title>投票系統</title> <head> <body> <CENTER><FONT SIZE='7' COLOR='#FF0000'>投票主題</FONT></CENTER><HR> <CENTER>請問一下你(妳)對這次高鐵成行的看法,你給高鐵局打幾分 ?</CENTER><BR><BR><BR> <form method="post" action="show_poll.php"> <input type="radio" name="vote" value="Good">還不錯<br /> <input type="radio" name="vote" value="soso">有點糟<br /> <input type="radio" name="vote" value="bad">太差了<br /><br /> <input type="submit" value="投票並立即開票"> </form> </body> 伺服端的程式 <?php $vote=$HTTP_POST_VARS['vote']; if (!$db_conn = @mysql_connect('localhost', 'a94213066', 'a94213066')) { echo 'Could not connect to db<br />'; exit; }; @mysql_select_db('a94213066'); if (!empty($vote)) // if they filled the form out, add their vote { $vote = addslashes($vote); $query = "update poll_results set num_votes = num_votes + 1 where candidate = '$vote'"; if(!($result = @mysql_query($query, $db_conn))) { echo 'Could not connect to db<br />'; exit; } }; // get current results of poll, regardless of whether they vote $query = 'select * from poll_results'; if(!($result = @mysql_query($query, $db_conn))) { echo 'Could not connect to db<br />'; exit; } $num_candidates = mysql_num_rows($result); // calculate total number of votes so far $total_votes=0; while ($row = mysql_fetch_object ($result)) { $total_votes += $row->num_votes; } mysql_data_seek($result, 0); @mysql_connect($good,$db_conn); $good = "select num_votes from poll_results where good"; ?> 我現在的方式是把值全存在同一個table裡面(poll_results) 然後將欄位分成 good,soso,bad 其初始值為零 每次假如點選後案送出其值就+1 不過現在我變成不知道怎樣讓網頁顯示出來分別查詢 good soso bad 的值 請問一下我應該要輸入哪些程式才可以叫出我想要的值呢? 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.22.18.92

01/12 23:17, , 1F
$HTTP_POST_VARS['vote']; 可以用 $_POST['vote'];替代
01/12 23:17, 1F
文章代碼(AID): #15fwNhL2 (PHP)
文章代碼(AID): #15fwNhL2 (PHP)