problema query mysql in php

Giuseppe Scarlato

Nuovo Utente
22 Feb 2015
3
0
0
26
Ciao a tutti, ho un problema con questo script in php:

PHP:
<?php

    include 'http://www.iwould.it/php/connectDB.php';

    $mail = htmlspecialchars($_POST["mail"]);
    $name = htmlspecialchars($_POST["name"]);
    $surname = htmlspecialchars($_POST["surname"]);
    $address = htmlspecialchars($_POST["address"]);
    $cap = htmlspecialchars($_POST["cap"]);
    $url = htmlspecialchars($_POST["url"]);
    $description = htmlspecialchars($_POST["description"]);
    $taxcode = htmlspecialchars($_POST["taxcode"]);
    $width = htmlspecialchars($_POST["Width"]);
    $height = htmlspecialchars($_POST["Height"]);
    $pix = htmlspecialchars($_POST["period"]);
    $price = ($width * $height) * $pix;
    $code = md5(uniqid(rand(), true));
    $dimensione = $width . "X" . $height;
    
    if ($pix==0.12) {
	    $period=5;
	} elseif ($pix==0.14) {
	    $period=6;
	} elseif ($pix==0.16) {
	    $period=7;
	} elseif ($pix==0.18) {
	    $period=8;
	} elseif ($pix==0.2) {
	    $period=9;
	} elseif ($pix==0.22) {
	    $period=10;
	} elseif ($pix==0.24) {
	    $period=11;
	} elseif ($pix==0.26) {
	    $period=12;
	} else {$period=4}
	
	$connect = getConnection();
    
    $query = "INSERT INTO `iwould_it`.`Ordini` (`ID`, `Nome`, `Cognome`, `E-mail`, `Indirizzo`, `CAP`, `Tax_Code`, `Url`, `Descrizzione`, `Dimensione`, `Periodo`, `Prezzo`, `Scadenza`, `Attivazione`, `Stato`)
                VALUES (NULL, \'" .
                $name . "\', \'" .
                $surname . "\', \'" . 
                $mail . "\', \'" . 
                $address . "\', \'" . 
                $cap . "\', \'" . 
                $taxcode . "\', \'" . 
                $url . "\', \'" . 
                $description . "\', \'" . 
                $dimensione . "\', \'" . 
                $period . "\', \'" . 
                $price . "\', NULL, \'" . 
                $code . "\', NULL);";
    
?>

il codice dovrebbe connettersi al database e inserire i dati presi da alcuni form nella tabella Ordini ma non li inserisce. Ho già verificato se si connette al database e non mi dà errore, il codice nel file connectDB.php è questo:

PHP:
<?php

function getConnection() {
    global $g_link;
        if( $g_link )
            return $g_link;
        $g_link = mysql_connect( 'iwould.it.mysql', 'iwould_it', 'csweUTKE') or die('Could not connect to server.' );
        mysql_select_db('iwould_it', $g_link) or die('Could not select database.');
        return $g_link;
}

function CleanUpDB()
    {
        global $g_link;
        if( $g_link != false )
            mysql_close($g_link);
        $g_link = false;
    }
 
 
?>

Spero che mi possiate aiutare a trovare e risolvere il problema, Grazie in anticipo!! :byebye:
 
a parte tutti gli apici "a rovescio" e le barre nel testo della query, pressoché inutili e che creano confusione,

ti connetti al database, componi la query e lo script termina, dove esegui la query ?
 
Ultima modifica:
si, scusa, hai scritto

$connect = ....

$query = "insert ...."

ma poi non richiami nessuna funzione di mysql x eseguirla
almeno così "non" si vede nello script che hai postato, o non vedo io ?
 
ah.. si scusa errore mio ho cancellato una parte di codice perchè c'erano dati personali e per sbaglio ho cancellato anche quella con la query. Ora invio il codice completo ;)
PHP:
<?php

    include 'http://www.iwould.it/php/connectDB.php';

    $mail = htmlspecialchars($_POST["mail"]);
    $name = htmlspecialchars($_POST["name"]);
    $surname = htmlspecialchars($_POST["surname"]);
    $address = htmlspecialchars($_POST["address"]);
    $cap = htmlspecialchars($_POST["cap"]);
    $url = htmlspecialchars($_POST["url"]);
    $description = htmlspecialchars($_POST["description"]);
    $taxcode = htmlspecialchars($_POST["taxcode"]);
    $width = htmlspecialchars($_POST["Width"]);
    $height = htmlspecialchars($_POST["Height"]);
    $pix = htmlspecialchars($_POST["period"]);
    $price = ($width * $height) * $pix;
    $code = md5(uniqid(rand(), true));
    $dimensione = $width . "X" . $height;
    
    if ($pix==0.12) {
	    $period=5;
	} elseif ($pix==0.14) {
	    $period=6;
	} elseif ($pix==0.16) {
	    $period=7;
	} elseif ($pix==0.18) {
	    $period=8;
	} elseif ($pix==0.2) {
	    $period=9;
	} elseif ($pix==0.22) {
	    $period=10;
	} elseif ($pix==0.24) {
	    $period=11;
	} elseif ($pix==0.26) {
	    $period=12;
	} else {$period=4}
	
	$connect = getConnection();
    
    $query = "INSERT INTO `iwould_it`.`Ordini` (`ID`, `Nome`, `Cognome`, `E-mail`, `Indirizzo`, `CAP`, `Tax_Code`, `Url`, `Descrizzione`, `Dimensione`, `Periodo`, `Prezzo`, `Scadenza`, `Attivazione`, `Stato`)
                VALUES (NULL, \'" .
                $name . "\', \'" .
                $surname . "\', \'" . 
                $mail . "\', \'" . 
                $address . "\', \'" . 
                $cap . "\', \'" . 
                $taxcode . "\', \'" . 
                $url . "\', \'" . 
                $description . "\', \'" . 
                $dimensione . "\', \'" . 
                $period . "\', \'" . 
                $price . "\', NULL, \'" . 
                $code . "\', NULL);";
    
    resource mysql_query ($query [, resource $connect ] ) or die("Query non valida: " . mysql_error());
    header("Location: http://www.iwould.it/index1.html");

ecco qua, grazie di avermelo fatto notare. :D
 
Manca l'esecuzione :)

PHP:
$result = mysql_query($query, $myconn) or die('Errore...');
 

Discussioni simili