mysql_fetch_assoc

chika chan

Nuovo Utente
28 Dic 2007
20
0
0
PHP:
<?php
if($_SESSION["uid"]) {
   $sql = "SELECT username FROM users WHERE in = '".$_SESSION['uid']."'";
   $sql = mysql_query ($sql) or die (mysql_error());

   if(mysql_num_rows($result) == 0 ){
      session_distroy ();
      echo "<p>Benvenuto, <b>Ospite</b>! | <a href=\"./register.php\">Registrati</a> | <a href=\"./login.php\">Login</a></p>"
} 
   else {
while ( $row = mysql_fetch_assoc($result)){
echo "<a href=\"./index.php?art=profile&id=".$rows['id']."\";>Profilo </a>".$row['username']";
    }
?>

Uffiii proprio sono in tilt
Chi mi aiuta a vedere che sbaglio ?
Se carico la pagina mi visualizza

Benvenuto, Ospite! | Registrati | Login

" } else { while ( $row = mysql_fetch_assoc($result)){ echo "Profilo ".$row['username']"; } ?>
 

hellslord

Utente Attivo
28 Nov 2006
99
3
0
Venezia
www.squall.it
Sì, in effetti sta cosa mi era sfuggita... $result è passata come parametro a mysql_num_rows e a mysql_fetch_assoc senza essere stata opportunamente inizializzata.

Tuttavia questo errore non porterebbe ad una visualizzazione del genere bensì ad un warning del tipo "is not a valid mysql resource in..."

E' anche vero, ad essere onesti, che anche la mia risposta prima è stata frettolosa.... La mancanza di un ; provocherebbe un errore di sintassi...

Mmmmh....
 

hellslord

Utente Attivo
28 Nov 2006
99
3
0
Venezia
www.squall.it
Ok sintassi messa a posto

Ok, ho trovato un paio di problemini...

Mancava un ; e svariate } di chiusura... Oltre ad esserci un " di troppo...

Il codice sintatticamente corretto è così... Poi chiaramente dipende da quello che si tira su sul db...

PHP:
<?php
if($_SESSION["uid"])
{

   $sql = "SELECT username FROM users WHERE in = '".$_SESSION['uid']."'";
   $sql = mysql_query ($sql) or die (mysql_error());

   if(mysql_num_rows($result) == 0 )
   {
      session_distroy ();
      echo "<p>Benvenuto, <b>Ospite</b>! | <a href=\"./register.php\">Registrati</a> | <a href=\"./login.php\">Login</a></p>";
   }
   else
   {
     while ( $row = mysql_fetch_assoc($result))
     {
       echo "<a href=\"./index.php?art=profile&id=".$rows['id']."\">Profilo </a>".$row['username'];
     }
   }
}
?>

Se posso permettermi un consiglio, ti direi di indentare un po' meglio il codice... Altrimenti è un attimo dimenticarsi una }...
 
Discussioni simili
Autore Titolo Forum Risposte Data
M funzione mysql fetch array PHP 3
K form Inserimento record mysql PHP 2
P Mysql lento a cancellare MySQL 1
P Codifica caratteri speciali mysql php PHP 0
N MAX() + ADD_DATE - per update su Mysql MySQL 0
F Applicazione PHP/MySQL per prenotazioni: limitare il numero massimo di posti prenotabili PHP 20
L tipo boolean non funzionante su mariadb (mysql). E codice php 7.4. PHP 0
M PHP/MySQL - Estrarre valori min e max di ogni gruppo PHP 5
W MySQL ciclo in SELECT MySQL 0
L Mysql gestionale multipiattaforma MySQL 0
W MySQL SELECT list dinamica MySQL 0
M utilizzo mysql in nodejs - crea createdAt e updateAt MySQL 1
T colonne di tabelle mysql ordinate MySQL 0
M Sintassi "personalizzata" per mysql workbench? MySQL 0
A Mysql MySQL 0
F Ricreare struttura php+mysql su Xampp Apache 0
M Array associativi php su 2 campi mysql PHP 10
Z Controllo giorni MYSQL PHP 0
L php mysql non salva solo id PHP 21
L php mysql cerca e visualizza pagina PHP 0
L Mysql: Nascondere le pagine dopo una ricerca PHP 1
R Aggiornare record mysql con Ajax, jQuery e php Ajax 2
S problema con recupero dati tabella mysql PHP 2
E Progressbar estrazione dati da tabella mySQL Ajax 9
Z MySql injection PHP PHP 1
D controllare valore in tabella mysql PHP 0
A pulsante di update campo mysql con javascript Javascript 2
R Tutto su utf-8 ma ancora problemi con i caratteri speciali in mysql MySQL 1
T differenza fra mysql xampp e un mysql server Database 0
R Importazione csv su mysql tramite array PHP 2
Z Problema con INT MySQL PHP 1
Z Problema database MySQL con XAMPP PHP 0
D problema php mysql PHP 1
D problema php mysql PHP 1
N Server mysql non raggiungibile da connessione esterna MySQL 1
B Crea pdf da tabella mysql "ultima riga modificata" MySQL 4
D evitare di inserirre duplicati in mysql PHP 4
L salvare codice html in mysql PHP 3
L Google chart php mysql PHP 2
S Gestire scelta dropdown con dati da Mysql PHP 2
K cron job mysql PHP 3
elpirata Query per leggere dati da una tabella mysql e mostrarli a video in base a parametri passati tramite GET PHP 5
R Errore UPDATE tabella mysql PHP 1
R Caricamento immagine su cartella remota + mysql PHP 3
D Emoji in mysql Database 0
L Aiuto per programma web php/mySQL PHP 2
S Problema esportazione tabelle Mysql in Excel PHP 0
S Cancellare una riga MYSQL PHP 1
L Ricerca valore mysql e incremento PHP 73
G database mysql contengono informazioni ? MySQL 0

Discussioni simili