Pagina 1 di 1

Problema mysql_fetch_assoc/array

Inviato: 03/04/2012, 12:13
da DaniX
Salve a tutti, come ho detto, sono alle prime armi col php, infatti ho appena avuto la necessita' di scrivere questo script che, in teoria, dovrebbe controllare se l'username inserito sia gia' presente nel database... purtroppo la query mi fallisce e il fetch mi restituisce l'errore: "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Passaver\PHP\funzioni_sito\username.php on line 11"
Non riesco minimamente a trovare una soluzione... che cosa devo fare??? :cry:

Questo e' l'ultima prova in PHP che ho fatto, fallendo:

Codice: Seleziona tutto

<?php

error_reporting (E_ALL ^ E_NOTICE);

	session_start();
	if(isset($_SESSION["email"]))
	
		if(isset($_POST["user"]))
		{
			$sql = mysql_query("SELECT username FROM utenti_registrati WHERE username = '".$_POST["user"]."'");
			$fetch = mysql_fetch_assoc($sql);
			
			if($fetch["username"] > 1)
			{
				echo "Username già esistente";
			}
			else
			{
				mysql_query("UPDATE utenti_registrati SET username = '".$_POST['user']."' WHERE email = '".$_SESSION['email']."'");
			}
		}
		else
		{
			if(!$_POST["user"])
			{
				echo "Inserisci un username";
			}
			else
			{
				echo "";
			}
			
		}

?>
Questa e' la struttura del database:

Codice: Seleziona tutto

-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generato il: Apr 03, 2012 alle 12:15
-- Versione del server: 5.5.16
-- Versione PHP: 5.3.8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

--
-- Database: `my_passaver`
--

-- --------------------------------------------------------

--
-- Struttura della tabella `utenti_registrati`
--

CREATE TABLE IF NOT EXISTS `utenti_registrati` (
  `email` varchar(30) NOT NULL,
  `password` varchar(15) NOT NULL,
  `data_nascita` date NOT NULL,
  `data_registrazione` date NOT NULL,
  `provincia` varchar(2) NOT NULL,
  `conferma` tinyint(1) NOT NULL,
  `username` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dump dei dati per la tabella `utenti_registrati`
--

INSERT INTO `utenti_registrati` VALUES('dnviti@localhost.com', 'daniele94', '1994-06-14', '2012-04-03', 'PG', 1, NULL);

Re: Problema mysql_fetch_assoc/array

Inviato: 06/04/2012, 14:22
da DaniX
Ehm... ragazzi? ci siete???

Re: Problema mysql_fetch_assoc/array

Inviato: 06/04/2012, 14:41
da Micogian
Certo che ci siamo, ma questo è un Forum di supporto a "phpbb", non PHP.

Re: Problema mysql_fetch_assoc/array

Inviato: 08/04/2012, 16:35
da DaniX
Non sapreste rispondermi? Mi scuso per avervi chiesto una cosa che non riguarda il phpbb. Credevo che in questa sezione (PHP - MySQL) si trattassero argomenti di PHP e non di phpbb... c'è pure scritto.

Re: Problema mysql_fetch_assoc/array

Inviato: 17/04/2012, 12:38
da Ditestamia
se ti può essere di aiuto
Returns an associative array of strings that corresponds to the fetched row, or FALSE if there are no more rows.
trovato su sito di php

prova a fare un echo della query e vedi se gli viene passato correttamente il parametro in POST[]