Visualizzazione dei risultati da 1 a 5 su 5

Discussione: PHP e MYSQL

Visualizzazione discussione

  1. #1
    Utente di HTML.it L'avatar di Valeria89
    Registrato dal
    Apr 2015
    residenza
    Pisa
    Messaggi
    129

    PHP e MYSQL

    Codice PHP:
     <?php
    require 'connessione.php';
    $db_selection mysql_select_db('db',$cn);


    if(
    $_POST && isset($_GET['ID']))
    {
        
    aggiorna_record();
    }
    elseif(isset(
    $_GET['ID']))
    {
        
    mostra_record();
    }
    else
        
    mostra_lista();


    function 
    mostra_lista()
    {
        if(isset(
    $_GET['msg']))
            echo 
    '<b>'.htmlentities($_GET['msg']).'</b><br /><br />';


        
    $query "SELECT ID FROM tabella";


        
    $result mysql_query($query);


        if (!
    $result) {
            die(
    "Errore nella query $query: " mysql_error());
        }


        echo 
    '
        <table border="1">
            <tr>
                <th>ID</th>
                <th>&nbsp;</th>
            </tr>'
    ;


        while (
    $row mysql_fetch_assoc($result))
        {
            
    $ID htmlspecialchars($row['ID']);


            
            
    $link $_SERVER['PHP_SELF'] . '?ID=' $row['ID'];
    echo 
    "<tr>
                    <td>
    $ID</td>
                    <td><a href=\"
    $link\">VIEW</a></td>
                </tr>"
    ;
        
            
        }
    echo 
    "</table>";


        
    mysql_free_result($result);


        
    mysql_close();
    }


    function 
    aggiorna_record()
    {        
        
    //funziona
    }


    function 
    mostra_record()
    {
        if(isset(
    $_GET['msg']))
            echo 
    '<b>'.htmlentities($_GET['msg']).'</b><br /><br />';


        
    $ID intval($_GET['ID']);


        
    $query "SELECT tabella1.cyl, 
                        tabella2.operating_pressure
                        
                FROM     tabella1, 
                        tabella2,
                        tabella,
                        tabella3
           
                WHERE    tabella.ID = 
    $ID AND  
                         tabella.FkEngine=tabella3.ID2 AND
                         tabella3.Fkcyl=tabella1.id AND
                         tabella3.Fkoperating_pressure=tabella2.id"
    ;


        
    $result mysql_query($query);


        if (!
    $result) {
            die(
    "Errore nella query $query: " mysql_error());
        }


        if(
    mysql_num_rows($result) != 1) {
            die(
    "l'ID passato via GET è errato");
        }


        list(
    $cyl,
            
    $operating_pressure) = mysql_fetch_row($result);


            
    $cylhtmlspecialchars($cyl);
            
    $operating_pressurehtmlspecialchars($operating_pressure);
            
        
    mysql_close();
        
    ?>
        <form name="form_registrazione" method="post" action="">
          <table width=”200″ border=”0″>
          <tr>
            <td>FkCyl:</td>
            <td><?php 
        
    include ("config.php"); 
        
        
    $DBName="db";


        
    mysql_select_db("$DBName") or die("Impossibile connettersi al database $DBName");


        
    //table tabella1
        
    $sql ="SELECT id FROM tabella2 where cyl='$cyl'";
        
    $rmysql_query($sql);
        
    $vmysql_fetch_array($r);
        echo 
    "<div id=styled-select> <select name='cyl'>"
        echo 
    "<option value = ".$v['id']." >$cyl</option>";
        
        
    $sqlquery ="SELECT id,cyl FROM tabella1";
        
    $result mysql_query($sqlquery);
        
        if (!
    $sqlquery) {
               exit (
    '<p> Errore mentre recuperavo i dati' mysql_error() . '</p>');
                    }
                    
         while (
    $valuemysql_fetch_array($result))  
       {
         echo 
    "<option value = ".$value['id'].">".$value['cyl']."</option>"
       }echo 
    "</select> </div>";
            
            
    ?> </td>
          </tr>
          
         </td>
            <td>Operating pressure: </td>
            <td><?php 
        $sql 
    ="SELECT id FROM tabella2 where operating_pressure='$operating_pressure'";
        
    $rmysql_query($sql);
        
    $vmysql_fetch_array($r);
        echo 
    "<div id=styled-select><select name='operating_pressure'>"
        echo 
    "<option value = ".$v['id']." >$operating_pressure</option>";
        
        
    $sqlquery ="SELECT id,operating_pressure FROM tabella2";
        
    $result mysql_query($sqlquery);
        if (!
    $sqlquery) {
               exit (
    '<p> Errore mentre recuperavo i dati' mysql_error() . '</p>');
                    }
         while (
    $valuemysql_fetch_array($result))  
       {
         echo 
    "<option value = ".$value['id'].">".$value['operating_pressure']."</option>";
       }echo 
    "</select> </div>";
            
    ?></td>  
          </tr>
     
         </table>
         <br> <br> 
          <p>
            <input name="invia" type="submit" value="Save" />
          </p>
        </form>


    <?php
    }
    mysql_close();
    ?>
    Non mi funziona questa parte:
    Codice PHP:
    //table tabella1
        $sql ="SELECT id FROM tabella2 where cyl='$cyl'";
        $r= mysql_query($sql);
        $v= mysql_fetch_array($r);
        echo "<div id=styled-select> <select name='cyl'>"; 
        echo "<option value = ".$v['id']." >$cyl</option>";
        
        $sqlquery ="SELECT id,cyl FROM tabella1";
        $result = mysql_query($sqlquery);
        
        if (!$sqlquery) {
               exit ('<p> Errore mentre recuperavo i dati' . mysql_error() . '</p>');
                    }
                    
         while ($value= mysql_fetch_array($result))  
       {
         echo "<option value = ".$value['id'].">".$value['cyl']."</option>"; 
       }echo "</select> </div>";
            
            ?> </td>
          </tr>
          
         </td>
            <td>Operating pressure: </td>
            <td><?php 
        $sql 
    ="SELECT id FROM tabella2 where operating_pressure='$operating_pressure'";
        
    $rmysql_query($sql);
        
    $vmysql_fetch_array($r);
        echo 
    "<div id=styled-select><select name='operating_pressure'>"
        echo 
    "<option value = ".$v['id']." >$operating_pressure</option>";
        
        
    $sqlquery ="SELECT id,operating_pressure FROM tabella2";
        
    $result mysql_query($sqlquery);
        if (!
    $sqlquery) {
               exit (
    '<p> Errore mentre recuperavo i dati' mysql_error() . '</p>');
                    }
         while (
    $valuemysql_fetch_array($result))  
       {
         echo 
    "<option value = ".$value['id'].">".$value['operating_pressure']."</option>";
       }echo 
    "</select> </div>";
            
    ?></td>  
          </tr>

    in particolare queste due query:

    $sql ="SELECT id FROM tabella2 where cyl='$cyl'";
    $sql ="SELECT id FROM tabella2 where operating_pressure='$operating_pressure'";

    non mi trova i valori di $cyl e $operating_pressure. Ho provato a stampare i valori di queste variabili e sono giusti. Quando faccio questo confronto cyl='$cyl'" non trova il record, la stessa cosa succede per operating_pressure='$operating_pressure'.

    Grazie mille a tutti



    Ultima modifica di Valeria89; 13-05-2015 a 16:30

Tag per questa discussione

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.