dou47732 2013-01-08 06:41
浏览 16
已采纳

三个PHP脚本合二为一,是否可能? [关闭]

Hey is it possible to make three scripts into one with the following code?

Can I just move "result" to the first script?

Here are codes:

<?php
error_reporting(E_ALL|E_NOTICE);
$nazwabazydanych = "projekt";

$pesel = mysql_real_escape_string($_POST['pesel']);
$imie = mysql_real_escape_string($_POST['imie']);  
$nazwisko = mysql_real_escape_string($_POST['nazwisko']);
$telefon = mysql_real_escape_string($_POST['telefon']);
$adres = mysql_real_escape_string($_POST['adres']);
$nr_konta = mysql_real_escape_string($_POST['nr_konta']);
$zarobek = mysql_real_escape_string($_POST['zarobek']);

if (!$pesel || !$imie || !$nazwisko || !$telefon || !$adres || !$nr_konta || !$zarobek)

 {
        print "Nie zostały wypełnione wszystkie pola";
        exit;
 }

 if (strlen($pesel) != 11 )
 {
 print "Zły numer pesel! Pesel powinien mieć 11 cyfr.";
 }

 if (strlen($telefon) != 9 )
 {
 print "Zły numer telefonu! Telefon powinien mieć 9 cyfr.";
 }

 if (strlen($nr_konta) != 20 )
 {
 print "Zły numer konta! Numer konta powinien mieć 20 cyfr.";
 }

$db = mysql_pconnect("localhost", "root", "");
if (!$db)  
        {  
        print "Nie można nawiązać połączenia z bazą danych";
        exit;
        }

mysql_select_db("$nazwabazydanych");

$result = mysql_query("CALL dodaj_osobe ('$pesel','$imie','$nazwisko','$telefon','$adres','$nr_konta','$zarobek')"); 
if (!$result) {
    print('');
}
else
{
    print('Dodano nowa osobe');
}



?>

Second code and "thrid", the third is the same with only 1 change:

<?php
error_reporting(E_ALL|E_NOTICE);
$nazwabazydanych = "projekt";

$pesel = mysql_real_escape_string($_POST['pesel']);



if (!$pesel)

 {
        print "Nie zostały wypełnione wszystkie pola";
        exit;
 }

   if (strlen($pesel) != 11 )
 {
 print "Zły numer pesel! Pesel powinien mieć 11 cyfr.";
 }

$db = mysql_pconnect("localhost", "root", "");
if (!$db)  
        {  
        print "Nie można nawiązać połączenia z bazą danych";
        exit;
        }

mysql_select_db("$nazwabazydanych");

$result = mysql_query("CALL magic_button ('$pesel',1)"); 
if (!$result) {
    print('');
}
else
{
    print('IT WORKS!');
}

?>

The change in third is :

$result = mysql_query("CALL magic_button1 ('$pesel',-11)"); 

Any suggestion, how can I make them into one?

  • 写回答

1条回答 默认 最新

  • dplo59755 2013-01-08 06:44
    关注

    You can call include one PHP file within another using include or require.

    As an example:

    // foo.php
    echo "hello";
    
    // bar.php
    echo "world!";
    
    // helloworld.php
    require('foo.php');
    require('bar.php');
    

    Output

    helloworld!
    

    Aside from that, you'll have to clean up that big, messy code dump

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号