phpÈëÃÅ½Ì³Ì ¾«¼ò°æ

5年以前  |  阅读数:556 次  |  编程语言:PHP 

ÏÂÃaeÎÒÂÌÆ»¹u´ø´o¼Ò×ß½øPHPµÄÈeÃÅÖ®Â
˵Ã÷£º
ÎÒÕaÀiÔÝʱÊÇÒÔ Apache web server ºÍ MY SQL ×÷ΪWEB
þÎñÆ÷ºÍÊý¾Ý¿a£¬ÔÚphp-4.3.3ϵĻ¾³×oµÄ³ÌÐo¡£µ±È»Òª¼oµ¥µÄ¹¹½¨ºÍÃÎʲe¿´Êý¾Ý¿a PHPMYADMIN ²»¿ÉÉÙ
ÕaÀiÐeÒª¶®µÃHTML»u´¡ÖªÊ¶£¡Ã»ÓÐHTML»u´¡ÖªÊ¶µÄ£¡¿ÉÒÔÈ¥°Ù¶È»oÕßGOOGLEËÑÏ£¡ºÜ¼oµ¥µÄ£¡ÕaÀi¾Í²»¶a˵ÁË
ºÃÁËÎÒÃÇ¿ªÊ¼°É£¡ÎÒÃǾͰÑPHPÈeÃŵ±³ÉÒ»¸oÆ»¹u°É£¡Ò»¿ÚÒ»¿ÚµÄ³ÔµoËu£¡
²»†ªaÂÁË£¡¿ªÊ¼ÁË
³ÔÆ»¹uÒ»
1¡¢Ç¶Èe½¨£º
ÀaËÆASPµÄ<%£¬PHP¿ÉÒÔÊÇ<?php»oÕßÊÇ<?£¬½aÊøuºÅÊÇ?>£¬µ±È»ÄuÒ²¿ÉÒÔ×Ô¼ºÖ¸¶¨¡£
2¡¢ÒýÓÃÎļþ£º
ÒýÓÃÎļþµÄ
½¨ÓÐÁ½ÖÖ£ºrequire ¼° include¡£
require µÄʹÓÃ
½¨Èç require("MyRequireFile.php"); ¡£Õa¸oº¯Êýͨ³£ÅÔÚ PHP ³ÌÐoµÄ×iÇ°Ãae£¬PHP ³ÌÐoÔÚÖ´ÐÐÇ°£¬¾Í»aÏȶÁÈe require ËuÖ¸¶¨ÒýÈeµÄÎļþ£¬Ê¹Ëu±a³É PHP ³ÌÐoÍøÒ³µÄÒ»²¿Ý¡£³£Óõĺ¯Êý£¬Òa¿ÉÒÔÕa¸o½¨½«ËuÒýÈeÍøÒ³ÖС£
include ʹÓÃ
½¨Èç include("MyIncludeFile.php"); ¡£Õa¸oº¯ÊýÒ»°aÊÇÅÔÚÁ÷³Ì¿ØÖƵĴ¦Ài²¿ÖÖС£PHP ³ÌÐoÍøÒ³ÔÚ¶Áµ½ include µÄÎļþʱ£¬²Å½«Ëu¶Á½øÀ´¡£ÕaÖֽʽ£¬¿ÉÒ԰ѳÌÐoÖ´ÐÐʱµÄÁ÷³Ì¼oµ¥»¯¡£
3¡¢×¢Êͽ¨£º
<?php
echo "ÕaÊǵÚÒ»ÖÖÀý×Ó¡£\n" ; // ±¾ÀýÊÇ C++ Ói¨µÄ×¢ÊÍ £¨PHPµÄ×¢Ê͸uC²i²»¶a£¡£(C)
/
±¾Àý²ÉÓöaÐеÄ
×¢Êͽʽ /
echo "ÕaÊǵڶþÖÖÀý×Ó¡£\n" ;
echo "ÕaÊǵÚÈýÖÖÀý×Ó¡£\n" ; # ±¾ÀýʹÓà UNIX Shell Ói¨×¢ÊÍ
?>
4¡¢±aÁ¿ÀaÐÍ£º
$mystring = "ÎÒÊÇ×Ö
u´®" ;
$NewLine = "»»ÐÐÁË\n" ;
$int1 = 38 ;
$float1 = 1.732 ;
$float2 = 1.4E+2 ;
$MyArray1 = array( "×Ó" , "³o" , "Òu" , "î" );
ÕaÀiÒý³oÁ½¸oÎÊÌa£¬Ê×ÏÈPHP±aÁ¿ÒÔ$¿ªÍ£¬µÚ¶þPHPÓi¾aÒÔ;½a⣬¿ÉÄÜASP³ÌÐoÔ±»a²»ÊÊÓ¦¡£ÕaÁ½¸oÒÅÂ(C)Ò²ÊdzÌÐoÉÏ´o¶a´iÎoËuÔÚ¡£
5¡¢ÔËËa
uºÅ£º
ÊýǨ×ÖÑÛÒѱ»ÆÁ±ÎËa£º
uºÅ ÒaÒa
+ ¼Ó
¨ÔËËa
- ¼o*¨ÔËËa

  • ³Ë¨ÔËËa
    / ³ý
    ¨ÔËËa
    % È¡ÓaÊý
    ++ ÀÛ¼Ó
    -- µÝ¼o

