Krijg geen waarde
Maar op onderstaande manier wil het niet lukken.
Kan iemand mij vertellen hoe ik die waarde er wel in krijg.
Ook krijg ik deze foutmelding te zien, waar ik dus niets van snap.
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /customers/7/1/d/thetimberwolves.nl/httpd.www/site/biggame.php:1) in /customers/7/1/d/thetimberwolves.nl/httpd.www/site/biggame.php on line 10
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* @author Ben Janssen
* @copyright 2012
*/
ini_set('display_errors',1);
error_reporting(E_ALL);
session_start();
//Include
include'../cfg/cfg.php';
mysql_select_db($db,$con);
# sql debug
define('DEBUG_MODE',true); // true == aan, false == uit
# functie voor sql debug
function showSQLError($sql,$error,$text='Error')
{
if (DEBUG_MODE)
{
return '<pre>Error: ' . $error . '<br />' . $sql . '</pre>';
}
else
{
return $text;
}
}
$sql = "SELECT COUNT(*) FROM reservation WHERE speeldatum='2012-10-07'";
if (($result = mysql_query($sql)) === false)
{
echo showSQLError($sql,mysql_error(),'Fout met database.');
}
else
{
$row = mysql_fetch_row($result,$con);
}
if($row == 100)
{
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="../css/content.css"/>
<title>TTW • Big game</title>
</head>
<body>
<p>Het is helaas niet meer mogelijk om te reserveren.</p>
<p>Voor meer info, neem contact op met de beheerder.</p>
<p></p>
</body>
</html>
';
}
else
{
$row2 = 100 - $row;
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="../css/content.css"/>
<title>TTW • Big game</title>
</head>
<body>
<p style="text-align:center">Er zijn nog '.$row2.' plaatsen van de 100 beschikbaar.</p>
<form action="../biggame.php" name="biggame" id="BG1" method="post">
<table style="margin-left:auto;margin-right:auto">
<tr><td style="text-align:left">Naam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="naam" id="BG2"/></td></tr>
<tr><td style="text-align:left">Achternaam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="anaam" id="BG3"/></td></tr>
<tr><td style="text-align:left">Team naam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="team" id="BG4"/></td></tr>
<tr><td style="text-align:left">Email</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="email" id="BG5"/></td></tr>
<tr><td style="text-align:left">Aantal dozen</td><td>:</td><td style="text-align:left">
<select id="BG6" name="dozen">
<option selected="selected" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<select id="BG7" name="paint">
<option selected="selected" value="Shield">Shield</option>
<option value="Claymore">Claymore</option>
<option value="Mace">Mace</option>
</select>
</td></tr>
<tr><td colspan="3">
<img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image"/>
</td></tr>
<tr><td colspan="3">
<input type="text" name="captcha_code" size="10" maxlength="6"/>
<a href="#" onclick="document.getElementById(\'captcha\').src = \'/securimage/securimage_show.php?\' + Math.random(); return false">[ Different Image ]</a></td></tr>
<tr><td style="text-align:center" colspan="3">
<input class="but" type="reset" id="butn_4" value="Reset"/>
<input class="but" type="submit" id="butn_5" value="Verzenden"/>
</td></tr>
</table>
</form>
</body>
</html>
';
}
?>
/**
* @author Ben Janssen
* @copyright 2012
*/
ini_set('display_errors',1);
error_reporting(E_ALL);
session_start();
//Include
include'../cfg/cfg.php';
mysql_select_db($db,$con);
# sql debug
define('DEBUG_MODE',true); // true == aan, false == uit
# functie voor sql debug
function showSQLError($sql,$error,$text='Error')
{
if (DEBUG_MODE)
{
return '<pre>Error: ' . $error . '<br />' . $sql . '</pre>';
}
else
{
return $text;
}
}
$sql = "SELECT COUNT(*) FROM reservation WHERE speeldatum='2012-10-07'";
if (($result = mysql_query($sql)) === false)
{
echo showSQLError($sql,mysql_error(),'Fout met database.');
}
else
{
$row = mysql_fetch_row($result,$con);
}
if($row == 100)
{
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="../css/content.css"/>
<title>TTW • Big game</title>
</head>
<body>
<p>Het is helaas niet meer mogelijk om te reserveren.</p>
<p>Voor meer info, neem contact op met de beheerder.</p>
<p></p>
</body>
</html>
';
}
else
{
$row2 = 100 - $row;
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="../css/content.css"/>
<title>TTW • Big game</title>
</head>
<body>
<p style="text-align:center">Er zijn nog '.$row2.' plaatsen van de 100 beschikbaar.</p>
<form action="../biggame.php" name="biggame" id="BG1" method="post">
<table style="margin-left:auto;margin-right:auto">
<tr><td style="text-align:left">Naam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="naam" id="BG2"/></td></tr>
<tr><td style="text-align:left">Achternaam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="anaam" id="BG3"/></td></tr>
<tr><td style="text-align:left">Team naam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="team" id="BG4"/></td></tr>
<tr><td style="text-align:left">Email</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="email" id="BG5"/></td></tr>
<tr><td style="text-align:left">Aantal dozen</td><td>:</td><td style="text-align:left">
<select id="BG6" name="dozen">
<option selected="selected" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<select id="BG7" name="paint">
<option selected="selected" value="Shield">Shield</option>
<option value="Claymore">Claymore</option>
<option value="Mace">Mace</option>
</select>
</td></tr>
<tr><td colspan="3">
<img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image"/>
</td></tr>
<tr><td colspan="3">
<input type="text" name="captcha_code" size="10" maxlength="6"/>
<a href="#" onclick="document.getElementById(\'captcha\').src = \'/securimage/securimage_show.php?\' + Math.random(); return false">[ Different Image ]</a></td></tr>
<tr><td style="text-align:center" colspan="3">
<input class="but" type="reset" id="butn_4" value="Reset"/>
<input class="but" type="submit" id="butn_5" value="Verzenden"/>
</td></tr>
</table>
</form>
</body>
</html>
';
}
?>
Gewijzigd op 22/08/2012 10:16:44 door Ben Janssen
Staat er geen witregel voor je phpscript?
Haal je mailadres even uit de code, om te voorkomen dat je mogelijk allerlei 'aanbiedingen' krijgt ;-)
Zo haal je alleen de datum uit het veld op en werkt de vergelijking wel.
Daarnaast fetch je de regel wel, maar check je of de hele array met resultaten die je ophaalt gelijk is aan 100:
Dat werkt dus ook niet, want een array is nooit gelijk aan 100. Wat je wilt doen is de juiste kolom vergelijken met 100. In jouw geval is de juiste kolom COUNT(*), omdat je geen alias meegeeft. Advies: geef wel een alias op dat is iets makkelijker:
De vergelijking wordt dan:
Warning: mysql_fetch_row() expects parameter 2 to be long, resource given in /customers/7/1/d/thetimberwolves.nl/httpd.www/site/biggame.php on line 36
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* @author Ben Janssen
* @copyright 2012
*/
ini_set('display_errors',1);
error_reporting(E_ALL);
//Include
include'../cfg/cfg.php';
mysql_select_db($db,$con);
# sql debug
define('DEBUG_MODE',true); // true == aan, false == uit
# functie voor sql debug
function showSQLError($sql,$error,$text='Error')
{
if (DEBUG_MODE)
{
return '<pre>Error: ' . $error . '<br />' . $sql . '</pre>';
}
else
{
return $text;
}
}
$sql = "SELECT COUNT(*) AS total FROM reservation WHERE DATE(speeldatum)='2012-10-07'";
if (($result = mysql_query($sql)) === false)
{
echo showSQLError($sql,mysql_error(),'Fout met database.');
}
else
{
$row = mysql_fetch_row($result,$con);
}
if($row['total'] == 100)
{
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="../css/content.css"/>
<title>TTW • Big game</title>
</head>
<body>
<p>Het is helaas niet meer mogelijk om te reserveren.</p>
<p>Voor meer info, neem contact op met de beheerder.</p>
<p></p>
</body>
</html>
';
}
else
{
$row2 = 100 - $row['total'];
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="../css/content.css"/>
<title>TTW • Big game</title>
</head>
<body>
<p style="text-align:center">Er zijn nog '.$row2.' plaatsen van de 100 beschikbaar.</p>
<form action="../biggame.php" name="biggame" id="BG1" method="post">
<table style="margin-left:auto;margin-right:auto">
<tr><td style="text-align:left">Naam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="naam" id="BG2"/></td></tr>
<tr><td style="text-align:left">Achternaam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="anaam" id="BG3"/></td></tr>
<tr><td style="text-align:left">Team naam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="team" id="BG4"/></td></tr>
<tr><td style="text-align:left">Email</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="email" id="BG5"/></td></tr>
<tr><td style="text-align:left">Aantal dozen</td><td>:</td><td style="text-align:left">
<select id="BG6" name="dozen">
<option selected="selected" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<select id="BG7" name="paint">
<option selected="selected" value="Shield">Shield</option>
<option value="Claymore">Claymore</option>
<option value="Mace">Mace</option>
</select>
</td></tr>
<tr><td colspan="3">
<img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image"/>
</td></tr>
<tr><td colspan="3">
<input type="text" name="captcha_code" size="10" maxlength="6"/>
<a href="#" onclick="document.getElementById(\'captcha\').src = \'/securimage/securimage_show.php?\' + Math.random(); return false">[ Different Image ]</a></td></tr>
<tr><td style="text-align:center" colspan="3">
<input class="but" type="reset" id="butn_4" value="Reset"/>
<input class="but" type="submit" id="butn_5" value="Verzenden"/>
</td></tr>
</table>
</form>
</body>
</html>
';
}
?>
/**
* @author Ben Janssen
* @copyright 2012
*/
ini_set('display_errors',1);
error_reporting(E_ALL);
//Include
include'../cfg/cfg.php';
mysql_select_db($db,$con);
# sql debug
define('DEBUG_MODE',true); // true == aan, false == uit
# functie voor sql debug
function showSQLError($sql,$error,$text='Error')
{
if (DEBUG_MODE)
{
return '<pre>Error: ' . $error . '<br />' . $sql . '</pre>';
}
else
{
return $text;
}
}
$sql = "SELECT COUNT(*) AS total FROM reservation WHERE DATE(speeldatum)='2012-10-07'";
if (($result = mysql_query($sql)) === false)
{
echo showSQLError($sql,mysql_error(),'Fout met database.');
}
else
{
$row = mysql_fetch_row($result,$con);
}
if($row['total'] == 100)
{
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="../css/content.css"/>
<title>TTW • Big game</title>
</head>
<body>
<p>Het is helaas niet meer mogelijk om te reserveren.</p>
<p>Voor meer info, neem contact op met de beheerder.</p>
<p></p>
</body>
</html>
';
}
else
{
$row2 = 100 - $row['total'];
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="../css/content.css"/>
<title>TTW • Big game</title>
</head>
<body>
<p style="text-align:center">Er zijn nog '.$row2.' plaatsen van de 100 beschikbaar.</p>
<form action="../biggame.php" name="biggame" id="BG1" method="post">
<table style="margin-left:auto;margin-right:auto">
<tr><td style="text-align:left">Naam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="naam" id="BG2"/></td></tr>
<tr><td style="text-align:left">Achternaam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="anaam" id="BG3"/></td></tr>
<tr><td style="text-align:left">Team naam</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="team" id="BG4"/></td></tr>
<tr><td style="text-align:left">Email</td><td>:</td><td style="text-align:left"><input class="mssg2" type="text" name="email" id="BG5"/></td></tr>
<tr><td style="text-align:left">Aantal dozen</td><td>:</td><td style="text-align:left">
<select id="BG6" name="dozen">
<option selected="selected" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<select id="BG7" name="paint">
<option selected="selected" value="Shield">Shield</option>
<option value="Claymore">Claymore</option>
<option value="Mace">Mace</option>
</select>
</td></tr>
<tr><td colspan="3">
<img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image"/>
</td></tr>
<tr><td colspan="3">
<input type="text" name="captcha_code" size="10" maxlength="6"/>
<a href="#" onclick="document.getElementById(\'captcha\').src = \'/securimage/securimage_show.php?\' + Math.random(); return false">[ Different Image ]</a></td></tr>
<tr><td style="text-align:center" colspan="3">
<input class="but" type="reset" id="butn_4" value="Reset"/>
<input class="but" type="submit" id="butn_5" value="Verzenden"/>
</td></tr>
</table>
</form>
</body>
</html>
';
}
?>
mysql_fetch_row($result);
Notice: Undefined index: total in /customers/7/1/d/thetimberwolves.nl/httpd.www/site/biggame.php on line 38 Notice: Undefined index: total in /customers/7/1/d/thetimberwolves.nl/httpd.www/site/biggame.php on line 63
mysql_fetch_row geeft het resultaat in een array terug met numerieke keys, mysql_fetch_assoc geeft het terug met associatieve keys (dus met de namen van de geselecteerde kolommen). Over het algemeen is de tweede een stuk eenvoudiger, want dan hoef je zelf niet te gaan zitten tellen welk kolom nummer je moet hebben.
Dank je Erwin.