2011-12-20 46 views
0

這是我的代碼,我需要我的消息出現在窗體頂部,但出現錯誤。 我需要打印我的信息的地方,我把代碼打印$ msg如何將我的消息放在我想要的地方使用php

關於這個請任何想法。

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> 
     <table width="300" border="0"> 
     <tr> 
     <td colspan="2"><?php print($msg); ?></td> 
     </tr> 
     <tr> 
      <td> *First name</td> 
      <td><span id="sprytextfield3"> 
      <input type="text" value="" name="RFname" /> 
      <br> 
      <span class="textfieldRequiredMsg">A value is required.</span></span></td> 
     </tr> 
     <tr> 
      <td>*Last name</td> 
      <td><span id="sprytextfield4"> 
      <input type="text" value="" name="RLname" /> 
      <br> 
      <span class="textfieldRequiredMsg">A value is required.</span></span></td> 
     </tr> 
     <tr> 
      <td>*User name</td> 
      <td><span id="sprytextfield1"> 
      <input type="text" name="UserName" value="" /> 
      <br /> 
      <span class="textfieldRequiredMsg">A value is required.</span></span></td> 
     </tr> 
     <tr> 
      <td>*Password</td> 
      <td><span id="sprypassword1"> 
      <input type="password" name="UserPass" value="" /> 
      <span class="passwordRequiredMsg"><br /> 
      A value is required.</span></span></td> 
     </tr> 
     <tr> 
      <td>*Email</td> 
      <td><span id="sprytextfield2"> 
      <input type="text" name="UserEmail" value="" /> 
      <br /> 
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td> 
     </tr> 
     <tr> 
      <td>Web site</td> 
      <td><input type="text" name="WebSite" value="" /></td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td><input name="submited" type="submit" onClick="MM_swapImage('Image1','','images/blog.png',1)" value="Register"/></td> 
     </tr> 
     </table> 
    </form> 
    </div> 
    <div class="image_NewUserRegister"><iframe src="images/Untitled-2.jpg" name="now_regist" width="207" height="280" scrolling="no" frameborder="0"></iframe></div> 
    </div> 
    <?php 
     if(isset($_POST['submited'])) { 
      $RFname = $_POST['RFname']; 
      $RLname = $_POST['RLname']; 
      $USERname = $_POST['UserName']; 
      $USERpassword = $_POST['UserPass']; 
      $USERemail = $_POST['UserEmail']; 
      $USERwebsite = $_POST['WebSite']; 

      $check=$db->query("select 1 from loginaccess where Email ='".$USERemail."'"); 

      if(mysqli_num_rows($check) > 0) { 
       $msg = "<span style='color:#F00; font-size:14px; font-weight:bold;'>This email already taken</span>"; 
       } 

這是我的代碼,我需要我的消息出現在我的窗體的頂部,但我得到了一個錯誤。我需要打印我的信息的地方,我把代碼打印$ msg

關於這個請任何想法。

回答

2

您確實需要在之前設置消息,然後嘗試輸出它。

+0

你能告訴我一個例子,請 – 2011-12-20 22:16:07

+1

無聊的人,希望他們的馬先於他們的車...:] – 2011-12-20 22:19:16

+0

天向T.感謝重播,但我來這裏是爲了解決一些不傻反正我會盡力做你剛告訴我的事情,我需要時間來調整我的代碼頁中的每一件事,因爲它很大謝謝親愛的泰森T.對你而言很棒 – 2011-12-21 15:02:05

1

爲了詳細說明大衛的回答是:形式標記之前挪動了PHP塊,像這樣:

<?php 
     if(isset($_POST['submited'])) { 
      $RFname = $_POST['RFname']; 
      $RLname = $_POST['RLname']; 
      $USERname = $_POST['UserName']; 
      $USERpassword = $_POST['UserPass']; 
      $USERemail = $_POST['UserEmail']; 
      $USERwebsite = $_POST['WebSite']; 

      $check=$db->query("select 1 from loginaccess where Email ='".$USERemail."'"); 

      if(mysqli_num_rows($check) > 0) { 
       $msg = "<span style='color:#F00; font-size:14px; font-weight:bold;'>This email already taken</span>"; 
      } 
    ?> 
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> 
     <table width="300" border="0"> 
     <tr> 
     <td colspan="2"><?php print($msg); ?></td> 
     </tr> 
     <tr> 
      <td> *First name</td> 
      <td><span id="sprytextfield3"> 
      <input type="text" value="" name="RFname" /> 
      <br> 
      <span class="textfieldRequiredMsg">A value is required.</span></span></td> 
     </tr> 
     <tr> 
      <td>*Last name</td> 
      <td><span id="sprytextfield4"> 
      <input type="text" value="" name="RLname" /> 
      <br> 
      <span class="textfieldRequiredMsg">A value is required.</span></span></td> 
     </tr> 
     <tr> 
      <td>*User name</td> 
      <td><span id="sprytextfield1"> 
      <input type="text" name="UserName" value="" /> 
      <br /> 
      <span class="textfieldRequiredMsg">A value is required.</span></span></td> 
     </tr> 
     <tr> 
      <td>*Password</td> 
      <td><span id="sprypassword1"> 
      <input type="password" name="UserPass" value="" /> 
      <span class="passwordRequiredMsg"><br /> 
      A value is required.</span></span></td> 
     </tr> 
     <tr> 
      <td>*Email</td> 
      <td><span id="sprytextfield2"> 
      <input type="text" name="UserEmail" value="" /> 
      <br /> 
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td> 
     </tr> 
     <tr> 
      <td>Web site</td> 
      <td><input type="text" name="WebSite" value="" /></td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td><input name="submited" type="submit" onClick="MM_swapImage('Image1','','images/blog.png',1)" value="Register"/></td> 
     </tr> 
     </table> 
    </form> 
    </div> 
    <div class="image_NewUserRegister"><iframe src="images/Untitled-2.jpg" name="now_regist" width="207" height="280" scrolling="no" frameborder="0"></iframe></div> 
    </div> 

HTH。

+0

感謝泰森T.但是沒有任何其他方式可以解決這個問題,我肯定有一個方法 – 2011-12-20 22:20:43

+0

還有其他方法,你可以改變'print($ msg);'在你的PHP代碼中調用一個函數來生成消息。 – 2011-12-20 22:23:52

+0

@Yousef不,沒有。在腳本運行之前,變量不會被分配。這是純粹的順序編程。編輯:大衛有一點,但現在,我仍然認爲答案是「不」。 – 2011-12-20 22:23:55

相關問題