本文介绍了向mysql添加信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以即时尝试使用我的html文件连接我的php文件发送信息到mysql并将信息插入表中但它不会工作,我似乎无法找到错误。有谁有想法?



继承人我的HTML。在html文件的底部,我有一个链接到我的php文件的按钮,它应该连接到mysql。



so im trying to use my html file to connect with my php file to send information to mysql and insert the information into the table but it wont work and i cant seem to find the error. anyone have an idea?

heres my html. at the bottom of the html file i have a button linked to my php file that should connect to mysql.

<body>
    <div id="form">
    <form action="signup.php" method="post" />
        <form>
            <h1>Sign up</h1>
                <div id="first" class="line"><label for="firstname">First Name * </label><input type="text" id="firstname" /></div>
                <div id="middle" class="line"><label for="initial">Middle Initial </label><input type="text" id="pwd" /></div>
                <!-- You may want to consider adding a "confirm" password box also -->
                <div id="last" class="line"><label for="lastname">Last Name * </label><input type="text" id="surname" /></div>
                <div id="email" class="line"><label for="email">Email * </label><input type="text" id="names" /></div>
                <div id="cemail" class="line"><label for="cemail">Comfirm Email * </label><input type="text" id="dob" /></div>
                <div id="password" class="line"><label for="password">Password * </label><input type="password" id="tel" /></div>
                <div id="cpassword" class="line"><label for="cpassword">Comfirm Pswd *</label><input type="password" id="tel" /></div>

                <div id="dob">
                Month* <select><option value="month">January</option>
                <option value="month">Febuary</option>
                <option value="month">March</option>
                <option value="month">April</option>
                <option value="month">May</option>
                <option value="month">June</option>
                <option value="month">July</option>
                <option value="month">Augast</option>
                <option value="month">September</option>
                <option value="month">October</option>
                <option value="month">November</option>
                <option value="month">December</option>
                </select>

                Day* <select>
                <option value="day">1</option>
                <option value="day">2</option><option value="day">3</option>
                <option value="day">4</option>
                <option value="day">5</option><option value="day">6</option>
                <option value="day">7</option>
                <option value="day">8</option><option value="day">9</option><option value="day">10</option><option value="day">11</option><option value="day">12</option><option value="day">13</option><option value="day">14</option><option value="day">15</option><option value="day">16</option><option value="day">17</option><option value="day">18</option><option value="day">19</option><option value="day">20</option><option value="day">21</option><option value="day">22</option><option value="day">23</option><option value="day">24</option><option value="day">25</option><option value="day">26</option><option value="day">27</option><option value="day">28</option><option value="day">29</option><option value="day">30</option><option value="day">31</option></select>

                year* <select><option value="year">1930</option><option value="year">1931</option><option value="year">1932</option><option value="year">1933</option><option value="year">1934</option><option value="year">1935</option><option value="year">1936</option><option value="year">1937</option><option value="year">1938</option><option value="year">1939</option><option "">1940</option><option value="year">1941</option><option value="year">1942</option><option value="year">1943</option><option ="">1944</option><option value="year">1945</option><option value="year">1946</option><option value="year">1947</option><option ="">1948</option><option value="year">1949</option><option value="year">1950</option><option value="year">1951</option><option value="year">1952</option><option value="year">1953</option><option value="year">1954</option><option value="year">1955</option><option ="">1956</option><option value="year">1957</option><option value="year">1958</option><option value="year">1959</option><option value="year">1960</option><option value="year">1961</option><option value="year">1962</option><option value="year">1963</option><option value="year">1964</option><option value="year">1965</option><option value="year">1966</option><option value="year">1967</option><option value="year">1968</option><option value="year">1969</option><option value="year">1970</option><option value="year">1971</option><option value="year">1972</option><option value="year">1973</option><option value="year">1974</option><option value="year">1975</option><option value="year">1976</option><option value="year">1977</option><option value="year">1978</option><option value="year">1979</option><option value="year">1980</option><option value="year">1981</option><option value="year">1982</option><option value="year">1983</option><option value="year">1984</option><option value="year">1985</option><option value="year">1986</option><option value="year">1987</option><option value="year">1988</option><option value="year">1989</option><option value="year">1990</option><option value="year">1991</option><option value="year">1992</option><option value="year">1993</option><option value="year">1994</option><option value="year">1995</option><option value="year">1996</option><option value="year">1997</option><option value="year">1998</option><option value="year">1999</option><option value="year">2000</option><option value="year">2001</option><option value="year">2002</option><option value="year">2003</option><option value="year">2004</option><option value="year">2005</option><option value="year">2006</option><option value="year">2007</option><option value="year">2008</option><option value="year">2009</option><option value="year">2010</option><option value="year">2011</option><option value="year">2012</option><option value="year">2013</option></select>
            </div>

                <!-- Valid input types: http://www.w3schools.com/html5/html5_form_input_types.asp -->
                <div id="number" class="line"><label for="tel">Phone Number </label><input type="text" id="tel" /></div>
                <div id="sex1">
                <form>
                    <input type="radio" name="sex" value="male">Male
                    <div id="sex2"><input type="radio" name="sex" value="female">Female</div>
                </form>
            </div>

                <div class="line submit"><a href="dbConfig.php" class="btn">submit</a></div>

        </form>
    </form>
