php libros de texto el código de prueba da un error de

  • Zealous
  • Guru
  • Guru
  • Avatar de Usuario
  • Registrado: Abr 15, 2011
  • Mensajes: 1202
  • Loc: Sydney
  • Status: Offline

Nota Abril 22nd, 2011, 12:56 am

Estoy trabajando a través de este libro php y estoy recibiendo una luz roja en dreamweaver y no puedo ver un problema en absoluto, es posible que alguien con un ojo mejor echar un vistazo a esto y decirme lo malo que es :P

Código: [ Select ]
<?php
/* Program: mysql_up.php
* Desc: Connects to MySQL Server and outputs settings.
* Testing Mysql -- page 35
*/
echo "<html>
<head> <title>test MySQL</title></head>
<body>";
$database = "database"; 
$mysql_user = "mysqluser";
$password = "mysqlpassowrd";
$host="host";
$user="mysqlaccount";
$password="mysqlpasssowrd";

$cxn = mysqli_connect($host, $user. $password);
$sql ="SHOW GLOBAL STATUS";
$result = mysql_query ($cxn,$sql);
if($result == flase)
{
      echo "<h4>error: ".mysqli_eror(cxn)."</h4>";
}
else
{
//* Table that displays
    
echo "<table border='1'>
<tr><th>variable_name</tr>";
for($i = 0; $i < mydwli_num_rows($result); $i++)
{
    echo "<tr>";
    $row_array = mysqli_fetch_row($result);
    for($j = 0;$j < mysqli_num_feilds($result);$j++)
    {
        echo "<td>".row_array[$j]."</td>\n";
    }
        
}
echo "</table>";
    }
?>
</body></html>
  1. <?php
  2. /* Program: mysql_up.php
  3. * Desc: Connects to MySQL Server and outputs settings.
  4. * Testing Mysql -- page 35
  5. */
  6. echo "<html>
  7. <head> <title>test MySQL</title></head>
  8. <body>";
  9. $database = "database"; 
  10. $mysql_user = "mysqluser";
  11. $password = "mysqlpassowrd";
  12. $host="host";
  13. $user="mysqlaccount";
  14. $password="mysqlpasssowrd";
  15. $cxn = mysqli_connect($host, $user. $password);
  16. $sql ="SHOW GLOBAL STATUS";
  17. $result = mysql_query ($cxn,$sql);
  18. if($result == flase)
  19. {
  20.       echo "<h4>error: ".mysqli_eror(cxn)."</h4>";
  21. }
  22. else
  23. {
  24. //* Table that displays
  25.     
  26. echo "<table border='1'>
  27. <tr><th>variable_name</tr>";
  28. for($i = 0; $i < mydwli_num_rows($result); $i++)
  29. {
  30.     echo "<tr>";
  31.     $row_array = mysqli_fetch_row($result);
  32.     for($j = 0;$j < mysqli_num_feilds($result);$j++)
  33.     {
  34.         echo "<td>".row_array[$j]."</td>\n";
  35.     }
  36.         
  37. }
  38. echo "</table>";
  39.     }
  40. ?>
  41. </body></html>
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Abril 22nd, 2011, 12:56 am

  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Registrado: Mar 28, 2009
  • Mensajes: 305
  • Loc: AFK
  • Status: Offline

Nota Abril 22nd, 2011, 10:43 am

Sólo tomó un vistazo rápido...

Lo primero que vi fue la falta de un </ th> etiquetas.

Se verá más, pero tratar de que en primer lugar.


EDITADO:

Las líneas 11 y 14: "contraseña" se escribe mal en cada uno.

Línea 16. Usted dispondrá de un plazo en lugar de una coma entre delimitadores.

Línea 19: FALSO está mal escrito, pero que no debe darle un mensaje de error.

Línea 21: "Error" se escribe mal.

Línea 33: "campos" se escribe "feilds" en "mysqli_num_fields". Ese podría ser el cabrón.
Custom Web Design
  • spork
  • Brewmaster
  • Silver Member
  • Avatar de Usuario
  • Registrado: Sep 22, 2003
  • Mensajes: 6134
  • Loc: Seattle, WA
  • Status: Offline

