Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/ii8dxkor/archive.iinkor.com/includes/libs/functions.class.php on line 407

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/ii8dxkor/archive.iinkor.com/includes/libs/functions.class.php on line 407

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/ii8dxkor/archive.iinkor.com/includes/libs/functions.class.php on line 407

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/ii8dxkor/archive.iinkor.com/includes/libs/functions.class.php on line 407

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/ii8dxkor/archive.iinkor.com/includes/libs/functions.class.php on line 407

Warning: Creating default object from empty value in /home/ii8dxkor/archive.iinkor.com/common.php on line 192

Warning: Cannot modify header information - headers already sent by (output started at /home/ii8dxkor/archive.iinkor.com/includes/config.php:53) in /home/ii8dxkor/archive.iinkor.com/modules/download.module.php on line 95

Warning: Cannot modify header information - headers already sent by (output started at /home/ii8dxkor/archive.iinkor.com/includes/config.php:53) in /home/ii8dxkor/archive.iinkor.com/modules/download.module.php on line 96
أرشيف انكور : التعامل مع قواعد بيانات MySQL بإستخدام php : إدخال البيانات فى قاعدة MySQLأرشيف انكور
موضوع بعنوان :التعامل مع قواعد بيانات MySQL بإستخدام php : إدخال البيانات فى قاعدة MySQL
الكاتب :Admin


بسم الله الرحمن الرحيم

التعامل مع قواعد بيانات MySQL بإستخدام php : إدخال البيانات فى قاعدة MySQL
يمكن إدخال البيانات في جداول #MySQL عن طريق تنفيذ عبارة SQL من خلال الوظيفة mysql_query التى تحدثنا عنها فى مقالات سابقة. أدناه مثال بسيط لإدراج بيانات في جدول الموظفين .
<?php
   $dbhost = 'localhost:3036';
   $dbuser = 'root';
   $dbpass = 'rootpassword';
   $conn = mysql_connect($dbhost, $dbuser, $dbpass);
   
   if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }
   
   $sql = 'INSERT INTO employee '.
      '(emp_name,emp_address, emp_salary, join_date) '.
      'VALUES ( "guest", "XYZ", 2000, NOW() )';
      
   mysql_select_db('test_db');
   $retval = mysql_query( $sql, $conn );
   
   if(! $retval ) {
      die('Could not enter data: ' . mysql_error());
   }
   
   echo "Entered data successfullyn";
   
   mysql_close($conn);
?>


المثال اعلاه قمنا باضافة البيانات الى جدول الموظفين مباشرة لكن فى التطبيقات ، سيتم أخذ جميع القيم باستخدام نموذج HTML ثم سيتم التقاط تلك القيم باستخدام سكريبت PHP وأخيراً سيتم إدراجها في جداول #MySQL .

مثال توضيحي :
هذا المثال يأخذ المدخلات باستخدام نموذج HTML ثم يقوم بإنشاء سجلات في قاعدة البيانات.
<html>
   
   <head>
      <title>Add New Record in MySQL Database</title>
   </head>
   
   <body>
      <?php
         if(isset($_POST['add'])) {
            $dbhost = 'localhost:3036';
            $dbuser = 'root';
            $dbpass = 'rootpassword';
            $conn = mysql_connect($dbhost, $dbuser, $dbpass);
            
            if(! $conn ) {
               die('Could not connect: ' . mysql_error());
            }
            
            if(! get_magic_quotes_gpc() ) {
               $emp_name = addslashes ($_POST['emp_name']);
               $emp_address = addslashes ($_POST['emp_address']);
            }else {
               $emp_name = $_POST['emp_name'];
               $emp_address = $_POST['emp_address'];
            }
            
            $emp_salary = $_POST['emp_salary'];
            
            $sql = "INSERT INTO employee ". "(emp_name,emp_address, emp_salary, 
               join_date) ". "VALUES('$emp_name','$emp_address',$emp_salary, NOW())";
               
            mysql_select_db('test_db');
            $retval = mysql_query( $sql, $conn );
            
            if(! $retval ) {
               die('Could not enter data: ' . mysql_error());
            }
            
            echo "Entered data successfullyn";
            
            mysql_close($conn);
         }else {
            ?>
            
               <form method = "post" action = "<?php $_PHP_SELF ?>">
                  <table width = "400" border = "0" cellspacing = "1" 
                     cellpadding = "2">
                  
                     <tr>
                        <td width = "100">Employee Name</td>
                        <td><input name = "emp_name" type = "text" 
                           id = "emp_name"></td>
                     </tr>
                  
                     <tr>
                        <td width = "100">Employee Address</td>
                        <td><input name = "emp_address" type = "text" 
                           id = "emp_address"></td>
                     </tr>
                  
                     <tr>
                        <td width = "100">Employee Salary</td>
                        <td><input name = "emp_salary" type = "text" 
                           id = "emp_salary"></td>
                     </tr>
                  
                     <tr>
                        <td width = "100"> </td>
                        <td> </td>
                     </tr>
                  
                     <tr>
                        <td width = "100"> </td>
                        <td>
                           <input name = "add" type = "submit" id = "add" 
                              value = "Add Employee">
                        </td>
                     </tr>
                  
                  </table>
               </form>
            
            <?php
         }
      ?>
   
   </body>
</html>


انتهى
منقول من منتدى مصر التقني
بالتوفيق للجميع
والسلام ختام