</div>







heres the php file



include (\"signup.html\");

$host = \"68.178.142.193\";

$user = \"RootSpread\";

$pass = \"******\";

$db = \"accounts\";



$ms = mysql_pconnect($host, $user, $pass);

if ( !$ms )

{

echo \"Error connecting to database.\n\";

}



mysql_select_db($db);



if ( $_GET[\"op\"] == \"reg\" )

{

$bInputFlag = false;

foreach ( $_POST as $field )

{

if ($field == \"\")

{

$bInputFlag = false;

}

else

{

$bInputFlag = true;

}

}

if ($bInputFlag == false)

{

die(\"Problem with your registration info.

Please go back and try again.\");

}



$q = \"INSERT INTO `accounts` (`firstname`,`initial`,`lastname`,`email`,`password`,`dob`,`number`,`sex`) \"



.\"VALUES (’\".$_ POST[\"firstname\"].\"’,

’\".$_POST[\"initial\"].\"’,

’\".$_POST[\"lastname\"].\"’,

’\".$_POST[\"email\"].\"’, ’\"

.\"PASSWORD(’\".$_POST[\"password\"].\"’), ’\".$_POST[\"dob\"].\"’, ’\".$_POST[\"number\"].\"’, ’\".$_POST[\"sex\"].\"’) \";



$r = mysql_query($q);



if ( !mysql_insert_id() )

{

die(\"Error: User not added to database.\");

}

else

{



Header(\"Location: index.html\");

}



if( $_GET[\"op\"] == \"thanks\" )

{

echo \"Thanks for registering!\";





?>




heres the php file

include ("signup.html");
$host = "68.178.142.193";
$user = "RootSpread";
$pass = "******";
$db = "accounts";

$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}

mysql_select_db($db);

if ( $_GET["op"] == "reg" )
{
$bInputFlag = false;
foreach ( $_POST as $field )
{
if ($field == "")
{
$bInputFlag = false;
}
else
{
$bInputFlag = true;
}
}
if ($bInputFlag == false)
{
die("Problem with your registration info.
Please go back and try again.");
}

$q = "INSERT INTO `accounts` (`firstname`,`initial`,`lastname`,`email`,`password`,`dob`,`number`,`sex`) "

."VALUES ('".$_POST["firstname"]."',
'".$_POST["initial"]."',
'".$_POST["lastname"]."',
'".$_POST["email"]."', '"
."PASSWORD('".$_POST["password"]."'), '".$_POST["dob"]."', '".$_POST["number"]."', '".$_POST["sex"]."') ";

$r = mysql_query($q);

if ( !mysql_insert_id() )
{
die("Error: User not added to database.");
}
else
{

Header("Location: index.html");
}

if( $_GET["op"] == "thanks" )
{
echo "Thanks for registering!";


?>

推荐答案




这篇关于向mysql添加信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:59