×Öu´®ÔËËa£º
ÔËËa
uºÅÖ»ÓÐÒ»¸o£¬¾ÍÊÇÓ¢ÎĵľaºÅ¡£Ëu¿ÉÒÔ½«×Öu´®Á¬½ÓÆðÀ´£¬±a³ÉºÏ²¢µÄÐÂ×Öu´®¡£ÀaËÆASPÖеÄ&
<?
$a = "PHP 4" ;
$b = "¹¦ÄÜÇ¿´o" ;
echo $a.$b;
?>
ÕaÀiÒ²Òý³oÁ½¸oÎÊÌa£¬Ê×ÏÈPHPÖÐÊa³oÓi¾aÊÇecho£¬µÚ¶þÀaËÆASPÖеÄ<%=±aÁ¿%>£¬PHPÖÐÒ²¿ÉÒÔ<?=±aÁ¿?>¡£
Âß¼­ÔËËa£º
*uºÅ ÒaÒa
< СÓÚ

´oÓÚ
<= СÓÚ»oµÈÓÚ
= ´oÓÚ»oµÈÓÚ
== µÈÓÚ
!= ²»µÈÓÚ
&& ¶øÇÒ (And)
and ¶øÇÒ (And)
»oÕß (Or)
or »oÕß (Or)
xor Òi»o (Xor)
! ²» (Not)
˵һÏÂÁ÷³Ì¿ØÖÆ¡£
ѧϰĿµÄ£ºÕÆÎÕphpµÄÁ÷³Ì¿ØÖÆ

1¡¢if..else Ñ­»*ÓÐÈýÖÖ½a¹¹

µÚÒ»ÖÖÊÇÖ»ÓÐÓõ½ if Ìo¼þ£¬µ±×÷µ¥´¿µÄÅжϡ£½aÊÍ³É "Èo¢ÉuÁËijÊÂÔoÔoÑu´¦Ài"¡£Ói¨ÈçÏ£º

if (expr) { statement }

ÆaÖÐµÄ expr ΪÅжϵÄÌo¼þ£¬Í¨³£¶¼ÊÇÓÃÂß¼­ÔËËauºÅµ±ÅжϵÄÌo¼þ¡£¶ø statement ΪuºÏÌo¼þµÄÖ´Ðв¿*Ö³ÌÐo£¬Èo³ÌÐoÖ»ÓÐÒ»ÐУ¬¿ÉÒÔÊ¡ÂÔ´oÀ¨ºÅ {}¡£

*¶Àý£º±¾ÀýÊ¡ÂÔ´oÀ¨ºÅ¡£

<?php
if ($state==1)echo "¹þ¹þ" ;
?>

ÕaÀiÌرð×¢ÒaµÄÊÇ£¬ÅжÏÊÇñÏaµÈÊÇ==¶ø²»ÊÇ=£¬ASP³ÌÐoÔ±¿ÉÄܳ£¸Õa¸o´iÎo£¬= ÊǸ³Öµ¡£

¶Àý£º±¾ÀýµÄÖ´Ðв¿ÖÓÐÈýÐУ¬²»¿ÉÊ¡ÂÔ´oÀ¨ºÅ¡£

<?php
if ($state==1) {
echo "¹þ¹þ ;
echo "
" ;
}
?>

µÚÁ½ÖÖÊdzýÁË if Ö®Ía£¬¼ÓÉÏÁË else µÄÌo¼þ£¬¿É½aÊÍ³É "Èo¢ÉuÁËijÊÂÔoÔoÑu´¦Ài£¬ñÔo¸ÃÈçºÎ½a¾o"¡£Ói*¨ÈçÏÂ

if (expr) { statement1 } else { statement2 } *¶Àý£ºÉÏÃaeµÄÀý×ÓÀ´Ð޸ijɸuÍeÕuµÄ´¦Ài¡£ÆaÖÐµÄ else ÓÉÓÚÖ»ÓÐÒ»ÐÐÖ´ÐеÄÖ¸Ái£¬Òo´Ë²»ÓüÓÉÏ´oÀ¨ºÅ¡£

<?php
if ($state==1) {
echo "¹þ¹þ" ;
echo "
";
}
else{
echo "ºÇºÇ";
echo "
";
}
?>

µÚÈýÖÖ¾ÍÊǵݹeµÄ if..else Ñ­»*£¬Í¨³£ÓÃÔÚ¶aÖÖ¾o²ßÅжÏʱ¡£Ëu½«Êý¸o if..else ÄÃÀ´ºÏ²¢ÔËÓô¦Ài¡£

