View: 2135|Reply: 8
|
PHP FORM (soalan beginner)
[Copy link]
|
|
dalam satu form, aku nak buat dua options dibawah label berasingan.. for example, aku buat satu label marital status, so optionnya married, single.. satu lagi label gender, option female, male
- <table>
- <tr>
- <td>
- Marital status:
- </td>
- <td>
- <input name="radio" type="radio" value="Married" /> Married<br />
- <input name="radio" type="radio" value="Single" /> Single
- </td>
- <tr>
- <tr>
- <td>
- Gender
- </td>
- <td>
- <input name="radio2" type="radio" value="Female" /> Female<br />
- <input name="radio2" type="radio" value="Male" /> Male
- </td>
- </tr>
- </table>
Copy the Code
then submit form ni ke succeed.php yang akan anta result ke email..
so dalam succeed.php ni pulak, aku kena buat camne eh?
- <?php
- if(isset($_POST['submit'])) {
-
- $to = "[email protected]";
- $option = $_POST['radio'];
- $option = $_POST['radio2'];
Copy the Code
aku belajar dari kirupa.com untuk 'radio' manakala additional 'radio2' aku buat try and error.. kalau satu label untuk radio button memang menjadi, tapi dua ie tambah lagi radio2, tak menjadi..
anu suggestion?
reference: http://www.kirupa.com/web/php_contact_form4.htm |
|
|
|
|
|
|
|
Originally posted by N_DIA at 23-11-2006 12:11 PM
tu $option tu leh ke pakai yg sama? :hmm:
my knowledge in this is in beginner level.. sebab tu aku tanya, aku pun tak tau.. kalau kau leh ejas, kau tukar camne? aku stuck part ni jer, lelain ok, form dah sampai kat email etc.. cuma radio button dua label ni jer ampeh sket.. |
|
|
|
|
|
|
|
Pembetulan sikit...
- <?php
- if(isset($_POST['submit'])) {
- $to = "[email protected]";
- $option = $_POST['radio'];
- $option2 = $_POST['radio2'];
- echo ("Option pertama: " . $option . "<br>");
- echo ("Option kedua: " . $option2 . "<br>");
- }
- ?>
Copy the Code
Betul kata N_DIA, kalau kekal code yang di atas, dia akan overwrite value yang pertama dengan value yang kedua.
Selamat mencuba. |
|
|
|
|
|
|
|
thank you very much shanazz, its working now :bgrin: |
|
|
|
|
|
|
|
:clap:
wah... artgeex mmg hebat... hehe
err.. yg lenlain pun hebat gak.. :bgrin: |
|
|
|
|
|
|
|
cane nak wat register form n login gune php
sy dah wat 1 register form..tp x dpt nak link laa..leh x sapa2 yg tau tu tlg check coding sy btoi ke x..
<?PHP
//Database Information
$dbhost = "localhost";
$dbname = "your database name";
$dbuser = "username";
$dbpass = "yourpass";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
// lets check to see if the username already exists
$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");
$username_exist = mysql_num_rows($checkuser);
if($username_exist > 0){
echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
unset($username);
include 'register.html';
exit();
}
// lf no errors present with the username
// use a query to insert the data into the database.
$query = "INSERT INTO users (name, email, username, password)
VALUES('$name', '$email', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();
echo "You have successfully Registered";
// mail user their information
$yoursite = 慬url]www.blahblah.com[/url] |
|
|
|
|
|
|
|
<?php
//Database Information
$dbhost = "local";
$dbname = "dbname";
$dbuser = "user";
$dbpass = "password";
//Connect to database
$dbConn = mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
//kalau user click submit button
$submit = $_REQUEST['submit'];
if (!is_null($submit))
{
$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'", $dbConn);
$username_exist = mysql_num_rows($checkuser);
if($username_exist > 0){
echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
unset($username);
include ("register.html");
exit();
}
else
{
// lf no errors present with the username
// use a query to insert the data into the database.
$query = "INSERT INTO users (name, email, username, password)
VALUES('$name', '$email', '$username', '$password')";
mysql_query($query, $dbConn) or die(mysql_error());
mysql_close();
echo "You have successfully Registered";
// mail user their information
$yoursite = 慬url]www.blahblah.com[/url] |
|
|
|
|
|
|
|
utk coding email.. aku berkongsi sikit..
<?php
function mymail($to,$subject,$message,$headers)
{
$smtp_host = "your_smtp_host";
$smtp_port = "25";
$user_auth = "youremail";
$pass_auth = "password";
$from = "youremail";
$interval=600;
// set as global variable
global $GLOBAL;
// get From address
//if ( preg_match("/From:.*?[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+.*/", $headers, $froms) ) {
// preg_match("/[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+/", $froms[0], $fromarr);
// $from = $fromarr[0];
//}
// Open an SMTP connection
$cp = fsockopen ($smtp_host, $smtp_port, &$errno, &$errstr, 1);
if (!$cp)
return "Failed to even make a connection";
$res=fgets($cp,256);
if(substr($res,0,3) != "220") return "Failed to connect";
//socket_set_timeout($smtp_host, $interval, 0);
// Say hello...
fputs($cp, "HELO ".$smtp_host."\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "250") return "Failed to Introduce";
// perform authentication
fputs($cp, "auth login\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "334") return "Failed to Initiate Authentication";
fputs($cp, base64_encode($user_auth)."\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "334") return "Failed to Provide Username for Authentication";
fputs($cp, base64_encode($pass_auth)."\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "235") return "Failed to Authenticate";
// Mail from...
fputs($cp, "MAIL FROM: <$from>\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "250") return "MAIL FROM failed";
// Rcpt to...
fputs($cp, "RCPT TO: <$to>\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "250") return "RCPT TO failed";
// Data...
fputs($cp, "DATA\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "354") return "DATA failed";
// Send To:, From:, Subject:, other headers, blank line, message, and finish
// with a period on its own line (for end of message)
fputs($cp, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "250") return "Message Body Failed";
// ...And time to quit...
fputs($cp,"QUIT\r\n");
$res=fgets($cp,256);
if(substr($res,0,3) != "221") return "QUIT failed";
return true;
}
?> |
|
|
|
|
|
|
| |
|