2013-12-03 2 views
1

내 웹 사이트의 등록 양식을 만들었지 만 한 가지 문제가 있습니다.PHP 및 MySQL 선택 상자

나는 city, country, state 및 business_category에 대한 데이터베이스를 만들었습니다.

다른 국가에서만 작동하는이 코드는 왜 작동하지 않습니까?

이 등록 양식 페이지 코드 선택 옵션 :

<?php 
    include("includes/function.php"); 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Untitled Document</title> 
<style> 
    body { 
     margin:0px; 
     padding:0px; 
     } 
.registiration_form { 
    width:415px; 
    height:auto; 
    margin-left:auto; 
    margin-right:auto; 
    margin-top:200px; 
    }  
.name_surname{ 
    width:415px; 
    height:40px; 
    float:left; 
    } 
.sirket_adi { 
    width:415px; 
    height:40px; 
    float:left; 
    margin-top:10px; 
    } 
.sirket_adi input{ 

     width:420px; 
     height:40px; 
     text-align:left; 
     text-indent:10px; 
     font-size:18px; 
     font-weight:bold; 
     color:#a9b2bd; 
     border: 1px solid #6ca8c6; 
     border-radius: 3px; 
     float:left; 
      } 
.email { 
    width:415px; 
    height:40px; 
    float:left; 
    margin-top:10px; 
    } 
.email input{ 

     width:420px; 
     height:40px; 
     text-align:left; 
     text-indent:10px; 
     font-size:18px; 
     font-weight:bold; 
     color:#a9b2bd; 
     border: 1px solid #6ca8c6; 
     border-radius: 3px; 
     float:left; 
      } 
.email-tekrar{ 
    width:415px; 
    height:40px; 
    float:left; 
    margin-top:10px; 
    } 
.email-tekrar input{ 

     width:420px; 
     height:40px; 
     text-align:left; 
     text-indent:10px; 
     font-size:18px; 
     font-weight:bold; 
     color:#a9b2bd; 
     border: 1px solid #6ca8c6; 
     border-radius: 3px; 
     float:left; 
      } 
.password{ 
    width:415px; 
    height:40px; 
    float:left; 
    margin-top:10px; 
    } 
.password input{ 

     width:420px; 
     height:40px; 
     text-align:left; 
     text-indent:10px; 
     font-size:18px; 
     font-weight:bold; 
     color:#a9b2bd; 
     border: 1px solid #6ca8c6; 
     border-radius: 3px; 
     float:left; 
      } 
.sirket_kategorisi{ 
    width:415px; 
    height:20px; 
    float:left; 
    margin-top:10px; 
    } 
.sirket_kategorisi select{ 
     width:400px; 
     height:20px; 
     border: 1px solid #6ca8c6; 
     border-radius: 12px;  
     margin-left:12px; 
      } 
.kaydol { 
    width:415px; 
    height:60px; 
    float:left; 
    margin-top:30px; 
    } 
.kaydol_buton { 
    float:left; 
    width:300px; 
    height:60px; 
    margin-left:auto; 
    margin-right:auto; 
    } 
