Visualizzazione dei risultati da 1 a 3 su 3

Discussione: problema update sql

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    216

    problema update sql

    Ciao, ho questo script php, il mio problema è che non riesco a far aggiornare il database con update.
    Potete aiutarmi?
    Codice PHP:
    <?php
    session_start
    ();
    ob_start();
    include (
    "../connessione.php");
    include (
    "funzioni.php");

    if (isset(
    $_SESSION['password']))
    {
    include(
    "../connessione.php");

    $userid=1;
    if (isset(
    $_GET['userid'])){
      
    $userid=$_GET['userid'];
    }
    $queryUtente=mysql_query("select * from webs_user where userID = ".$userid);
    $utente=mysql_fetch_array($queryUtente);

    <
    form name="post" action="veragestione.php?pagina=gestionenewsletter&paginanewsletter=nuovanewsletter" method="post" enctype="multipart/form-data"  onSubmit="return chkFormular()">
    <
    input type="hidden" name="userid" value="<?=$userid?>">

    <
    table align="left" width="200">
    <
    tr bgcolor="#003366">
    <
    td class="tahbol" width="120" align="center">Username</td>
    <
    td class="tahbol" width="120" align="center">Nickname</td>
    </
    tr>
    <?
    php
    $utenti
    =mysql_query("select * from webs_user order by nickname");
    $giri=0;
    while (
    $utente=mysql_fetch_array($utenti))
    {
    $giri++;

    ?>
    <tr bgcolor="#e9e7e7">
    <td class="tahnormal" width="120" align="left"><?php echo $utente['username']; ?></td>
    <input type="hidden" name="<?=$utente['username']; ?>" value="<?=$utente['username']; ?>">
    <td class="tahnormal" width="120"  align="left"><?php echo $utente['nickname']; ?></td>
    <td class="tahnormal"><input type="checkbox" value="utente<?=$utente['userID']; ?>" name="utente<?=$utente['userID']; ?>"/></td>

    </tr>
    <?php
      
      
    }
    ?>


    </table>

    <table width="600px" border="0" cellspacing="1" cellpadding="2" class="tahbol" align="right">
        <tr bgcolor="#003366"> 
          <td align="center" class="tahbolb">INVIO NUOVA NEWSLETTER</td>
        </tr>
        
        <tr> 
          <td>
          </td>
        </tr>
        
        
        <tr>
          <td>
            <hr noshade size="1" color="#666666">
          </td>
        </tr>
        
        <tr>
          <td colspan="3">
            <table width="600px" border="0" cellspacing="0" cellpadding="2"  align="center">
              <tr> 
                <td align="center">[b]Rubrica: [/b] 
                <select name="rubrica">
                <option value="logonewsletter" selected>Newsletter</option>
                <option value="logotnc">Redazione</option>
                </select>
                  [b]
                  Carica immagine
                  [/b]
                  <input type="file" name="imgnewsletter" class="formbutton">
                  <!--[b]
                    Allineamento
                  [/b]
                  <select name="alignimg">
                  <option value="left" selected>Left</option>
                  <option value="center">Center</option>
                  <option value="right">Right</option>
                  </select> 
         -->
                </td>
              </tr>
              <!--
              <tr>
                  <td align="center">[b]Dimensioni: [/b]
                  larghezza <input type="text" name="larg" size="3">
                  altezza <input type="text" name="alt" size="3">
                  </td>
              </tr>
                  -->      
              <tr>
                <td align="center">
                <hr noshade size="1" color="#666666">
                </td>
              </tr>
              
              <tr>
                <td align="left">[b]
                  Titolo: 
        [/b]
        </td>
      </tr>
        <tr>
         <td>
                  <input name="headline1" type="text" size="119" class="form_off" onFocus="this.className='form_on'" onBlur="this.className='form_off'">

                </td>
              </tr>
              <tr>
                <td align="left">[b]
                  Descrizione: 
        [/b]
        </td>
      </tr>          
              <tr> 
                <td align="center">
                <textarea name="message" rows="20" cols="90" class="form_off" onFocus="this.className='form_on'" onBlur="this.className='form_off'">inserisci testo</textarea>
                  
     
                </td>
              </tr>
                           
              <tr> 
                <td colspan="5">
                <hr noshade size="1" color="#666666">
                </td>
              </tr>
              
              <tr align="center"> 
                <td colspan="2">            
               <input type="submit" name="invia" value="Invia">
                </td>
              </tr>
            </table>
        </td>
      </tr>
    </table>
    </form>
    <?php

    if (isset($_POST['invia'])) {
        
    $rubricanewsletter=$_POST['rubrica'];
        
    $titolonewsletter=$_POST['headline1'];
     
    $newsletter=$_POST['utente'.$utente['userID']];
     
    $username=$_POST[$utente['username']];
     if(
    $_FILES['imgnewsletter']['name']!="") {
      
    $messaggio=immagine($_FILES['imgnewsletter'],140,140,366,196);
      if (
    $messaggio=="true") {
       
    $immagine=$_SESSION['nomeimmagine'];      
      }
      else 
    $immagine="";
     } 
     else 
    $immagine="";


        
    $testonewsletter=$_POST['message'];
        
    $datanewsletter=date('d-m-Y - H:i');
        
    $posizione="archivio";
     
        
    mysql_query("insert into newsletter (data,titolo,testo,immagine,logo)
        values ('
    $datanewsletter','$titolonewsletter','$testonewsletter','$immagine','$rubricanewsletter')"); 

     
    $sel = isset($newsletter) ? '1' '0';
    if(
    $sel == '1'){
            
    mysql_query("update webs_user set invio_newsletter = '1' where username = ".$username);

    ?>
      <script type="text/javaScript">
     alert("Campo modificato!")
     </script>
    <?php
    }
       }
    }
    ?>

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2000
    residenza
    Edinburgh
    Messaggi
    401
    Quando una query non funziona prova a usare:

    Codice PHP:
    echo mysql_error(); 
    Ti darà un messaggio di errore un po' più informativo di "non funziona".

    Inoltre anche stampare a video la query può essere utile per trovare errori tipo spazi mancanti etc.

    ---

    L'errore in questo caso sarà probabilmente che non esiste una colonna chiamata xxxxx (l'username).
    Questo perchè ti mancano delle virgolette o degli apici nella query attorno a $username e quindi mysql lo interpreta come un nome di colonna

    Prova:

    Codice PHP:
    mysql_query("update webs_user set invio_newsletter = '1' where username = '".$username."'"); 

  3. #3
    considera anche l'uso dello short tag tipo:

    value="<?=$userid?>">

    invece di:

    value="<?php echo $userid ?>">

    ne hai parecchi

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

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.