INSERT probleem
zit met een klein probleem, ik krijg volgende foutmelding:
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 26
als ik onderstaande query laat lopen
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
$datum = date("d/m/y");
$to = "[email protected]";
$problem = $_POST[problem];
$fl1 = $_POST[fl1];
$fr1 = $_POST[fr1];
$to1 = $_POST[to1];
$dl1 = $_POST[dl1];
$px1 = $_POST[px1];
$fl2 = $_POST[fl2];
$fr2 = $_POST[fr2];
$to2 = $_POST[to2];
$dl2 = $_POST[dl2];
$px2 = $_POST[px2];
$fl3 = $_POST[fl3];
$fr3 = $_POST[fr3];
$to3 = $_POST[to3];
$dl3 = $_POST[dl3];
$px3 = $_POST[px3];
$fl4 = $_POST[fl4];
$fr4 = $_POST[fr4];
$to4 = $_POST[to4];
$dl4 = $_POST[dl4];
$px4 = $_POST[px4];
$addi = $_POST[additional];
$auth1 = $_POST[auth1];
$auth2 = $_POST[auth2];
$ip = $_SERVER[REMOTE_ADDR];
$dbhost = 'xxx';
$dbuser = 'xxx';
$dbpass = 'xxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 's7654sho_report';
mysql_select_db($dbname);
//echo" '$problem','$fl1','$fr1','$to1','$dl1','$px1','$fl2','$fr2','$to2','$dl2','$px2','$fl3','$fr3','$to3','$dl3','$px3','$fl4','$fr4','$to4','$dl4','$px4','$addi','$auth1','$auth2','$ip'";
$sql="INSERT INTO fi( problem1, fl1, fr1, to1, dl1, px1, fl2, fr2, to2, dl2, px2, fl3, fr3, to3, dl3, px3, fl4, fr4, to4, dl4, px4, addi, auth1, auth2, ip)
VALUES(
'" . mysql_real_escape_string($problem) . "',
'" . mysql_real_escape_string($fl1) . "',
'" . mysql_real_escape_string($fr1) . "',
'" . mysql_real_escape_string($to1) . "',
'" . mysql_real_escape_string($dl1) . "',
'" . mysql_real_escape_string($px1) . "',
'" . mysql_real_escape_string($fl2) . "',
'" . mysql_real_escape_string($fr2) . "',
'" . mysql_real_escape_string($to2) . "',
'" . mysql_real_escape_string($dl2) . "',
'" . mysql_real_escape_string($px2) . "',
'" . mysql_real_escape_string($fl3) . "',
'" . mysql_real_escape_string($fr3) . "',
'" . mysql_real_escape_string($to3) . "',
'" . mysql_real_escape_string($dl3) . "',
'" . mysql_real_escape_string($px3) . "',
'" . mysql_real_escape_string($fl4) . "',
'" . mysql_real_escape_string($fr4) . "',
'" . mysql_real_escape_string($to4) . "',
'" . mysql_real_escape_string($dl4) . "',
'" . mysql_real_escape_string($px4) . "',
'" . mysql_real_escape_string($addi) . "',
'" . mysql_real_escape_string($auth1) . "',
'" . mysql_real_escape_string($auth2) . "',)";
//'$problem','$fl1','$fr1','$to1','$dl1','$px1','$fl2','$fr2','$to2','$dl2','$px2','$fl3','$fr3','$to3','$dl3','$px3','$fl4','$fr4','$to4','$dl4','$px4','$addi','$auth1','$auth2','$ip')";
if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());
}
echo " Your Irregularity been stored and send out to your selected distribution list "
?>
$datum = date("d/m/y");
$to = "[email protected]";
$problem = $_POST[problem];
$fl1 = $_POST[fl1];
$fr1 = $_POST[fr1];
$to1 = $_POST[to1];
$dl1 = $_POST[dl1];
$px1 = $_POST[px1];
$fl2 = $_POST[fl2];
$fr2 = $_POST[fr2];
$to2 = $_POST[to2];
$dl2 = $_POST[dl2];
$px2 = $_POST[px2];
$fl3 = $_POST[fl3];
$fr3 = $_POST[fr3];
$to3 = $_POST[to3];
$dl3 = $_POST[dl3];
$px3 = $_POST[px3];
$fl4 = $_POST[fl4];
$fr4 = $_POST[fr4];
$to4 = $_POST[to4];
$dl4 = $_POST[dl4];
$px4 = $_POST[px4];
$addi = $_POST[additional];
$auth1 = $_POST[auth1];
$auth2 = $_POST[auth2];
$ip = $_SERVER[REMOTE_ADDR];
$dbhost = 'xxx';
$dbuser = 'xxx';
$dbpass = 'xxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 's7654sho_report';
mysql_select_db($dbname);
//echo" '$problem','$fl1','$fr1','$to1','$dl1','$px1','$fl2','$fr2','$to2','$dl2','$px2','$fl3','$fr3','$to3','$dl3','$px3','$fl4','$fr4','$to4','$dl4','$px4','$addi','$auth1','$auth2','$ip'";
$sql="INSERT INTO fi( problem1, fl1, fr1, to1, dl1, px1, fl2, fr2, to2, dl2, px2, fl3, fr3, to3, dl3, px3, fl4, fr4, to4, dl4, px4, addi, auth1, auth2, ip)
VALUES(
'" . mysql_real_escape_string($problem) . "',
'" . mysql_real_escape_string($fl1) . "',
'" . mysql_real_escape_string($fr1) . "',
'" . mysql_real_escape_string($to1) . "',
'" . mysql_real_escape_string($dl1) . "',
'" . mysql_real_escape_string($px1) . "',
'" . mysql_real_escape_string($fl2) . "',
'" . mysql_real_escape_string($fr2) . "',
'" . mysql_real_escape_string($to2) . "',
'" . mysql_real_escape_string($dl2) . "',
'" . mysql_real_escape_string($px2) . "',
'" . mysql_real_escape_string($fl3) . "',
'" . mysql_real_escape_string($fr3) . "',
'" . mysql_real_escape_string($to3) . "',
'" . mysql_real_escape_string($dl3) . "',
'" . mysql_real_escape_string($px3) . "',
'" . mysql_real_escape_string($fl4) . "',
'" . mysql_real_escape_string($fr4) . "',
'" . mysql_real_escape_string($to4) . "',
'" . mysql_real_escape_string($dl4) . "',
'" . mysql_real_escape_string($px4) . "',
'" . mysql_real_escape_string($addi) . "',
'" . mysql_real_escape_string($auth1) . "',
'" . mysql_real_escape_string($auth2) . "',)";
//'$problem','$fl1','$fr1','$to1','$dl1','$px1','$fl2','$fr2','$to2','$dl2','$px2','$fl3','$fr3','$to3','$dl3','$px3','$fl4','$fr4','$to4','$dl4','$px4','$addi','$auth1','$auth2','$ip')";
if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());
}
echo " Your Irregularity been stored and send out to your selected distribution list "
?>
Iemand een idee waar het fout loopt? want na uren staren raak ik er maar niet wijzer uit :-(
Gewijzigd op 26/09/2010 15:11:24 door Yannick Bogaert
het is $_POST[''] in plaats van $_POST[]
ze wel goed weergegeven.
Heb toch overal eens de '' bijgezet maar krijg zelfde foutmelding.
Error: 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 26
'" . mysql_real_escape_string($auth2) . "',)";
Nu krijg ik wel nog volgende fout:
Error: Column count doesn't match value count at row 1
Er zit namelijk nog in de tabel een veld record dat de primary index
is en auto_increment. Heb al paar dingen gelezen en blijkbaar moet
je ook dat veld opnemen in de INSERT maar dan met als waarde gewoon ''.
Heb dit geprobeerd maar geen geluk, iemand nog een idee?
die hoef je niet eens te gebruiken, die kan je gewoon uit je query halen
Mis je het 'ip' niet?
Dit moet kloppen:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
# De Query
$qry = "INSERT INTO
fi
(
problem1,
fl1,
fr1,
to1,
dl1,
px1,
fl2,
fr2,
to2,
dl2,
px2,
fl3,
fr3,
to3,
dl3,
px3,
fl4,
fr4,
to4,
dl4,
px4,
addi,
auth1,
auth2,
ip
)
VALUES
(
'".mysql_real_escape_string( $_POST['problem1'] )."',
'".mysql_real_escape_string( $_POST['fl1'] )."',
'".mysql_real_escape_string( $_POST['fr1'] )."',
'".mysql_real_escape_string( $_POST['to1'] )."',
'".mysql_real_escape_string( $_POST['dl1'] )."',
'".mysql_real_escape_string( $_POST['px1'] )."',
'".mysql_real_escape_string( $_POST['fl2'] )."',
'".mysql_real_escape_string( $_POST['fr2'] )."',
'".mysql_real_escape_string( $_POST['to2'] )."',
'".mysql_real_escape_string( $_POST['dl2'] )."',
'".mysql_real_escape_string( $_POST['px2'] )."',
'".mysql_real_escape_string( $_POST['fl3'] )."',
'".mysql_real_escape_string( $_POST['fr3'] )."',
'".mysql_real_escape_string( $_POST['to3'] )."',
'".mysql_real_escape_string( $_POST['dl3'] )."',
'".mysql_real_escape_string( $_POST['px3'] )."',
'".mysql_real_escape_string( $_POST['fl4'] )."',
'".mysql_real_escape_string( $_POST['fr4'] )."',
'".mysql_real_escape_string( $_POST['to4'] )."',
'".mysql_real_escape_string( $_POST['dl4'] )."',
'".mysql_real_escape_string( $_POST['px4'] )."',
'".mysql_real_escape_string( $_POST['addi'] )."',
'".mysql_real_escape_string( $_POST['auth1'] )."',
'".mysql_real_escape_string( $_POST['auth2'] )."',
'".mysql_real_escape_string( $_SERVER['REMOTE_ADDR'] )."'
)";
if( $sql = mysql_query( $qry ) )
{
# Goed
}
else
{
# Fout
}
?>
# De Query
$qry = "INSERT INTO
fi
(
problem1,
fl1,
fr1,
to1,
dl1,
px1,
fl2,
fr2,
to2,
dl2,
px2,
fl3,
fr3,
to3,
dl3,
px3,
fl4,
fr4,
to4,
dl4,
px4,
addi,
auth1,
auth2,
ip
)
VALUES
(
'".mysql_real_escape_string( $_POST['problem1'] )."',
'".mysql_real_escape_string( $_POST['fl1'] )."',
'".mysql_real_escape_string( $_POST['fr1'] )."',
'".mysql_real_escape_string( $_POST['to1'] )."',
'".mysql_real_escape_string( $_POST['dl1'] )."',
'".mysql_real_escape_string( $_POST['px1'] )."',
'".mysql_real_escape_string( $_POST['fl2'] )."',
'".mysql_real_escape_string( $_POST['fr2'] )."',
'".mysql_real_escape_string( $_POST['to2'] )."',
'".mysql_real_escape_string( $_POST['dl2'] )."',
'".mysql_real_escape_string( $_POST['px2'] )."',
'".mysql_real_escape_string( $_POST['fl3'] )."',
'".mysql_real_escape_string( $_POST['fr3'] )."',
'".mysql_real_escape_string( $_POST['to3'] )."',
'".mysql_real_escape_string( $_POST['dl3'] )."',
'".mysql_real_escape_string( $_POST['px3'] )."',
'".mysql_real_escape_string( $_POST['fl4'] )."',
'".mysql_real_escape_string( $_POST['fr4'] )."',
'".mysql_real_escape_string( $_POST['to4'] )."',
'".mysql_real_escape_string( $_POST['dl4'] )."',
'".mysql_real_escape_string( $_POST['px4'] )."',
'".mysql_real_escape_string( $_POST['addi'] )."',
'".mysql_real_escape_string( $_POST['auth1'] )."',
'".mysql_real_escape_string( $_POST['auth2'] )."',
'".mysql_real_escape_string( $_SERVER['REMOTE_ADDR'] )."'
)";
if( $sql = mysql_query( $qry ) )
{
# Goed
}
else
{
# Fout
}
?>
Als je voortaan in een keer je query netjes opbouwt zie je dat veel sneller. Ook maak je onnodig variabelen.
Edit
Santhe was me net voor. En ik twijfel aan je database model, kunnen we daar misschien een kijkje in nemen?
Gewijzigd op 26/09/2010 15:52:07 door Milo S