Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 22-10-2004, 04:26 PM
Novice Webmaster
 
Join Date: Aug 2001
Posts: 11
Rep Power: 0
maman is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 22-10-2004, 05:49 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
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.
__________________
LiewCF | Malaysia Bloggers Forum

Last edited by lcf; 22-10-2004 at 05:56 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 22-10-2004, 09:31 PM
Novice Webmaster
 
Join Date: Sep 2004
Location: Shah Alam
Posts: 68
Rep Power: 51
infeeneetee is on a distinguished road
please paste the errors here...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 22-10-2004, 11:06 PM
mysticmind's Avatar
Super Moderator
 
Join Date: Jun 2001
Location: Mystic Kingdoms
Posts: 2,633
Rep Power: 142
mysticmind will become famous soon enough mysticmind will become famous soon enough
Send a message via Yahoo to mysticmind
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
__________________
Personal's Blog! - Malaysian Artist!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 22-10-2004, 11:54 PM
Novice Webmaster
 
Join Date: Sep 2004
Location: Shah Alam
Posts: 68
Rep Power: 51
infeeneetee is on a distinguished road
hah ado kemungkinan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 23-10-2004, 01:07 AM
Gemp-X's Avatar
Novice Webmaster
 
Join Date: Apr 2002
Location: kuantan, pahang
Posts: 58
Rep Power: 80
Gemp-X is on a distinguished road
Send a message via Yahoo to Gemp-X
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)
__________________
http://sidik.org/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 23-10-2004, 01:12 AM
Gemp-X's Avatar
Novice Webmaster
 
Join Date: Apr 2002
Location: kuantan, pahang
Posts: 58
Rep Power: 80
Gemp-X is on a distinguished road
Send a message via Yahoo to Gemp-X
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;

__________________
http://sidik.org/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 26-10-2004, 09:59 AM
Khairul_Izwan's Avatar
Novice Webmaster
 
Join Date: Nov 2003
Location: Kuala Lumpur
Posts: 28
Rep Power: 0
Khairul_Izwan is on a distinguished road
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>
........
__________________
" I love you as much as i know how "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 27-10-2004, 02:30 AM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 116
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
PHP code can be any where in the page. But a good programming practise is put all php code above HTML code.
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How come he doesn't have to work??? RB388 Member Introductions 14 10-01-2007 11:53 PM
check my work punithan Websites Review and Suggestion 6 29-06-2005 07:20 PM
Don't want to pay to work at home? gold2006 Job Vacancies 1 08-04-2005 03:03 PM
Will this tips work? List Mamak Stall 6 18-10-2004 02:09 AM
How this work ??? koisempoi Website Programming 4 04-06-2004 04:31 PM



All times are GMT +8. The time now is 01:24 AM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

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