Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Problema SQL su form

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    40

    Problema SQL su form

    ciao a tutti, io sto tentando di inserire dei dati in una tabella del database tramite form, i dati che inseriscono devono corrispondere alla riga in cui c'è lo username di quello loggato, di modo da modificare i dati dell'utente...c'è un piccolo problema xò....ora vi mostro il codice



    codice:
    <?php require_once('Connections/Register.php'); ?>
    <?php
    session_start();
    $squadra = $_SESSION['MM_Username'];
    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 'squadra' (Ultras, Stadio, Soprannome) VALUES (%s, %s, %s) WHERE 'Nome' = '$squadra' ",
                           GetSQLValueString($_POST['Ultras'], "text"),
                           GetSQLValueString($_POST['Stadio'], "text"),
                           GetSQLValueString($_POST['Soprannome'], "text"));
    
      mysql_select_db($database_Register, $Register);
      $Result1 = mysql_query($insertSQL, $Register) or die(mysql_error());
    }
    ?><style type="text/css">
    <!--
    body {
    	background-color: #006600;
    }
    -->
    </style>
    
    <div align="center">
      <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
        
    
    </p>
        
    
    </p>
        <table align="center" bgcolor="#006600">
          <tr valign="baseline">
            <td align="right" nowrap="nowrap" bgcolor="#006600">Ultras:</td>
            <td><input type="text" name="Ultras" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Stadio:</td>
            <td><input type="text" name="Stadio" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Soprannome:</td>
            <td><input type="text" name="Soprannome" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right"> </td>
            <td><input name="" type="submit" onclick="&lt;iframe&gt;id=&quot;main&quot; src=&quot;spogliatoio.php&quot; frameborder=&quot;0&quot; width=&quot;700&quot; height=&quot;100%&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;yes&quot;&lt;/iframe&gt;" value="Modifica" /></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form1" />
      </form>
      
    
    </p>
    </div>
    e quando schiaccio il pulsante x inviare i dati mi dice...

    codice:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''squadra' (Ultras, Stadio, Soprannome)

  2. #2
    Utente di HTML.it L'avatar di dararag
    Registrato dal
    Jan 2008
    Messaggi
    434
    non ci vogliono gli apici nè con il nome della tabella dopo INTO ne con il nome del campo dopo WHERE, attenzione però, il nome del campo, non il valore

  3. #3
    Esatto, non ci vogliono gli apici.

    Al massimo (necessario, ad esempio se specifichi come nome tabella una parola riservata) usi i backtick, che si ottengono cosi: ` -> ALT+9 6.

    Ciao

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    40
    niente....sono disperato.... :rollo:

  5. #5
    Utente di HTML.it L'avatar di dararag
    Registrato dal
    Jan 2008
    Messaggi
    434
    togli sprintf, così non ti serve a niente, forse è quello che da l'errore, scrivi così:
    codice:
    <?php require_once('Connections/Register.php'); ?>
    <?php
    session_start();
    $squadra = $_SESSION['MM_Username'];
    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 = "INSERT INTO 'squadra' (Ultras, Stadio, Soprannome) VALUES (%s, %s, %s) WHERE 'Nome' = '$squadra' ",
                           GetSQLValueString($_POST['Ultras'], "text"),
                           GetSQLValueString($_POST['Stadio'], "text"),
                           GetSQLValueString($_POST['Soprannome'], "text");
    
      mysql_select_db($database_Register, $Register);
      $Result1 = mysql_query($insertSQL, $Register) or die(mysql_error());
    }
    ?><style type="text/css">
    <!--
    body {
    	background-color: #006600;
    }
    -->
    </style>
    
    <div align="center">
      <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
        
    
     </p>
        
    
     </p>
        <table align="center" bgcolor="#006600">
          <tr valign="baseline">
            <td align="right" nowrap="nowrap" bgcolor="#006600">Ultras:</td>
            <td><input type="text" name="Ultras" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Stadio:</td>
            <td><input type="text" name="Stadio" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Soprannome:</td>
            <td><input type="text" name="Soprannome" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">  </td>
            <td><input name="" type="submit" onclick="&lt;iframe&gt;id="main" src="spogliatoio.php" frameborder="0" width="700" height="100%" marginheight="0" marginwidth="0" scrolling="yes"&lt;/iframe&gt;" value="Modifica" /></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form1" />
      </form>
      
    
     </p>
    </div>

  6. #6
    Utente bannato
    Registrato dal
    Apr 2008
    Messaggi
    146
    il codice che ti è stato scritto in rosso cioè:

    $insertSQL = "INSERT INTO 'squadra' (Ultras, Stadio, Soprannome) VALUES (%s, %s, %s) WHERE 'Nome' = '$squadra' ",
    GetSQLValueString($_POST['Ultras'], "text"),
    GetSQLValueString($_POST['Stadio'], "text"),
    GetSQLValueString($_POST['Soprannome'], "text")

    modificalo così:

    $utras=$_POST['Ultras'];
    $stadio=$_POST['Stadio'];
    $soprannome=$_POST['Soprannome'];

    $insertSQL = "INSERT INTO squadra (Ultras, Stadio, Soprannome) VALUES ($ultras, $stadio, $soprannome) WHERE Nome = '$squadra' ";


    SEMPLICE E RAPIDO

    prova e fammi sapere

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.