Ö±½Ó¿´ÏÂÃaeµÄÀý×Ó

<?php
if ( $a > $b ) {
echo "a ±È b ´o" ;
} elseif ( $a == $b ) {
echo "a µÈÓÚ b" ;
} else {
echo "a ±È b С" ;
}
?>

ÉÏÀýÖ»Óöþ²aµÄ if..else Ñ­»£¬ÓÃÀ´±È½Ï a ºÍ b Á½¸o±aÁ¿¡£Êµ¼ÊҪʹÓÃÕaÖֵݹe if..else Ñ­»Ê±£¬ÇeСÐÄʹÓã¬ÒoΪ̫¶a²aµÄÑ­»*ÈÝÒ×ʹÉe¼ÆµÄÂß¼­³oÎÊÌa£¬»oÕßÉÙ´oÁË´oÀ¨ºÅµÈ£¬¶¼»aÔi³É³ÌÐo³oÏÖĪÃuÆaÃiµÄÎÊÌa¡£

2¡¢ for Ñ­»¾Íµ¥´¿Ö»ÓÐÒ»ÖÖ£¬Ã»Óбa»¯£¬ËuµÄÓi¨ÈçÏÂ

for (expr1; expr2; expr3) { statement }

ÆaÖÐµÄ expr1 ΪÌo¼þµÄ³oʼֵ¡£expr2 ΪÅжϵÄÌo¼þ£¬Í¨³£¶¼ÊÇÓÃÂß¼­ÔËËauºÅ (logical operators) µ±ÅжϵÄÌo¼þ¡£expr3 ΪִÐÐ statement ºoÒªÖ´ÐеIJ¿Ý£¬ÓÃÀ´¸Ä±aÌo¼þ£¬¹(C)Ï´εÄÑ­»Åжϣ¬Èç¼ÓÒ»..µÈµÈ¡£¶ø statement ΪuºÏÌo¼þµÄÖ´Ðв¿*Ö³ÌÐo£¬Èo³ÌÐoÖ»ÓÐÒ»ÐУ¬¿ÉÒÔÊ¡ÂÔ´oÀ¨ºÅ {}¡£

ÏÂÀýÊÇÓà for Ñ­»*дµÄµÄÀý×Ó¡£

<?php
for ( $i = 1 ; $i <= 10 ; $i ++) {
echo "ÕaÊǵÚ".$i."´ÎÑ­»*
" ;
}
?>

3¡¢ switch Ñ­»£¬Í¨³£´¦Ài¸´ºÏʽµÄÌo¼þÅжϣ¬Ã¿¸o×ÓÌo¼þ£¬¶¼ÊÇ case Ö¸Ái²¿Ö¡£ÔÚʵ×÷ÉÏÈoʹÓÃÐi¶aÀaËÆµÄ if Ö¸Ái£¬¿ÉÒÔ½«Ëu×ÛºÏ³É switch Ñ­»*¡£

Ói*¨ÈçÏÂ

switch (expr) { case expr1: statement1; break; case expr2: statement2; break; default: statementN; break; }

ÆaÖÐµÄ expr Ìo¼þ£¬Í¨³£Îª±aÁ¿Ãu³Æ¡£¶ø case ºoµÄ exprN£¬Í¨³£±iʾ±aÁ¿Öµ¡£Ã°ºÅºoÔoΪuºÏ¸ÃÌo¼þÒªÖ´ÐеIJ¿Ö¡£×¢ÒaÒªÓà break ÌøÀeÑ­»*¡£

<?php
switch ( date ( "D" )) {
case "Mon" :
echo "½ñÌiÐÇÆÚÒ»" ;
break;
case "Tue" :
echo "½ñÌiÐÇÆÚ¶þ" ;
break;
case "Wed" :
echo "½ñÌiÐÇÆÚÈý" ;
break;
case "Thu" :
echo "½ñÌiÐÇÆÚËÄ" ;
break;
case "Fri" :
echo "½ñÌiÐÇÆÚÎa" ;
break;
default:
echo "½ñÌi*żÙ" ;
break;
}
?>

ÕaÀiÐeҪעÒaµÄÊÇbreak;±ðÒÅÂ(C)ÁË£¬default£¬Ê¡ÂÔÊÇ¿ÉÒԵġ£

ºÜÃ÷ÏԵģ¬ÉÏÊoµÄÀý×ÓÓà if Ñ­»¾ÍºÜÂe³ÁË¡£µ±È»ÔÚÉe¼Æʱ£¬Òª½«³oÏÖ»uÂÊ×i´oµÄÌo¼þÅÔÚ×iÇ°Ãae£¬×iÉÙ³oÏÖµÄÌo¼þÅÔÚ×iºoÃae£¬¿ÉÒÔÔo¼Ó³ÌÐoµÄÖ´ÐÐЧÂÊ¡£ÉÏÀýÓÉÓÚÿÌi³oÏֵĻuÂÊÏaͬ£¬ËuÒÔ²»ÓÃ×¢ÒaÌo¼þµÄ˳Ðo¡£