Nota Abril 22nd, 2011, 11:16 am

¿Cuáles son los errores reales que Dreamweaver te da?
The Beer Monocle. Classy.
  • Zealous
  • Guru
  • Guru
  • Avatar de Usuario
  • Registrado: Abr 15, 2011
  • Mensajes: 1202
  • Loc: Sydney
  • Status: Offline

Nota Abril 22nd, 2011, 11:34 am

la línea 36 es de color rojo en la barra lateral derecha.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de Usuario
  • Registrado: May 22, 2004
  • Mensajes: 3415
  • Loc: Richland, WA
  • Status: Offline

Nota Abril 22nd, 2011, 2:04 pm

¿Ha intentado ejecutar el script php? Identificación ignorar una línea roja y tan sólo ejecute el código para ver lo que le da errores de PHP.
#define NULL (::rand() % 2)
  • Zealous
  • Guru
  • Guru
  • Avatar de Usuario
  • Registrado: Abr 15, 2011
  • Mensajes: 1202
  • Loc: Sydney
  • Status: Offline

Nota Abril 22nd, 2011, 2:36 pm

Creo que tienen demasiada fe en Dreamweaver. Voy a subirlo al servidor y configurar mysql y ver lo que dice
  • demonmaestro
  • Gold Member
  • Gold Member
  • Avatar de Usuario
  • Registrado: Jun 21, 2006
  • Mensajes: 487
  • Loc: Conroe, Texas
  • Status: Offline

Nota Mayo 4th, 2011, 7:32 pm

así que veo un par de problemas...

PHP Código: [ Select ]
<?php
/* Program: mysql_up.php
* Desc: Connects to MySQL Server and outputs settings.
* Testing Mysql -- page 35
*/
echo "<html>"
."<head> <title>test MySQL</title></head> "
."<body>";
$database = "database";  
$mysql_user = "mysqluser";
$password = "mysqlpassowrd";
$host="host";
$user="mysqlaccount";
$password="mysqlpassword";
 
$cxn = mysql_connect($host, $user. $password);
$sql ="SHOW GLOBAL STATUS";
$result = mysql_query ($cxn,$sql);
if($result == flase)
{
      echo "<h4>error: ".mysql_error(cxn)."</h4>";
}
else
{
//* Table that displays
     
echo "<table border='1'>
<tr><th>variable_name</th></tr>";
for($i = 0; $i < mydwli_num_rows($result); $i++)
{
    echo "<tr>";
    $row_array = mysqli_fetch_row($result);
    for($j = 0;$j < mysqli_num_feilds($result);$j++)
    {
        echo "<td>".row_array[$j]."</td></tr>\n";
    }
         
}
echo "</table>";
    }
?>
</body></html>
 
  1. <?php
  2. /* Program: mysql_up.php
  3. * Desc: Connects to MySQL Server and outputs settings.
  4. * Testing Mysql -- page 35
  5. */
  6. echo "<html>"
  7. ."<head> <title>test MySQL</title></head> "
  8. ."<body>";
  9. $database = "database";  
  10. $mysql_user = "mysqluser";
  11. $password = "mysqlpassowrd";
  12. $host="host";
  13. $user="mysqlaccount";
  14. $password="mysqlpassword";
  15.  
  16. $cxn = mysql_connect($host, $user. $password);
  17. $sql ="SHOW GLOBAL STATUS";
  18. $result = mysql_query ($cxn,$sql);
  19. if($result == flase)
  20. {
  21.       echo "<h4>error: ".mysql_error(cxn)."</h4>";
  22. }
  23. else
  24. {
  25. //* Table that displays
  26.      
  27. echo "<table border='1'>
  28. <tr><th>variable_name</th></tr>";
  29. for($i = 0; $i < mydwli_num_rows($result); $i++)
  30. {
  31.     echo "<tr>";
  32.     $row_array = mysqli_fetch_row($result);
  33.     for($j = 0;$j < mysqli_num_feilds($result);$j++)
  34.     {
  35.         echo "<td>".row_array[$j]."</td></tr>\n";
  36.     }
  37.          
  38. }
  39. echo "</table>";
  40.     }
  41. ?>
  42. </body></html>
  43.  


