Results 1 to 9 of 9

Thread: My First PHP didn't work!

  1. #1
    Join Date
    Aug 2001
    Posts
    11
    Rep Power
    0

    My First PHP didn't work!

    File 1

    <HTML>
    <BODY>
    <form method="post" action="datain.php">
    First name:<input type="Text" name="first"><br>
    Last name:<input type="Text" name="last"><br>
    Nick Name:<input type="Text" name="nickname"><br>
    E-mail:<input type="Text" name="email"><br>
    Salary:<input type="Text" name="salary"><br>
    <input type="Submit" name="submit" value="Enter information">
    </form>
    </HTML>


    File 2

    <HTML>
    <?php
    $db = mysql_connect("localhost", "root","");
    mysql_select_db("learndb",$db);
    $sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary)
    VALUES ('$first','$last','$nickname','$email','$salary')" ;
    $result = mysql_query($sql);
    echo "Thank you! Information entered.\n";
    ?>
    </HTML>

    Why the mysql didn't add row?
    It that is becoz i am using phpdev for installing phpmyadmin & apache?

    pls advise

  2. #2
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    your first PHP is so complex.

    Do you get any error message? Make sure the database is connected.

    Also, your PHP file does not grab the input value at all. Please refer to "PHP Manual - Variables from outsite PHP" [ http://my2.php.net/variables.external ]

    Also your SQL query is not correct, try to replace this line:
    PHP Code:
    $sql "INSERT INTO personnel (firstname, lastname, nick, email, salary)
    VALUES ('
    $first','$last','$nickname','$email','$salary')"
    With this line:
    PHP Code:
    $sql "INSERT INTO personnel (firstname, lastname, nick, email, salary)
    VALUES ('" 
    $first "','" $last "','" $nickname "','" $email ."','" $salary "')"
    Hope this helps.
    Last edited by lcf; 22-10-2004 at 05:56 PM.

  3. #3
    Join Date
    Sep 2004
    Location
    Shah Alam
    Posts
    68
    Rep Power
    185
    please paste the errors here...

  4. #4
    Join Date
    Jun 2001
    Location
    Mystic Kingdoms
    Posts
    2,749
    Rep Power
    278
    aku rasa ini mungkin ada kaitan dengan php register globaf = off.
    sebab versi terkini register global tuh off by default!.

    try test paparkan data dalam bentuk biasa saja dulu...
    echo "$first $last $nickname";

    kalau output dari form tuh tak berjaya keluar.. so cubalah test :
    $satu = $_POST['first'];
    baru gunakan var dia..

    aku pun rasa susah lepas register global nih off.. bila aku enablekan semula dalam php ini.. aku pikir2 better aku start learn semula dengan register global off

  5. #5
    Join Date
    Sep 2004
    Location
    Shah Alam
    Posts
    68
    Rep Power
    185
    hah ado kemungkinan

  6. #6
    Join Date
    Apr 2002
    Location
    kuantan, pahang
    Posts
    58
    Rep Power
    214
    lebih selamat kita guna $_POST array nih, pergantungan kepada register global akan memudahkan penggodam menjalankan aktiviti

    sebelum masukkan data dalam mysql, jangan lupa escape string tu dulu menggunakan addslashes($string), atau pun mysql_escape_string($string)

  7. #7
    Join Date
    Apr 2002
    Location
    kuantan, pahang
    Posts
    58
    Rep Power
    214
    cara yang boleh dilakukan, sekiranya register global on,kalo kita malas nak buat
    PHP Code:
    $nama=$_POST['nama'];
    $email=$_POST['email']; 
    kita boleh guna "variable variable"
    letak kod ni kat ataaas skali..
    PHP Code:
    foreach ($_POST as $key => $value){
    $
    $key $value;


  8. #8
    Join Date
    Nov 2003
    Location
    Penang / Perak / Kedah
    Posts
    34
    Rep Power
    0
    raser macam taq tue tak betul...sebab <html> tak boleh ada sebelum php taq..kena ader selepas....kiranya macam nie ler....

    <?
    echo "hai.";
    ?>

    <html>
    <head>
    ........
    Regards,
    Khairul
    Wireless PBX
    Cheap Hosting!!

  9. #9
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    PHP code can be any where in the page. But a good programming practise is put all php code above HTML code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Work at home
    By veep1331 in forum Job Vacancies
    Replies: 1
    Last Post: 13-07-2009, 12:06 PM
  2. How come he doesn't have to work???
    By RB388 in forum Member Introductions
    Replies: 14
    Last Post: 10-01-2007, 11:53 PM
  3. Don't want to pay to work at home?
    By gold2006 in forum Job Vacancies
    Replies: 1
    Last Post: 08-04-2005, 03:03 PM
  4. How this work ???
    By koisempoi in forum Website Programming
    Replies: 4
    Last Post: 04-06-2004, 04:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112