ѧ»a¹¹½¨Êý¾Ý¿a

ÔÚPHPÖУ¬MY SQLµÄÃuÁiÐбa¼­¿ÉÄÜ»aÁi³oѧÕ߸е½ºÜÂe*³£¬²»Òª½o£¬ÄaÏÂÔØÒ»¸oPHPMYADMIN°²×°Ò»Ï£¬ÒÔºo½¨Á¢±a¼­Êý¾Ý¿a¿ÉÒÔ¿¿ËuÁË¡£

ÏÂÃae˵һÏÂËuµÄʹÓá£
½øÈeÁËphpmyadminºo£¬ÎÒÃÇÊ×ÏÈÐeÒª½¨Á¢Ò»¸oÊý¾Ý¿a£¬
Language (*) ÕaÀiÑ¡ÔñÖÐÎļoÌa£¬È»ºoÔÚ×o±ßµÄ ´´½¨Ò»¸oеÄÊý¾Ý¿a ÕaÀiÌiдÊý¾Ý¿aÃu×Ö£¬µa»÷´´½¨¼´¿É¡£

È»ºoÔÚ×o±ßÏÂÀ­²Ëµ¥ÖÐÑ¡ÔñÄǸoÒѾ­´´½¨µÄÊý¾Ý¿a¡£ÔÚÏÂÃaeµÄ

ÔÚÊý¾Ý¿a shop Öд´½¨Ò»¸oбi :
Ãu×Ö :
×Ö¶ÎÊý :

ÖÐÌiд±iÃu×ֺʹoÖÂÄaÈÏΪµÄ×Ö¶ÎÊý£¨²»¹»»oÕ߶aÁ˶¼²»Òª½o£¬ÒÔºo¿ÉÒÔÔÙÌi¼Ó»oÕßȱʡ£(C)£¬°´Ö´ÐС£
È»ºo¾Í¿ÉÒÔ¿ªÊ¼½¨Á¢±iÁË¡£
µÚÒ»À¸ÊÇ×ֶεÄÃu×Ö£»µÚ¶þÀ¸Ñ¡Ôñ×Ö¶ÎÀaÐÍ£º
ÎÒÃdz£ÓõÄÊÇÒÔϼ¸¸o£º
1£(C)VARCHAR£¬Îı¾ÀaÐÍ
2£(C)INT£¬ÕuÊýÀaÐÍ
3£(C)FLOAT£¬¸¡µaÊýÀaÐÍ
4£(C)DATE£¬ÈÕÆÚÐÍ
5£(C)´o¼Ò»oÐi»aÎÊ£¬×Ô¶¯Ìi¼ÓµÄIDÔÚÄÄÀi£¿Õa¸oֻҪѡÔñINTÀaÐÍ£¬ÔÚºoÃaeµÄ¶iÍaÖÐÑ¡Ôñ auto_increment ¾Í¿ÉÒÔÁË¡£

½¨Á¢Á˱iÒÔºo£¬¿ÉÒÔÔÚ×o±ß¿´µ½Äa½¨Á¢µÄ±i£¬µa»÷ÒÔºo£¬Äa¿ÉÒÔ£º
1£(C)°´ÓұߵĽa¹¹£º²e¿´Ð޸ıi½a¹¹
2£(C)°´ÓұߵÄa¯ÀÀ£º²e¿´±iÖеÄÊý¾Ý
3£(C)°´ÓұߵÄSQL£ºÔËÐÐSQLÓi¾a
4£(C)°´ÓұߵIJaÈe£º²aÈeÒ»ÐмǼ
5£(C)°´ÓұߵÄÇa¿Õ£ºÉ¾³ý±iÖÐËuÓмǼ
6£(C)°´ÓұߵÄɾ³ý£ºÉ¾³ý±i

»¹ÓÐÒ»¸oºÜÖØÒªµÄ¹¦ÄܾÍÊǵ¼ÈeºÍµ¼³o£¬µ±ÎÒÃDZ¾»u×oºÃÁ˳ÌÐoºÍÊý¾Ý¿aµÄʱºo£¬ÐeÒªÔÚþÎñÆ÷ÉÏÒ²ÓÐÒ»¸o±¾µØ¾µÏñ£¬Èç¹uÊÇASPµÄACCESS¼oµ¥ÁË£¬Ö±½ÓÉÏ´«MDBÎļþ¼´¿É£¬Èç¹uÊÇSQL SERVERÒ²¿ÉÒÔÁ¬½ÓÔ¶¶ËþÎñÆ÷½øÐе¼Èe¡£ÄÇôMY SQLÖÐÄa¿ÉÒÔµ¼³oËuÓеÄSQLÓi¾a£¬µ½ÁËÔ¶¶Ë*þÎñÆ÷µÄPHPMYADMINÉÏ£¬´´½¨Êý¾Ý¿aºo°´SQL£¬Õ³ÌuÄa¸Õ²Å¸´ÖÆÏÂÀ´µÄËuÓб¾¼¶Éu³ÉµÄSQLÓi¾a¼´¿É¡£

