1
我試圖爲我的網站實現一個兩步註冊表單,其中我使用了2個單獨的頁面以便從用戶那裏獲取信息。使用會話的多步註冊表單PHP/MySql
第一步:
if($submit)
{
$connect = mysql_connect("localhost","root","");
mysql_select_db("mydb");
$queryreg = mysql_query("INSERT INTO volunteerbio VALUES (<my insert values>)");
}
//gets the latest id added
$query = mysql_query("SELECT MAX(volunteerID) FROM volunteerbio");
$numrows = mysql_num_rows($query);
if($numrows!=0)
{
while($row = mysql_fetch_assoc($query))
{
$dbaccountID = $row['volunteerID'];
}
header("Location: http://localhost/RedCrossCaloocan/registration2_volunteer.php");
$_SESSION['volunteerID']=$dbaccountID;
}
}
?>
什麼的第一步做的是,它創建了一個完整的錶行,其中所需的第二個步驟中的值將與空值暫時離開,直到它們被更新下一步。
第二步:
<?php
session_start();
$idnum = @$_SESSION['volunteerID'];
$connect = mysql_connect("localhost","root","");
mysql_select_db("mydb");
if($submit)
{
$updateSkills = mysql_query("
UPDATE volunteerbio
SET medicalSkillRating = $medicalRating,
electronicsSkillRating = $electronicRating,
errandSkillRating = $errandRating,
childCareSkillRating = $childCareRating,
counsellingSkillRating = $counsellingRating,
officeSkillRating = $officeRating,
communicationSkillRating =$communicationRating,
carpentrySkillRating = $carpentryRating
WHERE volunteerID = $idnum;
");
}
?>
第二步基本上更新其中其中在爲了完成註冊的第一步填充空值的字段。
第一步已經工作,並且能夠將值添加到數據庫,但是,我在通過第二步更新空白值時遇到問題。
我有一種感覺,爲了從第一步獲取新生成的ID,我的會話使用可能存在問題,但我無法弄清楚。
管理修復它。似乎我在使用MAX時必須更改一些名稱。感謝您的幫助和偉大的編碼建議! – Programmer 2012-02-13 12:46:05
NP。歡迎來到SO! – PeeHaa 2012-02-13 12:49:00