Why does not work this code ?

Discussion in 'PHP' started by piropeator, May 6, 2010.

  1. #1
    This code was working, but now does not work, why?
    Can anybody help me?
    I using, first Xampp 1.6.8 and right now I using Xampp 1.7.3.

    index.php
    ======
    <?php
    $cn = mysql_connect("localhost","root","clave");
    mysql_select_db("reserva");
    $sql = "SELECT * FROM ciudad";
    $rsOrigen = mysql_query($sql);
    $nOrigen = mysql_num_rows($rsOrigen);
    ?>
    <form name="fvalida" method="POST" action="form_muestra.php">
      <table width="383" border="0" bgcolor="#FFFFFF">
        <tr>
          <th scope="row">&nbsp;</th>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <th scope="row"><div align="right">Nombre :</div></th>
          <td><input type="text" name="nombre"/></td>
        </tr>
        <tr>    </tr>
          <tr>
            <th scope="row"><div align="right">Seleccione : </div></th>
            <th scope="row"><div align="left">
              <select name="origen">
                <option value="0">Seleccione</option>
                <? for ($k=0;$k<$nOrigen;$k++) { 
    			$idciudad = mysql_result($rsOrigen,$k,"idciudad");
    			$ciudad = mysql_result($rsOrigen,$k,"ciudad");
    			?>
                <option value="<? echo $idciudad?>"> <? echo $ciudad ?> </option>
                <? } ?>
              </select>
            </div></th>
          </tr>
          <th colspan="2" scope="row">
    	  <input type="submit" value="Aceptar"/>  </th>
        </tr>
      </table>
    </form>
    
    PHP:
    form_muestra.php
    ============
    <head>
    <title>EJEMPLO</title>
    </head>
    <body>
    El nombre se fue : <?php echo $_POST['nombre'] ?>
    La ciudad fue    : <?php echo $_POST['origen'] ?>
    </body>
    </html>
    
    PHP:
    Data Base : Reserva
    =============
    CREATE TABLE `ciudad` (
      `idciudad` int(10) unsigned NOT NULL,
      `ciudad` varchar(50) NOT NULL default '',
      PRIMARY KEY  (`idciudad`)
    ) TYPE=MyISAM AUTO_INCREMENT=5 ;
    
    INSERT INTO `ciudad` VALUES (1, 'Lima');
    INSERT INTO `ciudad` VALUES (2, 'Trujillo');
    INSERT INTO `ciudad` VALUES (3, 'Cusco');
    INSERT INTO `ciudad` VALUES (4, 'Iquitos');
    
    PHP:
    Just in case... this code I did not write it. :rolleyes::confused:
     
    piropeator, May 6, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    It would help if you could give us an idea on what is "not working" - like the error message or line number.

    put this at the top of your script to get maximum error messages and warnings.
     error_reporting(E_ALL);
    PHP:
     
    sarahk, May 6, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Furthermore ensure short_tags (which one of your files is dependant on) are enabled (via php.ini), as the default configuration of Xampp has this disabled, alternatively replace <? manually with <?php

    Overwrite your old index.php content with the following, and let us know whether any errors occur (by quoting them exactly).

    <?php
    error_reporting(E_ALL);
    $cn = mysql_connect("localhost","root","clave") or trigger_error('Connection failed: ' . mysql_error($cn), E_USER_ERROR);
    mysql_select_db("reserva");
    $sql = "SELECT * FROM ciudad";
    $rsOrigen = mysql_query($sql) or trigger_error('Query failed: ' . mysql_error($rsOrigen), E_USER_ERROR);
    $nOrigen = mysql_num_rows($rsOrigen);
    ?>
    <form name="fvalida" method="POST" action="form_muestra.php">
      <table width="383" border="0" bgcolor="#FFFFFF">
        <tr>
          <th scope="row">&nbsp;</th>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <th scope="row"><div align="right">Nombre :</div></th>
          <td><input type="text" name="nombre"/></td>
        </tr>
        <tr>    </tr>
          <tr>
            <th scope="row"><div align="right">Seleccione : </div></th>
            <th scope="row"><div align="left">
              <select name="origen">
                <option value="0">Seleccione</option>
                <?php for ($k=0;$k<$nOrigen;$k++) { 
                $idciudad = mysql_result($rsOrigen,$k,"idciudad");
                $ciudad = mysql_result($rsOrigen,$k,"ciudad");
                ?>
                <option value="<?php echo $idciudad?>"> <?php echo $ciudad ?> </option>
                <?php } ?>
              </select>
            </div></th>
          </tr>
          <th colspan="2" scope="row">
          <input type="submit" value="Aceptar"/>  </th>
        </tr>
      </table>
    </form>
    PHP:
     
    Last edited: May 6, 2010
    danx10, May 6, 2010 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #4
    Good point. I've had hosting companies beef up their security and block features without warning. First I know is when a script won't run.
     
    sarahk, May 6, 2010 IP
  5. piropeator

    piropeator Well-Known Member

    Messages:
    194
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #5
    ok, you're right.
    First, the program does not show table "ciudad" in the dropdown.

    But now It's ok... but why??
    :confused::confused::confused:
     
    piropeator, May 6, 2010 IP