i cuestiones simples beleaved su fijo ahora .. intentarlo.
Thanks, Josh --DemonMaestro
www.LilNetwork.com
Fun Website www.ShoutsCloud.com
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8212
  • Loc: USA
  • Status: Offline

Nota Mayo 4th, 2011, 9:30 pm

PHP Código: [ Select ]
<?php
/* Program: mysql_up.php
* Desc: Connects to MySQL Server and outputs settings.
* Testing Mysql -- page 35
*/
 
// Starting page generation
echo "<html>
<head><title>test MySQL</title></head>
<body>\n";
 
// SQL Credentials
$database = "database";
$host = "host";
$user = "mysqlaccount";
$password = "mysqlpassword";
 
// Connecting to the database
$cxn = mysql_connect($host, $user, $password);
$sql = "SHOW GLOBAL STATUS";
$result = mysql_query($sql, $cxn);
 
// Checking for errors
if($result == false)
{
    echo "<h4>error: " . mysql_error($cxn) . "</h4>";
}
else
{
   
    //* Displaying the table
    echo "<table border='1'>
   <tr><th>variable_name</th></tr>\n";
    for($i = 0; $i < mysql_num_rows($result); $i++)
    {
        echo "<tr>\n";
        $row_array = mysql_fetch_row($result);
        for($j = 0; $j < mysql_num_fields($result); $j++)
        {
            echo "<td>{$row_array[$j]}</td>\n";
        }
        echo "</tr>\n";
    }
    echo "</table>";
}
?>
</body></html>
  1. <?php
  2. /* Program: mysql_up.php
  3. * Desc: Connects to MySQL Server and outputs settings.
  4. * Testing Mysql -- page 35
  5. */
  6.  
  7. // Starting page generation
  8. echo "<html>
  9. <head><title>test MySQL</title></head>
  10. <body>\n";
  11.  
  12. // SQL Credentials
  13. $database = "database";
  14. $host = "host";
  15. $user = "mysqlaccount";
  16. $password = "mysqlpassword";
  17.  
  18. // Connecting to the database
  19. $cxn = mysql_connect($host, $user, $password);
  20. $sql = "SHOW GLOBAL STATUS";
  21. $result = mysql_query($sql, $cxn);
  22.  
  23. // Checking for errors
  24. if($result == false)
  25. {
  26.     echo "<h4>error: " . mysql_error($cxn) . "</h4>";
  27. }
  28. else
  29. {
  30.    
  31.     //* Displaying the table
  32.     echo "<table border='1'>
  33.    <tr><th>variable_name</th></tr>\n";
  34.     for($i = 0; $i < mysql_num_rows($result); $i++)
  35.     {
  36.         echo "<tr>\n";
  37.         $row_array = mysql_fetch_row($result);
  38.         for($j = 0; $j < mysql_num_fields($result); $j++)
  39.         {
  40.             echo "<td>{$row_array[$j]}</td>\n";
  41.         }
  42.         echo "</tr>\n";
  43.     }
  44.     echo "</table>";
  45. }
  46. ?>
  47. </body></html>
Todo lo que se había errores de ortografía en las funciones y un booleano. A pocos indicios de falta de dólar ($) que indica una variable...un fuera de lugar </ tr>...

Incluso el formato del código para usted gif "alt = =":)" título" Smile ">

Aquí, en vez de darle el código fijo, la enfermedad se ejecuta a través del código que envió y le dirá exactamente donde salió mal
PHP Código: [ Select ]
<?php
/* Program: mysql_up.php
* Desc: Connects to MySQL Server and outputs settings.
* Testing Mysql -- page 35
*/
echo "<html>
<head> <title>test MySQL</title></head>
<body>";
$database = "database";  
$mysql_user = "mysqluser";
$password = "mysqlpassowrd";
$host="host";
$user="mysqlaccount";
$password="mysqlpasssowrd";
  1. <?php
  2. /* Program: mysql_up.php
  3. * Desc: Connects to MySQL Server and outputs settings.
  4. * Testing Mysql -- page 35
  5. */
  6. echo "<html>
  7. <head> <title>test MySQL</title></head>
  8. <body>";
  9. $database = "database";  
  10. $mysql_user = "mysqluser";
  11. $password = "mysqlpassowrd";
  12. $host="host";
  13. $user="mysqlaccount";
  14. $password="mysqlpasssowrd";

