Un Evento Unico. 5 Sale. 27 Interventi. SEO, SOCIAL, E-Commerce, Mobile, Turismo.
CLICCA QUI e SCOPRI DI PIù X Chiudi
 
Forum GT: Condividiamo idee e conoscenza Forum GT: Condividiamo idee e conoscenza


Condividi questo contenuto nei Social Network:
Ti stiamo aspettando: Registrati subito e gratis. Entra a far parte di una delle comunità più attive in Italia. Se hai dimenticato i tuoi dati li puoi recuperare subito.


Vai indietro   Forum per Webmaster: Condividiamo Idee e Conoscenza > Sviluppo e Gestione siti web > Php - Mysql
Benvenuto! Forum Regole FAQ Lista utenti Calendario Segna come letti


Rispondi
 
LinkBack Strumenti di discussione
Vecchio 27-12-11, 11:26   #1 (permalink)
User
 
Data di registrazione: Oct 2011
Ubicazione: Roma
Messaggi: 33
Piccolo problema...

Buongiorno a tutti
ho questo pezzo di codice per aggiungere certi valori su un DB Mysql:

Codice:
<?php
 // creates the new record form
 // since this form is used multiple  times in this file, I have made it a function that is easily reusable
 function renderForm($apiario, $lat, $long, $error)
 {
 ?>
<!DOCTYPE  html>
<head>
	<meta charset="utf-8" />
</head>
<body>
<div class="container">
			<div class="eight columns">
				<h3>Elenco degli apiari</h3>
				<div class="row">
					<div class="twelve columns">
						<div class="panel">
 <?php 
 // if there are any errors, display them
 if ($error != '')
 {
  echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 ?> 
 
 <form action="" method="post">
 <div>
 <label>Nome Apiario: *</label> <input type="text" class="input-text" name="apiario" value="<?php echo $apiario; ?>" /><br/>

 <label>Latitudine: *</label> <input type="text" class="input-text" name="lat" value="<?php echo $lat; ?>" /><br/><br>

 <label>Longitudine: *</label> <input type="text" class="input-text" name="long" value="<?php echo $long; ?>" /><br/><br>
 
 <p>* campi obbligatori</p>
 <input type="submit" name="submit" value="Registra" class="nice radius blue button">
 </div>
 </form> 
</div></div>
 <!-- Included JS Files -->
	<script src="javascripts/foundation.js"></script>
	<script src="javascripts/app.js"></script>
 </body>
 </html>  
 <?php 
 }
  // connect to the database
 include('connect-db.php');
 
 // check if the form has been submitted. If it has, start to process the form and save it to the database
 if (isset($_POST['submit']))
 { 
 // get form data, making sure it is valid
 $apiario = mysql_real_escape_string(htmlspecialchars($_POST['apiario']));
 $lat = mysql_real_escape_string(htmlspecialchars($_POST['lat']));
 $long = mysql_real_escape_string(htmlspecialchars($_POST['long']));

 // check to make sure both fields are entered
 if ($apiario == '' || $lat == '' || $long == '')
 {
 // generate error message
 $error = '* Riempire i campi obbligatori';
 
 // if either field is blank, display the form again
 renderForm($apiario, $lat, $long, $error);
 }
 else
 {
 // save the data to the database
  mysql_query("INSERT apiari SET apiario='$apiario', lat='$lat', long='$long'")
 or die(mysql_error()); 
 
 // once saved, redirect back to the view page
 header("Location: index.php"); 
 }
 }
 else
 // if the form hasn't been submitted, display the form
 {
 renderForm('','','','');
 }
?>
Ho ricontrollato mille volte il codice ma ricevo questo errore:
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 'long='testo di prova'' at line 1

Non so più che pesci prendere !!
Riuscite a darmi una mano ?

Grazie !
marcopietro non in linea   Rispondi citando
Vecchio 27-12-11, 15:42   #2 (permalink)
User
 
Data di registrazione: Jun 2010
Messaggi: 193
E' sbagliato la sintassi del INSERT MySQL, dai un'occhiata dev.mysql.com/doc/refman/5.5/en/insert.html.
__________________
Siti Web
linoma non in linea   Rispondi citando
Vecchio 30-12-11, 22:01   #3 (permalink)
User
 
Data di registrazione: Nov 2011
Ubicazione: Bologna
Messaggi: 13
mysql_query($database,"INSERT INTO $db_table (`campo1`,`campo2`,...,`campon`)
VALUES (`valorecampo1`,`valorecampo2`,...,`valorecampon`) or die(mysql_error());

Controlla le parentesi, non sono sicuro che vadano bene
Joshua Whopper non in linea   Rispondi citando
Rispondi


Strumenti di discussione

Regole di scrittura
Non puoi postare nuove discussioni
Non puoi rispondere alle discussioni
Non puoi allegare file
Non puoi editare i tuoi post

BB code is Attivo
smilies è Attivo
[IMG] il codice è Attivo
Il codice HTML è Disattivato
Trackbacks are Attivo
Pingbacks are Attivo
Refbacks are Disattivato
Vai al forum



Tutti gli orari sono GMT +3. Attualmente sono le 15:40.




Forum GT - © 2004-2009 GT idea S.r.l P.iva 02418200800 - Privacy/Disclaimer

SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.