我遇到了將字符串與字符進行比較的麻煩。 我有一個下拉菜單,有兩個選項1.教練2.運動員。提交時,值「C」或「A」存儲在我的數據庫的「類型」下。我已經讓程序看看是否已經創建了「user」,並且如果「user」不存在,它將創建一個目錄。因此,只有當「C」作爲用戶帳戶「類型」提交時才能夠創建目錄。PHP將字符串與字符比較
我下面的代碼:mytest.php
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$database = "basketball_database";
$table = "users";
mysql_connect($hostname, $username, $password)
or die("Unable to connect to MYsql");
// echo "Connected to mysql<br>";
mysql_select_db("$database")
or die("Could not select Basketball_database");
//echo "Connected to database";
//check to see if user exists
$userquery = mysql_query("SELECT login_name FROM $table WHERE login_name='$_POST[loginName]'");
if (mysql_num_rows($userquery) != 0)
{
echo "Username already exists";
}//end user exists
//insert data to database
else
{
//insert into database
$mysql = "INSERT INTO $table(login_name, password, last_name, first_name, type) VALUES('$_POST[loginName]','$_POST[password]','$_POST[lastName]','$_POST[firstName]','$_POST[dropdown]')";
echo "User was added";
echo '<br>';
if(!mysql_query($mysql))
die("Disconnected");
mysql_close();
我需要幫助的部分。
//創建文件夾
//check to see if user is coach
$typequery = mysql_query("SELECT type FROM $table WHERE type='$_POST[dropdown]'");
$Ctype="C";
if (strcmp($typequery,$Ctype))
{
echo "Directory not created for Athletes";
}// directory for athletes
//Submit button create directory
else
{
if(isset($_POST['reg_submit'])){
$username=$_POST['loginName'];
$cur = getcwd();
if(is_dir($cur . '/'.$username))
{
echo "Directory Exists";
}//end directory exist
//create directory
else{
$new = mkdir($cur . '/'.$username, 0777);
if ($new) {
echo '<p>Directory created</p>';
} //end directory created
else {
echo '<p>Directory not created</p>';
}//end directory failed
}//end create directory
}// end Submit button create directory
}//end insert data to database
}//end else user exist
?>
<html>
<title>User Added</title>
<body>
</body>
<form action="users-form.php" method="post">
<input type="submit" value="Add Another User">
</form>
</html>
如果需要使用提交按鈕讓我知道了相應的頁面。謝謝
什麼問題 –
的問題是我希望能夠提交表單輸入用戶名和用戶類型,然後創建一個文件夾只有當用戶類型爲「C」並且回顯出「如果用戶類型爲」A「時未爲運動員創建的文件夾」被選中 –