Eso no tiene nada de malo en ello...tal vez podría tener el formato un poco mejor. Lo único que veo es que tienes dos variables clave en allí ($ contraseña)

PHP Código: [ Select ]
$cxn = mysqli_connect($host, $user. $password);
$sql ="SHOW GLOBAL STATUS";
$result = mysql_query ($cxn,$sql);
  1. $cxn = mysqli_connect($host, $user. $password);
  2. $sql ="SHOW GLOBAL STATUS";
  3. $result = mysql_query ($cxn,$sql);

Usted está utilizando mysql i _connect pero mysql_query...eliminar esa "i" de mysqli_connect y usted debe ser bueno.

Otra de las cosas...poner el identificador de enlace ($ CXN) en primer lugar...contrariamente a lo que puso, el $ sql debe ser el primer argumento pasado a mysql_query (mysql ( cxn $ sql, $ ))

PHP Código: [ Select ]
if($result == flase)
{
  1. if($result == flase)
  2. {

Que se supone que es falsos ...no flase

PHP Código: [ Select ]
       echo "<h4>error: ".mysqli_eror(cxn)."</h4>";
}
  1.        echo "<h4>error: ".mysqli_eror(cxn)."</h4>";
  2. }

Aquí es un lugar donde se perdió el signo de dólar...que
PHP Código: [ Select ]
else
{
//*  Table that displays
   
echo "<table border='1'>
<tr><th>variable_name</tr>";
  1. else
  2. {
  3. //*  Table that displays
  4.    
  5. echo "<table border='1'>
  6. <tr><th>variable_name</tr>";

Le falta un </ th> justo antes de que </ tr> (Wouldnt lanzar un error de PHP...el código HTML puede tener un aspecto funky sin embargo.

PHP Código: [ Select ]
for($i = 0; $i < mydwli_num_rows($result); $i++)
{
  1. for($i = 0; $i < mydwli_num_rows($result); $i++)
  2. {

Yo nunca he oído hablar de un mydwli_num_rows función...a menos que usted declaró que la función en alguna parte, su supone que mysql_num_rows Probablemente escribiendo demasiado rápido gif "alt = =":)" título" Smile ">

PHP Código: [ Select ]
   echo "<tr>";
   $row_array = mysqli_fetch_row($result);
   for($j = 0;$j < mysqli_num_feilds($result);$j++)
   {
  1.    echo "<tr>";
  2.    $row_array = mysqli_fetch_row($result);
  3.    for($j = 0;$j < mysqli_num_feilds($result);$j++)
  4.    {

Los mysqli_ * debe ser mysql_ * (Mysql_fetch_row ($ resultado) y mysql_num_fields ($ resultado)

También mal escrito campos...que deletreó feilds. Escribiendo demasiado rápido otra vez (creo).

PHP Código: [ Select ]
      echo "<td>".row_array[$j]."</td>\n";
   }
     
}
echo "</table>";
   }
?>
</body></html>
  1.       echo "<td>".row_array[$j]."</td>\n";
  2.    }
  3.      
  4. }
  5. echo "</table>";
  6.    }
  7. ?>
  8. </body></html>

Otro caso en el que se olvidó de que signo de dólar...que row_array [$ j] deberían tener el derecho signo de dólar frente a ella. Por lo tanto, debe ser $ Row_array [$ j] ...el hecho de que la variable es una matriz no cambia nada.

Esa línea puede ser escrito un poco mejor también...mediante llaves.
PHP Código: [ Select ]
      echo "<td>{$row_array[$j]}</td>\n";

Esto ahorra un poco de espacio :)
"Bring forth therefore fruits meet for repentance:" Matthew 3:8

Publicar Información

  • Total de mensajes en este tema: 8 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 162 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC