2014-01-13 2 views
0

저는 학교 직원이 특정 게시물이나 경품에 대해 학생을 지명 할 수있는 온라인 대학 입학을 위해 노력했습니다. 프론트 엔드에는 css를, 백엔드에는 phpmyadmin을 사용했습니다. 그러나 일단 학생을 지명하기 위해 입력 (regno)을하면 테이블에서 업데이트되지 않습니다. 누구든지 도와 줄 수 있습니까? 내 코드 :입력을 사용하여 phpmyadmin의 테이블을 업데이트하십시오.

<!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>NOMINATE ENTRIES</title> 
<meta author="" content=""> 
<link rel="stylesheet" type="text/css" href="view.css" media="all"> 
</head> 
<body id="main_body" > 
    <img id="top" src="top.png" alt=""> 
    <div id="form_container"> 
     <h1><a>Nominate Entries</a></h1> 
     <form name="form5" class="appnitro" method="post" action="test.php"> 
        <div class="form_description"> 
      <center><h2>Students Database</h2></center> 
      <p><center><font size='3'> 

<?php 
$con=mysqli_connect("localhost","staff","12345","mop"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

$result = mysqli_query($con,"SELECT * FROM `student` WHERE `Nominated` = 0"); 

echo "<table border='1'> 
<tr> 
<th>Register No</th> 
<th>Department &nbsp </th> 
<th>Name &nbsp &nbsp &nbsp </th> 
<th>Class &nbsp </th> 
</tr>"; 

while($row = mysqli_fetch_array($result)) 
    { 
    echo "<tr>"; 
    echo "<td>" . $row['RegNo'] . "</td>"; 
    echo "<td>" . $row['Name'] . "</td>"; 
    echo "<td>" . $row['Department'] . "</td>"; 
    echo "<td>" . $row['Class'] . "</td>"; 
    echo "</tr>"; 
    } 
echo "</table>"; 

if(isset($_POST['submit'])) 
{ 
$regno = $_POST['regno']; 
$reason = $_POST['reason']; 
$sql = "UPDATE `mop`.`student` SET `Nominated` = \'1\' WHERE `student`.`RegNo` = 1106103;";} 
mysqli_close($con); 
?> 
</center></font> 
      </p> 
     </div> 
     <b>Enter Register Number <font color='red'>*</font> </b> <input type="text" id="regno" name="regno"><br> 
     <b>Enter Reason <font color='red'>*</font> </b> <input type="text" id="reason" name="reason"><br> 
      <ul > 
        <center><li class="buttons"> 
       <input type="hidden" name="form_id" value="768845" /> 
       <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /></center> 
     </li> 
      </ul> 
     </form> 
    </div> 
    <img id="bottom" src="bottom.png" alt=""> 
    </body> 
</html> 
+0

오류 메시지가 무엇인가요? – ajtrichards

+0

도 양식을 보여줍니다. – msturdy

+2

phpmyadmin은 데이터베이스가 아닙니다. MySQL은 테이블과 인덱스가있는 데이터베이스이며 whotnot이며, phpmyadmin은 클라이언트 스크립트로 사용할 수 있습니다. PHP 코드는 phpmyadmin이 아니라 MySQL에 액세스합니다. –

답변

1

실제로 쿼리를 보내지 않았습니다. $connection

$result = $connection -> query($sql); 

// Or, since it is only an update 

$connection -> query($sql); 

내가이 선생님처럼 전체 파일을 변경하여 DB

+0

에 대한 질문을 업데이 트했습니다. 실제로 it.see 내 전체 코드를 내 질문을 다시 업데이 트했습니다. –

+0

@YeshwanthVShenoy, 선택한 쿼리에 대해했던 것처럼 업데이트 된 쿼리를 실행하지 않았습니다. 쿼리에서 변수를 할당 한 후에는 mysql_query를 사용하여 실행해야합니다. – developerCK

+0

나는 더 이상 설명 할 수 없습니까? –

0

에 연결입니다. UR 입력이 다른 사람에 대한 정보를 공유하고 싶었 모든 감사 :

<?php 
$con=mysqli_connect("localhost","staff","123456","mop"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 
$sql1="UPDATE student SET Reason = '$_POST[reason]' WHERE RegNo ='$_POST[regno]'"; 
if (!mysqli_query($con,$sql1)) 
    { 
    die('Error: ' . mysqli_error($con)); 
    } 
    else 
    { 
    $sql2="INSERT INTO nominated select * from student where regno = '$_POST[regno]'"; 
    if (!mysqli_query($con,$sql2)) 
    { 
    die('Error: ' . mysqli_error($con)); 
    } 
    else 
    { 
    $sql3="DELETE from student where regno = ".intval($_POST["regno"]); 
    if (!mysqli_query($con,$sql3)) 
    { 
    die('Error: ' . mysqli_error($con)); 
    } 
    } 
} 
header("location:form5_1.php"); 

mysqli_close($con); 
?> 
:

<!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>NOMINATE ENTRIES</title> 
<meta author="" content=""> 
<link rel="stylesheet" type="text/css" href="view.css" media="all"> 
</head> 
<body id="main_body" > 
    <img id="top" src="top.png" alt=""> 
    <div id="form_container"> 
     <h1><a>Nominate Entries</a></h1> 
     <form name="form" class="appnitro" method="post" action="test.php"> 
        <div class="form_description"> 
      <center><h2>Students Database</h2></center> 
      <p><center><font size='3'> 
      <?php 
$con=mysqli_connect("localhost","staff","123456","mop"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

$result = mysqli_query($con,"SELECT * FROM student"); 

echo "<table border='1'> 
<tr> 
<th>Register No</th> 
<th>Name &nbsp &nbsp &nbsp </th> 
<th>Department &nbsp </th> 
<th>Class &nbsp </th> 
</tr>"; 

while($row = mysqli_fetch_array($result)) 
    { 
    echo "<tr>"; 
    echo "<td>" . $row['RegNo'] . "</td>"; 
    echo "<td>" . $row['Name'] . "</td>"; 
    echo "<td>" . $row['Department'] . "</td>"; 
    echo "<td>" . $row['Class'] . "</td>"; 
    echo "</tr>"; 
    } 
echo "</table>"; 

mysqli_close($con); 
?> 
</center></font> 
      </p> 
     </div> 
     <b>Enter Register Number <font color='red'>*</font> </b> <input type="text" name="regno"><p> 
     <b>Enter Reason <font color='red'>*</font> </b> <input type="text" name="reason"><p> 

        <ul > 
        <center><li class="buttons"> 
       <input type="hidden" name="form_id" value="768845" /> 
       <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /></center> 
     </li> 
      </ul> 
     </form> 
    </div> 
    <img id="bottom" src="bottom.png" alt=""> 
    </body> 
</html> 

가 여기에 test.php 파일을 참조하고도 그 파일 : 여기

내 form.php 파일입니다

관련 문제