CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2135|Reply: 8

PHP FORM (soalan beginner)

[Copy link]
Post time 22-11-2006 08:12 PM | Show all posts |Read mode
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


  1. <table>
  2. <tr>
  3. <td>
  4. Marital status:
  5. </td>
  6. <td>
  7. <input name="radio" type="radio" value="Married" /> Married<br />
  8. <input name="radio" type="radio" value="Single" /> Single
  9. </td>
  10. <tr>

  11. <tr>
  12. <td>
  13. Gender
  14. </td>
  15. <td>
  16. <input name="radio2" type="radio" value="Female" /> Female<br />
  17. <input name="radio2" type="radio" value="Male" /> Male
  18. </td>
  19. </tr>
  20. </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?


  1. <?php
  2. if(isset($_POST['submit'])) {


  3. $to = "[email protected]";
  4. $option  =  $_POST['radio'];
  5. $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
Reply

Use magic Report


ADVERTISEMENT


Post time 23-11-2006 12:11 PM | Show all posts
tu $option tu leh ke pakai yg sama? :hmm:

Rate

1

View Rating Log

Reply

Use magic Report

 Author| Post time 23-11-2006 08:24 PM | Show all posts
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..
Reply

Use magic Report

Post time 23-11-2006 08:54 PM | Show all posts
Pembetulan sikit...


  1. <?php
  2. if(isset($_POST['submit'])) {


  3. $to = "[email protected]";
  4. $option  =  $_POST['radio'];
  5. $option2  =  $_POST['radio2'];

  6. echo ("Option pertama: " . $option . "<br>");
  7. echo ("Option kedua: " . $option2 . "<br>");
  8. }

  9. ?>
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.
Reply

Use magic Report

 Author| Post time 23-11-2006 10:21 PM | Show all posts
thank you very much shanazz, its working now :bgrin:
Reply

Use magic Report

Post time 9-12-2006 09:46 PM | Show all posts
:clap:

wah... artgeex mmg hebat... hehe

err.. yg lenlain pun hebat gak.. :bgrin:
Reply

Use magic Report

Follow Us
Post time 10-8-2007 11:21 PM | Show all posts

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]
Reply

Use magic Report

Post time 11-8-2007 04:52 PM | Show all posts
<?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]
Reply

Use magic Report


ADVERTISEMENT


Post time 16-8-2007 09:30 AM | Show all posts
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;
}
     
?>
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

3-1-2025 01:12 AM GMT+8 , Processed in 0.378689 second(s), 20 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list