ѧ»aÁ¬½ÓÊý¾Ý¿a

PHP¼oÖ±¾ÍÊÇÒ»¸oº¯Êý¿a£¬a¸»µÄº¯ÊýʹPHPµÄijÐ(C)µØ½Ïaµ±¼oµ¥¡£½¨Òe´o¼ÒdownÒ»±¾PHPµÄº¯ÊýÊÖ²a£¬×ÜÓõĵ½¡£

ÎÒÕaÀi¾Í¼oµ¥ËµÒ»ÏÂÁ¬½ÓMYSQLÊý¾Ý¿a¡£

1¡¢mysql_connect

´o¿ª MySQL þÎñÆ÷Á¬½Ó¡£
Ói
¨: int mysql_connect(string [hostname] [:port], string [username], string [password]); *µ»ØÖµ: ÕuÊý

±¾º¯Êý½¨Á¢Óe MySQL þÎñÆ÷µÄÁ¬½Ó¡£ÆaÖÐËuÓеIJÎÊý¶¼¿ÉÊ¡ÂÔ¡£µ±Ê¹Óñ¾º¯ÊýÈ´²»¼ÓÈκβÎÊýʱ£¬²ÎÊý hostname µÄĬÈÏֵΪ localhost¡¢²ÎÊý username µÄĬÈÏֵΪ PHP Ö´ÐÐÐг̵ÄÓµÓÐÕß¡¢²ÎÊý password ÔoΪ¿Õ×Öu´® (¼´Ã»ÓÐÃÜÂe)¡£¶ø²ÎÊý hostname ºoÃae¿ÉÒÔ¼ÓðºÅÓe¶Ë¿ÚºÅ£¬´u±iʹÓÃÄĸo¶Ë¿ÚÓe MySQL Á¬½Ó¡£µ±È»ÔÚʹÓÃÊý¾Ý¿aʱ£¬ÔçµaʹÓà mysql_close() ½«Á¬½Ó¹Øµo¿ÉÒÔ½ÚÊ¡×ÊÔ´¡£

2¡¢ mysql_select_db

Ñ¡ÔñÒ»¸oÊý¾Ý¿a¡£
Ói¨: int mysql_select_db(string data£a£a£o£a_name, int [link_identifier]); µ»ØÖµ: ÕuÊý

±¾º¯ÊýÑ¡Ôñ MySQL þÎñÆ÷ÖеÄÊý¾Ý¿aÒÔ¹(C)Ö®ºoµÄ×ÊÁϲeѯ×÷Òµ (query) ´¦Ài¡£³É¹¦µ»Ø true£¬Ê§°ÜÔo*µ»Ø false¡£

×i¼oµ¥µÄÀý×Ó¾ÍÊÇ£º
$conn=mysql_connect ("127.0.0.1", "", "");
mysql_select_db("shop");
Á¬½Ó»uMY SQLÊý¾Ý¿a£¬´o¿ªSHOPÊý¾Ý¿a¡£ÔÚʵ¼ÊÓ¦ÓÃÖÐÓ¦µ±¼ÓÇ¿µa´iÎoÅжϡ£

ѧ»a¶ÁÈ¡Êý¾Ý

ÏÈ¿´Á½¸oº¯Êý£º
1¡¢mysql_query
ËͳoÒ»¸o query ×Öu´®¡£ Ói¨: int mysql_query(string query, int [link_identifier]); *µ»ØÖµ: ÕuÊý

±¾º¯ÊýËͳo query ×Öu´®¹(C) MySQL ×oÏa¹ØµÄ´¦Ài»oÕßÖ´ÐС£ÈoûÓÐÖ¸¶¨ link_identifier ²ÎÊý£¬Ôo³ÌÐo»a×Ô¶¯Ñ°ÕÒ×i½u´o¿ªµÄ ID¡£µ± query ²eѯ×Öu´®ÊÇ UPDATE¡¢INSERT ¼° DELETE ʱ£¬µ»ØµÄ¿ÉÄÜÊÇ true »oÕß false£»²eѯµÄ×Öu´®ÊÇ SELECT Ôoµ»ØÐ嵀 ID Öµ£¬µ±µ»Ø false ʱ£¬²¢²»ÊÇÖ´Ðгɹ¦µ«ÎÞµ»ØÖµ£¬¶øÊDzeѯµÄ×Öu´®ÓдiÎo¡£

