Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Problema form

  1. #1

    Problema form

    Salve a tutti, dopo infiniti tentativi sono riuscito a costruire una pagina con form per l'inserimento di alcuni dati da parte degli utenti del sito. Il problema che sto riscontrando ora è che quando vado a caricare la pagina sul mio server (altervista) mi viene restituito un messaggio di errore "database non trovato" riporto di seguito il codice:

    <?php require_once('Connections/fabio.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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']);
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO fabio (nome, cognome, indirizzo, telefono) VALUES (%s, %s, %s, %s)",
    GetSQLValueString($_POST['nome'], "text"),
    GetSQLValueString($_POST['cognome'], "text"),
    GetSQLValueString($_POST['indirizzo'], "text"),
    GetSQLValueString($_POST['telefono'], "double"));

    mysql_select_db($database_fabio, $fabio);
    $Result1 = mysql_query($insertSQL, $fabio) or die(mysql_error());
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO fabio (nome, cognome, indirizzo, telefono) VALUES (%s, %s, %s, %s)",
    GetSQLValueString($_POST['nome'], "text"),
    GetSQLValueString($_POST['cognome'], "text"),
    GetSQLValueString($_POST['indirizzo'], "text"),
    GetSQLValueString($_POST['telefono'], "double"));

    mysql_select_db($database_fabio, $fabio);
    $Result1 = mysql_query($insertSQL, $fabio) or die(mysql_error());
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO fabio (nome, cognome, indirizzo, telefono) VALUES (%s, %s, %s, %s)",
    GetSQLValueString($_POST['nome'], "text"),
    GetSQLValueString($_POST['cognome'], "text"),
    GetSQLValueString($_POST['indirizzo'], "text"),
    GetSQLValueString($_POST['telefono'], "double"));

    mysql_select_db($database_fabio, $fabio);
    $Result1 = mysql_query($insertSQL, $fabio) or die(mysql_error());
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO fabio (nome, cognome, indirizzo, telefono) VALUES (%s, %s, %s, %s)",
    GetSQLValueString($_POST['nome'], "text"),
    GetSQLValueString($_POST['cognome'], "text"),
    GetSQLValueString($_POST['indirizzo'], "text"),
    GetSQLValueString($_POST['telefono'], "int"));

    mysql_select_db($database_fabio, $fabio);
    $Result1 = mysql_query($insertSQL, $fabio) or die(mysql_error());
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO fabio (nome, cognome, indirizzo, telefono) VALUES (%s, %s, %s, %s)",
    GetSQLValueString($_POST['nome'], "text"),
    GetSQLValueString($_POST['cognome'], "text"),
    GetSQLValueString($_POST['indirizzo'], "text"),
    GetSQLValueString($_POST['telefono'], "double"));

    mysql_select_db($database_fabio, $fabio);
    $Result1 = mysql_query($insertSQL, $fabio) or die(mysql_error());
    }
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Documento senza titolo</title>
    </head>

    <body>
    <form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
    <table width="600" border="1" cellspacing="0" cellpadding="0">
    <tr>
    <td width="118"><div align="center">nome</div></td>
    <td width="476"><label>
    <input type="text" name="nome" id="nome">
    </label></td>
    </tr>
    <tr>
    <td><div align="center">cognome</div></td>
    <td><label>
    <input type="text" name="cognome" id="cognome">
    </label></td>
    </tr>
    <tr>
    <td><div align="center">indirizzo</div></td>
    <td><label>
    <input type="text" name="indirizzo" id="indirizzo">
    </label></td>
    </tr>
    <tr>
    <td><div align="center">telefono</div></td>
    <td><label>
    <input type="text" name="telefono" id="telefono">
    </label></td>
    </tr>
    <tr>
    <td><div align="center">testo inserzione</div></td>
    <td><label>
    <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>
    </label></td>
    </tr>
    <tr>
    <td><div align="center">invio</div></td>
    <td><label>
    <input type="submit" name="button" id="button" value="Invia">
    </label></td>
    </tr>
    </table>
    <input type="hidden" name="MM_insert" value="form1">
    </form>
    </body>
    </html>

    Qualcuno saprebbe indicarmi cosa c'è di sbagliato? Mille grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2001
    Messaggi
    101
    Io cercherei prima nel file di connessione fabio.php se c'è qualche errore;
    posta quello così vediamo

  3. #3
    Ecco qui il codice di "fabio.php". Sono ai primi passi con la programmazione, perdonate eventuali bestialità che ho combinato

    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_fabio = "localhost";
    $database_fabio = "fabio";
    $username_fabio = "root";
    $password_fabio = "xxxxxx";
    $fabio = mysql_pconnect($hostname_fabio, $username_fabio, $password_fabio) or trigger_error(mysql_error(),E_USER_ERROR);
    ?>

  4. #4
    Utente di HTML.it
    Registrato dal
    Feb 2001
    Messaggi
    101
    $database_fabio = "fabio";
    $username_fabio = "root";
    $password_fabio = "xxxxxx";
    Questi parametri sono quelli che hai settato in locale, sei sicuro che su altervista siano gli stessi?
    anche perchè mi pare (non ne sono certo) che altervista metta il prefisso "my" sul nome del database nel tuo caso sarebbe "my_fabio".
    Controlla anche Username e Password.

  5. #5
    infatti, nel file di connessione devi stare sempre attento a mettere le coordinate del server, non quelle che usi in locale. Ti consiglio di farne 2 e di rinominarli a seconda delle necessità

  6. #6
    E' vero, ho corretto i parametri ed ora funziona. Mille grazie

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.