php selides

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
cor_mar
Δημοσιεύσεις: 24
Εγγραφή: 08 Οκτ 2005 13:10

php selides

Δημοσίευση από cor_mar » 12 Δεκ 2005 18:46

ftiaxnv php selides giati thelv na tis syndesv me Mysql database
De gnvrizv php code opote hprvth selida pou eftiaja tha hthela na odhghsei to xrhsth se mia all php selida kai parallhla na stalei mail sto logariasmo pou exei grapsei sth form
Sas stelnv ton kvdika

Κώδικας: Επιλογή όλων

"<?php require_once&#40;'Connections/room.php'&#41;; ?>
<?php
function GetSQLValueString&#40;$theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""&#41; 
&#123;
  $theValue = &#40;!get_magic_quotes_gpc&#40;&#41;&#41; ? addslashes&#40;$theValue&#41; &#58; $theValue;

  switch &#40;$theType&#41; &#123;
    case "text"&#58;
      $theValue = &#40;$theValue != ""&#41; ? "'" . $theValue . "'" &#58; "NULL";
      break;    
    case "long"&#58;
    case "int"&#58;
      $theValue = &#40;$theValue != ""&#41; ? intval&#40;$theValue&#41; &#58; "NULL";
      break;
    case "double"&#58;
      $theValue = &#40;$theValue != ""&#41; ? "'" . doubleval&#40;$theValue&#41; . "'" &#58; "NULL";
      break;
    case "date"&#58;
      $theValue = &#40;$theValue != ""&#41; ? "'" . $theValue . "'" &#58; "NULL";
      break;
    case "defined"&#58;
      $theValue = &#40;$theValue != ""&#41; ? $theDefinedValue &#58; $theNotDefinedValue;
      break;
  &#125;
  return $theValue;
&#125;

$editFormAction = $_SERVER&#91;'PHP_SELF'&#93;;
if &#40;isset&#40;$_SERVER&#91;'QUERY_STRING'&#93;&#41;&#41; &#123;
  $editFormAction .= "?" . htmlentities&#40;$_SERVER&#91;'QUERY_STRING'&#93;&#41;;
&#125;

if &#40;&#40;isset&#40;$_POST&#91;"MM_insert"&#93;&#41;&#41; && &#40;$_POST&#91;"MM_insert"&#93; == "userform"&#41;&#41; &#123;
  $insertSQL = sprintf&#40;"INSERT INTO clients &#40;firstName, lastName, address1, address2, town, province, postCode, email&#41; VALUES &#40;%s, %s, %s, %s, %s, %s, %s, %s&#41;",
                       GetSQLValueString&#40;$_POST&#91;'firstName'&#93;, "text"&#41;,
                       GetSQLValueString&#40;$_POST&#91;'lastName'&#93;, "text"&#41;,
                       GetSQLValueString&#40;$_POST&#91;'address1'&#93;, "text"&#41;,
                       GetSQLValueString&#40;$_POST&#91;'address2'&#93;, "text"&#41;,
                       GetSQLValueString&#40;$_POST&#91;'town'&#93;, "text"&#41;,
                       GetSQLValueString&#40;$_POST&#91;'province'&#93;, "text"&#41;,
                       GetSQLValueString&#40;$_POST&#91;'postcode'&#93;, "text"&#41;,
                       GetSQLValueString&#40;$_POST&#91;'email'&#93;, "text"&#41;&#41;;

  mysql_select_db&#40;$database_room, $room&#41;;
  $Result1 = mysql_query&#40;$insertSQL, $room&#41; or die&#40;mysql_error&#40;&#41;&#41;;

  $insertGoTo = "booking_details.php?url=booking_details.php&email=" . $HTTP_POST_VARS &#91;'email'&#93; . "";
  if &#40;isset&#40;$_SERVER&#91;'QUERY_STRING'&#93;&#41;&#41; &#123;
    $insertGoTo .= &#40;strpos&#40;$insertGoTo, '?'&#41;&#41; ? "&" &#58; "?";
    $insertGoTo .= $_SERVER&#91;'QUERY_STRING'&#93;;
  &#125;
  header&#40;sprintf&#40;"Location&#58; booking_details.php", $insertGoTo&#41;&#41;;
&#125;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http&#58;//www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.style3 &#123;font-family&#58; "Times New Roman", Times, serif; font-weight&#58; bold; &#125;
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_displayStatusMsg&#40;msgStr&#41; &#123; //v1.0
  status=msgStr;
  document.MM_returnValue = true;
&#125;

function MM_findObj&#40;n, d&#41; &#123; //v4.01
  var p,i,x;  if&#40;!d&#41; d=document; if&#40;&#40;p=n.indexOf&#40;"?"&#41;&#41;>0&&parent.frames.length&#41; &#123;
    d=parent.frames&#91;n.substring&#40;p+1&#41;&#93;.document; n=n.substring&#40;0,p&#41;;&#125;
  if&#40;!&#40;x=d&#91;n&#93;&#41;&&d.all&#41; x=d.all&#91;n&#93;; for &#40;i=0;!x&&i<d.forms.length;i++&#41; x=d.forms&#91;i&#93;&#91;n&#93;;
  for&#40;i=0;!x&&d.layers&&i<d.layers.length;i++&#41; x=MM_findObj&#40;n,d.layers&#91;i&#93;.document&#41;;
  if&#40;!x && d.getElementById&#41; x=d.getElementById&#40;n&#41;; return x;
&#125;

