Advertisement
Guest User

Untitled

a guest
May 13th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.21 KB | None | 0 0
  1. /* funclib.php */
  2.  
  3. <?php
  4. $i=1;
  5. $hostT;
  6. $userT;
  7. $passT;
  8.  
  9. function recibir($host, $user, $pass) {
  10.     $hostT=$host;
  11.     $userT=$user;
  12.     $passT=$pass;
  13. }
  14.  
  15. function conectar($host, $user, $pass) {
  16.     $conex = mysql_connect($host, $user, $pass);
  17.     /*if (mysql_select_db($db, $conex)) {
  18.         return $conex; 
  19.     } else {
  20.         print (mysql_error());
  21.     }*/
  22.     return $conex; 
  23. }
  24.  
  25. function desconectar($conex) {
  26.     mysql_close($conex);
  27. }
  28.  
  29. function insertar() {
  30.     if (!isset($accion)){
  31.         echo"
  32.         <h3>Guardar datos en la base</h3>
  33.         <form name=\"form1\" method=\"post\" action=\"insertar.php?accion=insertar\">
  34.           <table>
  35.           <tr>
  36.             <td>Juego</td><td>DVDs</td><td>Region</td><td>Wave</td><td>SSv</td><td>Stealth</td><td>Audio</td><td>Textos, Subs.</td>
  37.           </tr>
  38.           <tr>
  39.             <td><input type=\"text\" name=\"nombre\"></td><td><input type=\"text\" name=\"discos\"></td><td><input type=\"text\" name=\"reg\"></td><td><input type=\"text\" name=\"w\"></td><td><input type=\"text\" name=\"ss\"></td><td><input type=\"text\" name=\"st\"></td><td><input type=\"text\" name=\"audio\"></td><td><input type=\"text\" name=\"text\"></td>
  40.           </tr>
  41.           <tr>
  42.             <td><input type=\"submit\" name=\"Submit\" value=\"Insertar datos\"></td>
  43.           </tr>
  44.         </form>";
  45.     } elseif(isset($accion)) {
  46.         $nombre=$HTTP_POST_VARS["nombre"];
  47.         echo $nombre;
  48.         $discos=$HTTP_POST_VARS["discos"];
  49.         $reg=$HTTP_POST_VARS["reg"];
  50.         $w=$HTTP_POST_VARS["w"];
  51.         $ss=$HTTP_POST_VARS["ss"];
  52.         $st=$HTTP_POST_VARS["st"];
  53.         $audio=$HTTP_POST_VARS["audio"];
  54.         $text=$HTTP_POST_VARS["text"];
  55.        
  56.         $conex=conectar($hostT, $userT, $passT);
  57.         if (mysql_select_db("zoby_5231271_lj", $conex)) {
  58.             $result=mysql_query("INSERT INTO juegos  (Juego,DVDs,Region,Wave,SSv,Stealth,Audio,Textos Subs)
  59.                 VALUES ('',$nombre,$discos,$reg,$w,$ss,$st,$audio,$text) ",$conex);
  60.             echo"<h3>Los datos han sido guardados</h3>";
  61.         } else {
  62.             print (mysql_error());
  63.         }
  64.         desconectar($conex);       
  65.     }
  66.    
  67. }
  68.  
  69. function mostrar() {
  70.     $conex=conectar("sql104.zobyhost.com", "zoby_5231271", "m4Sj0D10");
  71.     mysql_select_db("zoby_5231271_lj", $conex);
  72.     $result=mysql_query("SELECT * FROM juegos ORDER BY Juego",$conex);
  73.     echo"<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#999999\">
  74.       <tr bgcolor=\"#FFFF66\">
  75.         <td width=\"35%\"> <div align=\"left\"><font face=\"MS Serif\">Juego</font></div></td>
  76.         <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">DVDs</font></div></td>
  77.         <td width=\"20%\"> <div align=\"center\"><font face=\"MS Serif\">Region</font></div></td>
  78.         <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">Wave</font></div></td>
  79.         <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">SSv</font></div></td>
  80.         <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">Stealth</font></div></td>
  81.         <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">Audio</font></div></td>
  82.         <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">Textos, Subs.</font></div></td>
  83.       </tr>
  84.     ";
  85.     while($row=mysql_fetch_row($result)){
  86.         if (!is_odd($i)) {
  87.             echo"<tr>
  88.             <td width=\"35%\"><div align=\"left\"><font face=\"MS Serif\">$row[0]</font></div></td>
  89.             <td width=\"5%\"><div align=\"center\"><font face=\"MS Serif\">$row[1]</font></div></td>
  90.             <td width=\"20%\"> <div align=\"center\"><font face=\"MS Serif\">$row[2]</font></div></td>
  91.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[3]</font></div></td>
  92.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[4]</font></div></td>
  93.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[5]</font></div></td>
  94.             <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">$row[6]</font></div></td>
  95.             <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">$row[7]</font></div></td>
  96.             </tr>";
  97.             $i++;
  98.         } else  if (is_odd($i)) {
  99.             echo"<tr bgcolor=\"#99CCCC\">
  100.             <td width=\"35%\"><div align=\"left\"><font face=\"MS Serif\">$row[0]</font></div></td>
  101.             <td width=\"5%\"><div align=\"center\"><font face=\"MS Serif\">$row[1]</font></div></td>
  102.             <td width=\"20%\"> <div align=\"center\"><font face=\"MS Serif\">$row[2]</font></div></td>
  103.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[3]</font></div></td>
  104.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[4]</font></div></td>
  105.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[5]</font></div></td>
  106.             <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">$row[6]</font></div></td>
  107.             <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">$row[7]</font></div></td>
  108.             </tr>";
  109.             $i++;
  110.         }
  111.        
  112.     }   /* else {
  113.                print (mysql_error());
  114.             }*/
  115.     echo"</table>";
  116.    
  117.     desconectar($conex);
  118. }
  119.  
  120. function is_odd($number) {
  121.  return $number & 1; // 0 = par, 1 = impar
  122. }
  123.  
  124.  
  125. ?>
  126.  
  127. /* fin funcion insertar() de funclib */
  128.  
  129. /* insertar.php */
  130.  
  131. <?php
  132.     include("funclib.php");
  133. ?>
  134. <html>
  135. <head>
  136.     <title>insertar lineas en la base de datos</title>
  137. </head>
  138. <body>
  139.  
  140. <?php
  141. $host=$_POST["host"];
  142. $user=$_POST["user"];
  143. $pass=$_POST["pass"];
  144. recibir($host, $user, $pass);
  145. insertar();
  146. ?>
  147. </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement