Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

製作PHP留言板 取不到POST值

我一開始就有先設計好~留言板輸入姓名、EMAIL、及內容之後,然傳送有指定到去php程式執行。可是為什麼出現Notice: Use of undefined constant name - assumed 'name' in c:\\www\\guest_add.php on line 5Notice: Use of undefined constant email - assumed 'email' in c:\\www\\guest_add.php on line 6Notice: Use of undefined constant messages - assumed 'messages' in c:\\www\\guest_add.php on line 7Notice: Use of undefined constant ip_show - assumed 'ip_show' in c:\\www\\guest_add.php on line 8Notice: Use of undefined constant REMOTE_ADDR - assumed 'REMOTE_ADDR' in c:\\www\\guest_add.php on line 12Warning: Cannot modify header information - headers already sent by (output started at c:\\www\\gbphp.php:20) in c:\\www\\guest_add.php on line 22

Update:

gbphp.php 執令

$dbhost = "localhost"; $dbuser = "root"; $dbpass = "abc"; $dbname = "gbphp"; $admin = "abc"; $passwd = "123";

Update 2:

guest_add.php 執令

include("gbphp.php");

$name =$_POST[name]; $email =$_POST[email];

$messages =$_POST[messages];

$sql = "insert into guest (name,email,messages)

values('$name','$email','$messages')";

mysql_query($sql);

3 Answers

Rating
  • 1 decade ago
    Favorite Answer

    這應該是你的 PHP 版本是 5.x 版的吧! 5.x 版的有加強一些防護措施才會發生你所遇到的問題。

    請參考官方網址: http://tw.php.net/manual/en/tutorial.oldcode.php

    最快的解決方式(但官方認為不是最安全的)

    在你的 php.ini 找出下列並修改:

    register_globals = Off 改成 On

    register_argc_argv = Off 改成 On

    以下兩項要不要修改,看你還會不會有錯誤訊息出現。(官方認為不是最安全的)

    allow_call_time_pass_reference = Off 改成 On

    register_long_arrays = Off 改成 On

    修改完後,重起你的網頁伺服器。

    不做檢查就直接抓 form 的東西是會很危險的,5.x版應該會要求你先做檢查。

    建議用這種方式:

    // get url values

    if( array_key_exists('type', $_GET) ) // or $_POST

    $edit_type = $_GET['type'];

    else

    $edit_type = "new";

    2006-10-23 01:30:44 補充:

    另外在 $_POST[xxx] 方框內的東西需要用引號或雙引號包起來。例如: $_POST['xxx'] 或 $_POST["xxx"]

  • 1 decade ago

    $name =$_POST[name];

    $email =$_POST[email];

    你寫錯了喔

    $name =$_POST["name"];

    $email =$_POST["email"];

    你少了 "

  • 1 decade ago

    因為用post 等去取變數時,要加雙引號

    $name =$_POST[name];

    就要變成

    $name =$_POST["name"];

    上面的錯誤訊息就是指找不到 name 這個變數(此網頁的name,不是post的name)

    Source(s): 自已
Still have questions? Get your answers by asking now.