Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Problemi mysql_num_rows

    Ciao ragazzi ecco il problema:
    (Da premettere che nonostante abbia effettuato ricerche sul forum non sono riuscito a risolvere il problema)
    sto realizzando uno script si registrazione utente e voglio inserire un controllo per evitare che ci siano dati doppi nel database, ovvero che due utenti inseriscano la stessa user, non riesco ad inserire il controllo, vi posto il mio codice sperando nel vostro aiuto, gli errori che mi rileva adesso sono alle righe che ho contraddistinto con il colore rosso , credo ce ne siano altri, aiutatemi.

    <?php require_once('Connections/server.php'); ?>
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING']))
    {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    $query = "SELECT user FROM prova WHERE user = '$user'";
    $risultato = mysql_query($query,$db);
    $num = mysql_num_rows ($risultato);
    if($num == '0')
    {
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
    {
    $insertSQL = sprintf("INSERT INTO prova (`user`, nome) VALUES (%s, %s)",
    GetSQLValueString($_POST['user'], "text"),
    GetSQLValueString($_POST['nome'], "text"));
    mysql_select_db($database_server, $server);
    $Result1 = mysql_query($insertSQL, $server) or die("Devi Compilare tutti i campi");
    }
    }
    else
    {
    print ("errore record gia esistente");
    }


    ?>$risultato = mysql_query($query,$db);

  2. #2
    che errore ti da???

  3. #3

    Ecco l'errore

    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\wamp\www\ceduc\untitled-1.php on line 33

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\wamp\www\ceduc\untitled-1.php on line 34

  4. #4
    Visto che siete in molti ad usare sprintf per settare una variabile, mi dici in che testo lo hai letto.... cosi' evito di suggerire il titolo ad altri...

    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 © 2024 vBulletin Solutions, Inc. All rights reserved.