2¡¢mysql_fetch_object µ»ØÀa×ÊÁÏ¡£ Ói¨: object mysql_fetch_object(int result, int [result_typ]); *µ»ØÖµ: Àa

±¾º¯ÊýÓÃÀ´½«²eѯ½a¹u result ²ðµ½Àa±aÁ¿ÖС£Èo result ûÓÐ×ÊÁÏ£¬Ôo*µ»Ø false Öµ¡£

¿´Ò»¸o¼oµ¥µÄÀý×Ó£º
<?
$exec="select from user";
$result=mysql_query($exec);
while($rs=mysql_fetch_object($result))
{
echo "username:".$rs->username."
";
}
?>
µ±È»£¬±iuserÖÐÓÐÒ»¸ousernameµÄ×ֶΣ¬Õa¾ÍÀaËÆaspÖеÄ
<%
exec="select
from user"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
do while not rs.eof
response.write "username:"&rs;("username")&"
"
rs.movenext
loop
%>
µ±È»ÏÈÒªÁ¬½ÓÊý¾Ý¿a£¬Ò»°aÎÒÃÇ require_once('conn.php');¶øconn.phpÀiÃae¾ÍÊÇÉÏÒ»´Î˵µÄÁ¬½ÓÊý¾Ý¿aµÄ´uÂe¡£

ССµÄÁ½ÌoÃuÁi¿ÉÒÔÍe³É¶ÁÈ¡Êý¾ÝµÄ¹¤×÷ÁË

ѧ»aÌi¼Óɾ³ýÐÞ¸ÄÊý¾Ý

mysql_query($exec);
µ¥Õa¸oÓi¾a¾Í¿ÉÒÔÖ´ÐÐËuÓеIJÙ×÷ÁË£¬²»Í¬µÄ¾ÍÊÇ$execÕa¸osqlÓi¾a

Ìi¼Ó£º$exec="insert into tablename (item1,item2) values ('".$_POST['item1']."',".$_POST['item1'].")";

ɾ³ý£º$exec="delete from tablename where...";

Ð޸ģº$exec="update tablename set item1='".$_POST['item1']."' where ...";

˵µ½ÕaÀi¾ÍҪ˵һϱiµ¥ºÍphp±aÁ¿´«µÝ£¬Èç¹u±iµ¥ÖеÄÒ»¸o
±iµ¥ÒÔPOSTÌa½»µÄ£¬ÄÇô´¦Ài±iµ¥Îļþ¾Í¿ÉÒÔÓÃ$_POST['item1']µÃµ½±aÁ¿Öµ£¬Í¬ÑuÒÔGETÌa½»µÄ¾ÍÊÇ$_GET['item1']

ÊDz»ÊǺܼoµ¥£¿µ«ÊÇͨ³£$exec»aÓÐÎÊÌa£¬ÒoΪ¿ÉÄÜÄuµÄSQLÓi¾a»aºÜ³¤£¬Äu»aÒÅÂ(C).Á¬½Óu£¬»oÕß'À´°uΧ×ÖuÐÍ×ֶΡ£
ÎÒÃÇ¿ÉÒÔ×¢ÊÍmysql_query($exec);Ói¾aÓÃecho $exec;´uÌaeÀ´Êa³o$execÒÔ¼i²eÕýÈÐÔ¡£Èç¹uÄu»¹²»Äܲi¾o$execÓÐʲô´iÎoµÄ»°£¬¿ÉÒÔ¸´ÖÆÕa¸osqlÓi¾aµ½phpmyadminÖÐÖ´ÐУ¬¿´¿´ËuµÄ³o´iÐÅÏ¢¡£»¹ÓÐÐeҪעÒaµÄÊÇ£¬ÎÒÃDz»ÒªÊ¹ÓÃÒ»Ð(C)Ão¸ÐµÄ×Öu´®×÷Ϊ×Ö¶ÎÃu×Ö£¬*ñÔoºÜ¿ÉÄÜ»a³oÏÖÎÊÌa£¬±ÈÈç˵dateʲôµÄ¡£±aÁ¿µÄÃuÃu£¬×ֶεÄÃuÃu×ñÑ­Ò»µa¹aeÂÉÓеÄʱºo¶Ô×Ô¼ºÊÇÒ»Öֺô¦£¬³oѧÕß²¢²»¿ÉºoÊÓÆaÖØÒªÐÔ¡£

ѧ»aSESSIONµÄʹÓÃ

SESSIONµÄ×÷Óúܶa£¬×i¶aÓõľÍÊÇÕ¾µaÄÚÒ³Ãae¼a±aÁ¿´«µÝ¡£