function MM_validateForm&#40;&#41; &#123; //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for &#40;i=0; i<&#40;args.length-2&#41;; i+=3&#41; &#123; test=args&#91;i+2&#93;; val=MM_findObj&#40;args&#91;i&#93;&#41;;
    if &#40;val&#41; &#123; nm=val.name; if &#40;&#40;val=val.value&#41;!=""&#41; &#123;
      if &#40;test.indexOf&#40;'isEmail'&#41;!=-1&#41; &#123; p=val.indexOf&#40;'@'&#41;;
        if &#40;p<1 || p==&#40;val.length-1&#41;&#41; errors+='- '+nm+' must contain an e-mail address.\n';
      &#125; else if &#40;test!='R'&#41; &#123; num = parseFloat&#40;val&#41;;
        if &#40;isNaN&#40;val&#41;&#41; errors+='- '+nm+' must contain a number.\n';
        if &#40;test.indexOf&#40;'inRange'&#41; != -1&#41; &#123; p=test.indexOf&#40;'&#58;'&#41;;
          min=test.substring&#40;8,p&#41;; max=test.substring&#40;p+1&#41;;
          if &#40;num<min || max<num&#41; errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    &#125; &#125; &#125; else if &#40;test.charAt&#40;0&#41; == 'R'&#41; errors += '- '+nm+' is required.\n'; &#125;
  &#125; if &#40;errors&#41; alert&#40;'The following error&#40;s&#41; occurred&#58;\n'+errors&#41;;
  document.MM_returnValue = &#40;errors == ''&#41;;
&#125;
//-->
</script>
</head>

<body>
<p>&nbsp;</p>
<form action="<?php echo $editFormAction; ?>" method="POST" name="userform" id="userform">
  <table width="200" border="0">
    <tr>
      <th scope="col"><div align="left"><span class="style3">Title</span></div></th>
      <th scope="col"><select name="select">
        <option value="Mr">Mr</option>
        <option value="Mrs">Mrs</option>
        <option value="Ms">Ms</option>
        <option value="Dr">Dr</option>
      </select></th>
      <th scope="col">&nbsp;</th>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">First Name </span></div></td>
      <td><input name="firstName" type="text" id="firstName" onFocus="MM_displayStatusMsg&#40;'Please enter your First Name'&#41;;return document.MM_returnValue" size="30"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">Surname</span></div></td>
      <td><input name="lastName" type="text" id="lastName" size="30"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">Address 1 </span></div></td>
      <td><input name="address1" type="text" id="address1" size="100"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">Address 2 </span></div></td>
      <td><input name="address2" type="text" id="address2" size="100"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">Town</span></div></td>
      <td><input name="town" type="text" id="town" size="100"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">State</span></div></td>
      <td><select name="select">
        <option value="England">England</option>
        <option value="Spain">Spain</option>
        <option value="Italy">Italy</option>
        <option value="France">France</option>
        <option value="United States">United States</option>
      </select></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">Country</span></div></td>
      <td><input name="province" type="text" id="province" size="100"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">Postcode</span></div></td>
      <td><input name="postcode" type="text" id="postcode" size="20"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">Telephone</span></div></td>
      <td><input name="telephone" type="text" id="telephone" size="20"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"><span class="style3">email</span></div></td>
      <td><input name="email" type="text" id="email" size="100"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="left"></div></td>
      <td><input name="Submit" type="submit" onFocus="MM_validateForm&#40;'firstName','','R','lastName','','R','address1','','R','town','','R','province','','R','postcode','','R','email','','RisEmail'&#41;;return document.MM_returnValue" value="Add my Details"></td>
      <td>&nbsp;</td>
    </tr>
  </table>
  
    <input type="hidden" name="MM_insert" value="userform">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
"
Mporeite na me bohthisete?

Άβαταρ μέλους
billt
Δημοσιεύσεις: 1175
Εγγραφή: 20 Φεβ 2004 16:17
Τοποθεσία: Θεσσαλονίκη

php selides

Δημοσίευση από billt » 12 Δεκ 2005 19:02

Γειά σου,
καλό είναι να βάζεις τον κώδικα σε code tags στο forum γιατί γέρος άνθρωπος που είμαι μου βγήκαν τα μάτια :)

Λοιπόν πάμε παρακάτω :
1ον Φτιάξε μια σελίδα που έχει μόνο τη φόρμα με τα στοιχεία που θέλεις να συλλέξεις και action μια σελίδα πχ data.php

2ον Η data.php θα έχει :
α. σύνδεση με τη βάση
β. εισαγωγή δεδομένων INSERT INTO ...... κτλ
γ. με χρήση της εντολής mail() θα σου στέλνει το μήνυμα

Σπάσε τις διαδικασίας όπως τα περιγράφω παραπάνω γιατί ο κώδικάς σου τώρα είναι μπάχαλο.

Άβαταρ μέλους
Basilakis
PHP Moderator
Δημοσιεύσεις: 8574
Εγγραφή: 17 Νοέμ 2003 13:03
Τοποθεσία: Womans' Brain
Επικοινωνία:

php selides

Δημοσίευση από Basilakis » 12 Δεκ 2005 19:59

Tha elega to eidio gia to code tag. Kai se parakalw na mas eksigeis kalytera... Moy bghke h pisth! Alla me kalypse o billt! Panw pou exeis to "<?php require_once('Connections/room.php'); ?>
balto mesa ston kwdika ton ypoloipo.Den xreiazete na anoigoklineis perita tags!

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες