2012-04-27 49 views
0

我需要構建HTML頁面來顯示和組織我的結果。我在哪裏放置HTML?我試過了,我得到錯誤。它是否進入PHP腳本? php腳本之後?之前?困惑。通過php建立搜索結果頁面

<?php 

if (isset($_POST['Submit'])) { 
if (!empty($_POST['reg'])) { 

    $record = $_POST['reg']; 

    $query = mysql_query("SELECT * FROM reg_add WHERE reg='" . mysql_real_escape_string($record) . "'"); 
    $result = mysql_num_rows($query); 

    if ($result != 0) { 

     $row = mysql_fetch_array($query); 

     $connect_date = $row['connect_date']; 
     $reg = $row['reg']; 
     $first_name = $row['first_name']; 
     $last_name = $row['last_name']; 
     $nickname = $row['nickname']; 
     $gender = $row['gender']; 
     $birthday = $row['birthday']; 
     $home_state = $row['home_state']; 
     $national = $row['national']; 
     $location = $row['location']; 


    } else { 
     header("Location: search_error1.php"); 
     exit; 
    } 

} else { 
    header("Location: search_error2.php"); 
    exit; 
} 
} 
?> 
+0

'我嘗試了,我得到errors'那你試着和你得到了什麼錯誤? – 2012-04-27 14:15:18

回答

2

PHP可嵌入到HTML中,因此您可以在php文件中編寫您的html標記。你只需要放在裏面<?php ?>所有的PHP代碼:

<?php 
    //php code 
?> 
<html> 
<!-- ... --> 
</html> 
<?php /* php again */ ?> 

PHP解釋器會忽略PHP的標籤(<?php ?>)之外的所有書面文本和直接寫入它到標準輸出。因此,對於你

這將是這樣的:

<?php 

// ... 

if ($result != 0) { 
    while($row = mysql_fetch_array($query)) { 
     $connect_date = $row['connect_date']; 
     $reg = $row['reg']; 
     $first_name = $row['first_name']; 
     $last_name = $row['last_name']; 
     $nickname = $row['nickname']; 
     $gender = $row['gender']; 
     $birthday = $row['birthday']; 
     $home_state = $row['home_state']; 
     $national = $row['national']; 
     $location = $row['location']; 
?> 
    First name: <?php echo $first_name ?><br/> 
    Last name: <?php echo $last_name ?><br/> 
    ... 
<?php 
    } 
} 

// ... 

?> 
+0

我嘗試了你寫的內容,並且我的錯誤頁面在腳本中不起作用。 – Erik 2012-04-27 15:13:59

+0

看起來以下不起作用:} else { header(「Location:search_error1.php」); 退出; } } else { header(「Location:search_error2.php」); 退出; – Erik 2012-04-27 15:16:47

+0

@Erik請顯示您的更新代碼。我們將看到有什麼問題 – lazyhammer 2012-04-27 15:45:12