ÔÚÒ³Ãae¿ªÊ¼ÎÒÃÇÒªsession_start();¿ªÆoSESSION£»
È»ºo¾Í¿ÉÒÔʹÓÃSESSION±aÁ¿ÁË£¬±ÈÈç˵Ҫ¸³Öµ¾ÍÊÇ£º$_SESSION['item']="item1";ÒªµÃµ½Öµ¾ÍÊÇ$item1=$_SESSION['item'];£¬ºÜ¼oµ¥°É¡£ÕaÀiÎÒÃÇ¿ÉÄÜ»aʹÓõ½Ò»Ð(C)º¯Êý£¬±ÈÈç˵ÅжÏÊDz»ÊÇijSESSION±aÁ¿Îª¿Õ£¬¿ÉÒÔÕaôд£ºempty($_SESSION['inum'])*µ»Øtrue or false¡£

ÏÂÃae×ÛºÏÒ»ÏÂÇ°ÃaeËu˵µÄÎÒÃÇÀ´¿´Ò»¸oµÇ½³ÌÐo£¬ÅжÏÓû§ÃuÃÜÂeÊÇñÕýÈ¡£
µÇ½±iµ¥ÊÇÕaÑu£ºlogin.php

Administrators Login
Username
Password

´¦ÀiÎļþÊÇÕaÑu
<?
require_once('conn.php');
session_start();
$username=$_POST['username'];
$password=$_POST['password'];
$exec="select * from admin where username='".$username."'";
if($result=mysql_query($exec))
{
if($rs=mysql_fetch_object($result))
{
if($rs->password==$password)
{
$_SESSION['adminname']=$username;
header("location:index.php");
}
else
{
echo "";
}
}
else
{
echo "";
}
}
else
{
echo "";
}

?>

conn.phpÊÇÕaÑu£º
<?
$conn=mysql_connect ("127.0.0.1", "", "");
mysql_select_db("shop");
?>

ÓÉÓÚ $_SESSION['adminname']=$username;ÎÒÃÇ¿ÉÒÔÕaÑuдÑeÖ¤ÊÇ*ñµÇ½Ói¾aµÄÎļþ£ºcheckadmin.php
<?
session_start();
if($_SESSION['adminname']=='')
{
echo "";
}
?>

×oÒ»¸o*ÖÒ³ÏÔʾ

¹Ø¼u¾ÍÊÇÓõ½ÁËSQLÓi¾aÖеÄlimitÀ´ÏÞ¶¨ÏÔʾµÄ¼Ç¼´Ó¼¸µ½¼¸¡£ÎÒÃÇÐeÒªÒ»¸o¼Ç¼µ±Ç°Ò³µÄ±aÁ¿$page£¬»¹ÐeÒª×ܹ²µÄ¼Ç¼Êý$num

¶ÔÓÚ$pageÈç¹uûÓÐÎÒÃǾÍÈÃËu=0£¬Èç¹uÓÐ<0¾ÍÈÃËuÒ²=0£¬Èç¹u³¬¹ýÁË×ܵÄÒ³Êý¾ÍÈÃËu=×ܵÄÒ³Êý¡£

$execc="select count(*) from tablename ";
$resultc=mysql_query($execc);
$rsc=mysql_fetch_array($resultc);
$num=$rsc[0];

ÕaÑu¿ÉÒԵõ½¼Ç¼×ÜÊý
ceil($num/10))Èç¹uÒ»Ò³10¼Ç¼µÄ»°£¬Õa¸o¾ÍÊÇ×ܵÄÒ³Êý

ËuÒÔ¿ÉÒÔÕaôд
if(empty($_GET['page']))
{
$page=0;
}
else
{
$page=$_GET['page'];
if($page<0)$page=0;
if($page>=ceil($num/10))$page=ceil($num/10)-1;//ÒoΪpageÊÇ´Ó0¿ªÊ¼µÄ£¬ËuÒÔÒª-1
}

ÕaÑu$exec¿ÉÒÔÕaôд $exec="select from tablename limit ".($page10).",10";
//Ò»Ò³ÊÇ10¼Ç¼µÄ

×iºoÎÒÃÇÐeÒª×oµÄ¾ÍÊǼ¸¸oÁ¬½Ó£º
FirstPage
PrevPage
NextPage
LastPage

×¢ÒaÊÂÏi

1¡¢×¢Òa²»ÒªÂ(C)ÁË*ÖºÅ
2¡¢×¢Òa²»ÒªÂ(C)Á˱aÁ¿Ç°µÄ$
3¡¢Ê¹ÓÃSESSIONµÄʱºo×¢Òa²»ÒªÒÅÂ(C)session_start();

Èç¹u¢Éu´iÎoµÄʱºo£¬¿ÉÒÔ²ÉÓÃÒÔϽ¨£º
1¡¢Èç¹uÊÇSQLÓi¾a³o´i£¬¾Í×¢ÊÍÁËÈ»ºoÊa³oSQLÓi¾a£¬×¢ÒaҲҪעÊ͵÷ºoÐøµÄÖ´ÐÐSQLÓi¾a
2¡¢Èç¹uÊDZaÁ¿Îª¿Õ£¬´o¶aÊÇûÓд«µÝµ½Î»£¬Êa³o±aÁ¿¼i²eһϣ¬¼i²eһϱiµ¥µÄidºÍname
3¡¢Èç¹uÊÇÊý¾Ý¿aÁ¬½Ó³o´i£¬¼i²eÊÇ
ñÕýÈ´o¿ªMY SQLºÍÊÇñÒÅÂ(C)ÁËÁ¬½ÓÓi¾a
4¡¢×¢ÒaËo½ø£¬ÅųýÀ¨ºÅ²»ÇøÅaµÄ´iÎo

