Insert record PHP/MySQL

Fermé
tux_linux Messages postés 3 Date d'inscription dimanche 13 avril 2008 Statut Membre Dernière intervention 14 avril 2008 - 13 avril 2008 à 23:18
tux_linux Messages postés 3 Date d'inscription dimanche 13 avril 2008 Statut Membre Dernière intervention 14 avril 2008 - 14 avril 2008 à 09:00
Bonjour,
Je suis en train de faire un site sur lequel il y a un formulaire d'insertion d'enregistrements.
N'etant pas un vrai informaticien mais plutot un bidouilleur, j'outilise DreamWeaver ...
J'ai un mechant message d'erreur : <<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 '' at line 1>> visible si jamais vous avez la curiosite de renseigner les champs de l'adresse : www.job.edendesign-tm.com/formular_inscriere.php
Voici aussi un morceau de code pour ceux qui auront l'amabilite de jeter un coup d'oeuil, et avant de les fatiguer trop, voici aussi mes remerciements pour l'eventuelle aide : MERCI !

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php require_once('Connections/job_con.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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "formular")) {
$insertSQL = sprintf("INSERT INTO candidati",
GetSQLValueString($HTTP_POST_VARS['nume'], "text"),
GetSQLValueString($HTTP_POST_VARS['prenume'], "text"),
GetSQLValueString($HTTP_POST_VARS['sex'], "text"),
GetSQLValueString($HTTP_POST_VARS['data_nasterii'], "date"),
GetSQLValueString($HTTP_POST_VARS['email'], "text"),
GetSQLValueString($HTTP_POST_VARS['adresa'], "text"),
GetSQLValueString($HTTP_POST_VARS['localitate'], "text"),
GetSQLValueString($HTTP_POST_VARS['judet'], "text"),
GetSQLValueString($HTTP_POST_VARS['tel_principal'], "text"),
GetSQLValueString($HTTP_POST_VARS['tel_secundar'], "text"),
GetSQLValueString($HTTP_POST_VARS['studii_candidat'], "text"),
GetSQLValueString($HTTP_POST_VARS['experienta_candidat'], "text"),
GetSQLValueString($HTTP_POST_VARS['nivel_profesional'], "text"),
GetSQLValueString($HTTP_POST_VARS['domeniu_profesional'], "text"),
GetSQLValueString($HTTP_POST_VARS['domeniu_profesional_altul'], "text"),
GetSQLValueString(isset($HTTP_POST_VARS['a']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($HTTP_POST_VARS['b']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($HTTP_POST_VARS['c']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($HTTP_POST_VARS['d']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($HTTP_POST_VARS['e']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($HTTP_POST_VARS['germana'], "text"),
GetSQLValueString($HTTP_POST_VARS['engleza'], "text"),
GetSQLValueString($HTTP_POST_VARS['franceza'], "text"),
GetSQLValueString($HTTP_POST_VARS['italiana'], "text"),
GetSQLValueString($HTTP_POST_VARS['spaniola'], "text"),
GetSQLValueString($HTTP_POST_VARS['domeniu1'], "text"),
GetSQLValueString($HTTP_POST_VARS['domeniu2'], "text"),
GetSQLValueString($HTTP_POST_VARS['domeniu3'], "text"),
GetSQLValueString($HTTP_POST_VARS['domeniu1_altul'], "text"),
GetSQLValueString($HTTP_POST_VARS['domeniu2_altul'], "text"),
GetSQLValueString($HTTP_POST_VARS['domeniu3_altul'], "text"),
GetSQLValueString($HTTP_POST_VARS['salariu_minim'], "int"));

mysql_select_db($database_job_con, $job_con);
$Result1 = mysql_query($insertSQL, $job_con) or die(mysql_error());

$insertGoTo = "/interim/index.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
A voir également:

2 réponses

gryzzly Messages postés 4608 Date d'inscription lundi 7 novembre 2005 Statut Contributeur Dernière intervention 24 octobre 2020 1 332
14 avril 2008 à 00:58
Salut,

Merci d'utiliser la balise code pour poster ... du code. Ca facilite le travail de tout le monde, notament en conservant l'indentation.
0
tux_linux Messages postés 3 Date d'inscription dimanche 13 avril 2008 Statut Membre Dernière intervention 14 avril 2008
14 avril 2008 à 09:00
Bonjour,

Je reposte mon premier message en essayant de respecter les regles du postage sur le forum que j'ai ignore ... Mea culpa. Je m'excuse aussi d'avoir demare un autre fil de discution identique avec les memes ignorances ... il m'avait paru que ce premier messsage n'etait pas sur le forum. Je demmande pardon !

Je suis en train de faire un site sur lequel il y a un formulaire d'insertion d'enregistrements.
N'etant pas un vrai informaticien mais plutot un bidouilleur, j'outilise DreamWeaver ...
J'ai un mechant message d'erreur :

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 '' at line 1

visible si jamais vous avez la curiosite de renseigner les champs de l'adresse :

http://www.job.edendesign-tm.com/formular_inscriere.php

Voici aussi un morceau de code pour ceux qui auront l'amabilite de jeter un coup d'oeuil, et avant de les fatiguer trop, voici aussi mes remerciements pour l'eventuelle aide : MERCI !


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<?php require_once('Connections/job_con.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 = $HTTP_SERVER_VARS['PHP_SELF']; 
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { 
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; 
} 

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "formular")) { 
$insertSQL = sprintf("INSERT INTO candidati", 
GetSQLValueString($HTTP_POST_VARS['nume'], "text"), 
GetSQLValueString($HTTP_POST_VARS['prenume'], "text"), 
GetSQLValueString($HTTP_POST_VARS['sex'], "text"), 
GetSQLValueString($HTTP_POST_VARS['data_nasterii'], "date"), 
GetSQLValueString($HTTP_POST_VARS['email'], "text"), 
GetSQLValueString($HTTP_POST_VARS['adresa'], "text"), 
GetSQLValueString($HTTP_POST_VARS['localitate'], "text"), 
GetSQLValueString($HTTP_POST_VARS['judet'], "text"), 
GetSQLValueString($HTTP_POST_VARS['tel_principal'], "text"), 
GetSQLValueString($HTTP_POST_VARS['tel_secundar'], "text"), 
GetSQLValueString($HTTP_POST_VARS['studii_candidat'], "text"), 
GetSQLValueString($HTTP_POST_VARS['experienta_candidat'], "text"), 
GetSQLValueString($HTTP_POST_VARS['nivel_profesional'], "text"), 
GetSQLValueString($HTTP_POST_VARS['domeniu_profesional'], "text"), 
GetSQLValueString($HTTP_POST_VARS['domeniu_profesional_altul'], "text"), 
GetSQLValueString(isset($HTTP_POST_VARS['a']) ? "true" : "", "defined","'Y'","'N'"), 
GetSQLValueString(isset($HTTP_POST_VARS['b']) ? "true" : "", "defined","'Y'","'N'"), 
GetSQLValueString(isset($HTTP_POST_VARS['c']) ? "true" : "", "defined","'Y'","'N'"), 
GetSQLValueString(isset($HTTP_POST_VARS['d']) ? "true" : "", "defined","'Y'","'N'"), 
GetSQLValueString(isset($HTTP_POST_VARS['e']) ? "true" : "", "defined","'Y'","'N'"), 
GetSQLValueString($HTTP_POST_VARS['germana'], "text"), 
GetSQLValueString($HTTP_POST_VARS['engleza'], "text"), 
GetSQLValueString($HTTP_POST_VARS['franceza'], "text"), 
GetSQLValueString($HTTP_POST_VARS['italiana'], "text"), 
GetSQLValueString($HTTP_POST_VARS['spaniola'], "text"), 
GetSQLValueString($HTTP_POST_VARS['domeniu1'], "text"), 
GetSQLValueString($HTTP_POST_VARS['domeniu2'], "text"), 
GetSQLValueString($HTTP_POST_VARS['domeniu3'], "text"), 
GetSQLValueString($HTTP_POST_VARS['domeniu1_altul'], "text"), 
GetSQLValueString($HTTP_POST_VARS['domeniu2_altul'], "text"), 
GetSQLValueString($HTTP_POST_VARS['domeniu3_altul'], "text"), 
GetSQLValueString($HTTP_POST_VARS['salariu_minim'], "int")); 

mysql_select_db($database_job_con, $job_con); 
$Result1 = mysql_query($insertSQL, $job_con) or die(mysql_error()); 

$insertGoTo = "/interim/index.php"; 
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { 
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; 
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; 
} 
header(sprintf("Location: %s", $insertGoTo)); 
} 
?>
0