.kaydol_buton input{ 
    width: 300px; 
    height: 60px; 
    padding: 0; 
    -webkit-box-sizing: content-box; 
    -moz-box-sizing: content-box; 
    box-sizing: content-box; 
    color: rgba(255,255,255,1); 
    font: normal 37px/60px "Lucida Grande"; 
    border: none; 
    border:1px solid #6ca8c6; 
    -webkit-border-radius: 5px; 
    -moz-border-radius: 5px; 
    border-radius: 5px; 
    background-image: rgba(235,235,235,1); 
    background-image: -webkit-linear-gradient(top, #299c0a 0%,#207001 100%); 
    background-image: -moz-linear-gradient(top, #299c0a 0%,#207001 100%); 
    background-image: -o-linear-gradient(top, #299c0a 0%,#207001 100%); 
    background-image: -ms-linear-gradient(top, #299c0a 0%,#207001 100%); 
    background-image: linear-gradient(top, #299c0a 0%,#207001 100%); 
    -webkit-box-shadow: rgba(183,183,183,1) 0px 1px 2px 0px, inset rgba(255,255,255,1) 0px 51px 10px -50px; 
    -moz-box-shadow: rgba(183,183,183,1) 0px 1px 2px 0px, inset rgba(255,255,255,1) 0px 51px 10px -50px; 
    box-shadow: rgba(183,183,183,1) 0px 1px 2px 0px, inset rgba(255,255,255,1) 0px 51px 10px -50px; 
} 
.ulke_sehir{ 
    width:415px; 
    height:30px; 
    float:left; 
    margin-top:3px; 
    } 
.ulke { 
    float:left; 
    width:150px; 
    height:30px; 
    margin-left:55px; 
    } 
.ulke select{ 
     width:150px; 
     height:30px; 
     border: 1px solid #6ca8c6; 
     border-radius: 12px; 
     } 
.sehir { 
    float:left; 
    width:150px; 
    height:30px; 
    margin-left:10px; 
    } 
.sehir select{ 
     width:150px; 
     height:30px; 
     border: 1px solid #6ca8c6; 
     border-radius: 12px; 
     } 
.name { 
    float:left; 
    width:200px; 
    height:40px; 
    } 
.name input{ 
      float:left; 
     width:200px; 
     height:40px; 
     text-align:left; 
     text-indent:10px; 
     font-size:18px; 
     font-weight:bold; 
     color:#a9b2bd; 
     border: 1px solid #6ca8c6; 
     border-radius: 3px; 
      } 
.surname{ 
    float:left; 
    width:200px; 
    height:40px; 
    margin-left:15px; 
    } 
.surname input{ 
     width:200px; 
     height:40px; 
     text-align:left; 
     text-indent:10px; 
     font-size:18px; 
     font-weight:bold; 
     color:#a9b2bd; 
     border: 1px solid #6ca8c6; 
     border-radius: 3px; 
     float:left; 
      } 

</style> 
</head> 

<body> 
<form method='post' action='kaydol.php'> 
<div class="registiration_form"> 
<div class="name_surname"> 
    <div class="name"> 
    <input type="name" value="Ad" name="name" autocomplete="off" /> 
    </div> 
    <div class="surname"> 
    <input type="surname" value="Soyad" name="surname" autocomplete="off"/> 
    </div> 
</div> 
<div class="sirket_adi"> 
<input type="sirketadi" value="Şirket Adı" name="business_name" autocomplete="off" /> 
</div> 

<div class="email"><input type="email" name="email" value="E-Mail" /></div> 
<div class="email-tekrar"> <input type="emailagain" value="E-Mail Tekrar" /></div> 
<div class="password"> <input type="password" name="password"value="Şifre" /></div> 
<div class="sirket_kategorisi"><select name="business_category"><?php query()?> 
</select> 
<?php close()?> 
</div> 
<div class="ulke_sehir"> 
<div class="ulke"><select name="country"><?php query()?> 
</select> 
<?php close()?> 
</div> 
<div class="sehir"><select name="city"><?php query()?> 
</select> 
<?php close()?></div> 
</div> 
<div class="kaydol"> 
    <div class="kaydol_buton"> 
    <input type="submit" name="submit" value="Gönder"/> 
    </div> 
</div> 
</div> 
</form> 
</body> 
</html> 
<?php 
    if(isset($_POST['submit'])){ 
     echo $name = $_POST['name']; 
     echo $surname = $_POST['surname']; 
     echo $business_name = $_POST['business_name']; 
     echo $email = $_POST['email']; 
     echo $password = $_POST['password']; 
     echo $business_category = $_POST['business_category']; 
     echo $country = $_POST['country']; 
     echo $city = $_POST['city']; 


     } 


?> 

그리고이 코드는 원하는 테이블을 통과하는 데 필요한 선택 상자

<?php 
include("connect.php"); 
function connect() { 
mysql_connect($db_host,$db_user,$db_pass) or die('happy coding ' . mysql_error()); 
    mysql_select_db($db_name); 
} 


function close() { 


mysql_close(); 

    } 


function query() { 
    $myData = mysql_query("SELECT * FROM country"); 

while($record = mysql_fetch_array($myData)){ 
     echo '<option value="' . $record['country_name'] . '">' . $record['country_name'] . '</option>'; 
    } 

} 
?> 
+0

'국가'에서 선택하는 기능 만 제공했기 때문에. 다른 테이블에서 다른 사용자를 선택해야합니까? –

+0

무엇을 할 수 있습니까? 작동하지 않는 것은 무엇입니까? 당신의 코드에서 당신은 단지 "국가"와 일하고 있습니다 .. 당신은 도시, 비지니스 등등에 관해 아무것도 가지고 있지 않습니다 ... –

+0

왜 소스 테이블 하나만 출력 한 후 당신의 mysql 연결을 close합니까? –

답변

0

연결이 글로벌하지 않습니다. 함수 내부로 전달해야합니다.

여기에있는 동안 mysql_ 기능 사용을 중지하십시오. 그들은 더 이상 유지되지 않습니다 and are officially deprecated. red box을 참조하십시오. prepared statements에 대해 자세히 알아보고 PDO 또는 MySQLi - this article을 사용하면 어떤 결정을 내리는 데 도움이됩니다.

+0

내가 할 수 없었다 :( – EcoWebtr

+0

@EcoWebtr Do * * * – Kermit

+0

@FreshPrienceOfSO 이것은 내 모든 function.php 코드 '$ 기록 [ 'COUNTRY_NAME'] '';.. } } > – EcoWebtr

0

먼저 내 function.php 코드 검색어 기능에 대한 목록

function query($place) { 
    $sql = "SELECT * FROM {$place}"; 
} 

그런 다음 적절한 위치에서 전화 할 수 있습니다 :

query('city'); 

query('country'); 

N.B는 mysqli 또는 PDO 기능을 대신 오래된 mysql_로 기능을 사용하시기 바랍니다.

$mysqli = new mysqli("localhost", "my_user", "my_password", "world"); 

function query($place) { 
    global $mysqli; // I don't like globals but this will fix your problem 

    // create SQL statement as before 
    $sql = "SELECT * FROM {$place}"; 
    $result = $mysqli->query($sql); 
    while ($row = $result->fetch_array()) { 
     // echo stuff here or build result string 
    } 
} 
+0

나는 모든 코드를 말해 줄 수 없다. 그것은 나를 위해 중요합니다. – EcoWebtr

+0

몇 가지 문제를 해결하기위한 개요를 넣었습니다.하지만 불행히도 시간이 조금 제한되어 있으며 질문에 더 많은 코드를 넣어야합니다. 당신은 분명히 * 새로운 mysqli * 문에 자신 만의 연결 매개 변수를 넣어야 만합니다. – vogomatix

+0

country, city 및 bussiness_category에 대해 다른 테이블을 사용하고 있습니다. 기능 코드가 작동하지만 도시에만 해당됩니다. 내가이 기능을 코드를 추가 할 수있는 나라, 도시 및 bussiness_category 작동합니까? – EcoWebtr