ÔÚ×o´oÍøÕ¾µÄʱºo£¬ÎÒµÄ˼ÂÊÇÏȹ¹½¨Êý¾Ý¿a£¬È¶¨Ã¿Ò»¸o×ֶεÄ×÷Ó㬺ͱiÖ®¼aµÄ¹Øϵ¡£È»ºoÉe¼Æºǫ½çÃae£¬´ÓÌi¼ÓÊý¾Ý¿ªÊ¼×oÆð£¬ÒoΪÌi¼ÓÊÇ*ñ³É¹¦¿ÉÒÔÖ±½Óµ½Êý¾Ý¿aÀiÃaeÑeÖ¤£¬×oºÃÁËÌi¼ÓÔÙ×oÏÔʾµÄÒ³Ãae£¬×iºo²ÅÊÇÁ½ÕߵĽaºÏ¡£Ò»°aÀ´Ëµºǫ¾Í°uÀ¨Ìi¼Óɾ³ýÐ޸ĺÍÏÔʾ£¬ºǫûÓÐÎÊÌaÁË£¬Ç°Ì¨Ò²Ã»ÓÐʲô´oÎÊÌa¡£Ç°Ì¨»¹ÐeҪעÒa°²È«ÐÔºÍÈÝ´i»¹ÓоÍÊÇÊa³o¸ñʽ¡£

ѧ»aÓÃPHPÉÏ´«ÎļþºÍ*¢Óʼþ

ÉÏ´«Îļþ±iµ¥±ØÐe¼ÓÉÏ enctype="multipart/form-data"
ºÍ
ÏÂÃae¿´Ò»Ï´uÂe£º

$f=&$HTTP_POST_FILES['file'];
$dest_dir='uploads';//Ée¶¨ÉÏ´«Ä¿Â¼
$dest=$destdir.'/'.date("ymd")."".$f['name'];//ÎÒÕaÀiÉeÖÃÎļþÃuΪÈÕÆÚ¼ÓÉÏÎļþÃu±ÜÃaÖظ´
$r=move_uploaded_file($f['tmp_name'],$dest);
chmod($dest, 0755);//Ée¶¨ÉÏ´«µÄÎļþµÄÊoÐÔ

ÉÏ´«µÄÎļþÃuΪdate("ymd")."_".$f['name'] £¬¿ÉÒÔÔÚÒÔºo²aÈeµ½Êý¾Ý¿aµÄʱºoÓõ½£¬PHPʵ¼ÊÉÏÊÇ°ÑÄaÉÏ´«µÄÎļþ´ÓÁÙʱĿ¼Òƶ¯µ½Ö¸¶¨Ä¿Â¼¡£move_uploaded_file($f['tmp_name'],$dest);ÕaÊǹؼu

ÖÁÓÚ*¢Óʼþ¾Í¸u¼Ó¼oµ¥£¬¿ÉÒÔʹÓÃmail()º¯Êý

mail("ÊÕ¼þÈ˵ØÖ","Ö÷Ìa","ÕýÎÄ","From:¢¼þÈË\r\nReply-to:¢¼þÈ˵ĵØÖ");

²»¹ýmail()ÐeÒªþÎñÆ÷µÄÖ§³Ö£¬ÔÚWINDOWSÏ»¹ÐeÒªÅaÖÃSMTPþÎñÆ÷£¬Ò»°aÀ´ËµÍaÃaeµÄLINUX¿Õ¼a¶¼ÐС£
ºÃÏñÉÏ´«ÎļþºÍ¢Óʼþ±ÈASP¼oµ¥ºÜ¶a£¬Ö»Òªµ÷Óú¯Êý¾Í¿ÉÒÔÁË¡£ASP»¹ÐeÒªÓõ½þÎñÆ÷µÄ²»Í¬×e¼þ±ÈÈçFSO¡¢JMAILʲôµÄ¡£

ѧ»aPHP˵µ½ÕaÀiÁË£¬Ïe¸aeËß´o¼ÒµÄÊÇPHPÈeÃÅ¿ÉÒÔÊÇÊ®Ìi£¬µ«ÊǾ«Í¨¾o²»ÊÇÊ®Ìi°¡£¬»¹ÐeÒª´o¼Ò×Ô¼ºÈ¥Ñо¿ £¬¶a²Î¿¼±ðÈ˵ĴuÂe£¬È¥Ài½a²»Êdz­Ï®¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例