php tutorial
Mijn probleem is namelijk als ik zelf op youtube filmpje kijk krijg ik altijd nog foutmeldingen en het voorbeeld niet.
Alvast bedankt
Zijn die niet op te lossen?
Ik gok op Notice-meldingen?
Ik gok op "Depricated" meldingen.
Met name dat laatste: als je een overtikfout maakt ligt je applicatie vaak in puin en men weet zich geen raad met de foutmeldingen. Dit komt weer omdat beginnende hobbyisten zich nooit aangeleerd hebben om zo te ontwikkelen.
Het is overigens "deprecated".
Codeacademy kan je de basis leren.
Op 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
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
<?php
include("connection.php");
$chkbox = array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
if(isset($_POST['btnsave']))
{ $fruit = $_POST['fruit'];
$values = array();
foreach($collection as $selection )
{ if(in_array($selection, $fruit))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
} // end of foreach.
// MySQL statement.
$insert = "INSERT INTO table_location (orange, apple, grapefruit, banana, watermelon)
VALUES ({$values['orange']}, {$values['apple']}, {$values['grapefruit']}, {$values['banana']}, {$values['watermelon']})";
// MySQL statement to execute the INSERT statement above.
mysqli_query($dbconnect, $insert) or die('<br/>Error reading database: '.mysqli_error($dbconnect));
mysqli_close($dbconnect);
} // End of, if statement from the button check
?>
<html>
<head>
<title>Checkbox</title>
<head>
<title>HTML Checkbox</title>
</head>
<body>
<h2> Pick your most favorite fruits: </h2>
<form name="fruitcheckbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="fruit[Orange]" value="orange"> Orange
<input type="checkbox" name="fruit[Apple]" value="apple"> Apple
<input type="checkbox" name="fruit[Grapefruit]" value="grapefruit"> Grapefruit
<input type="checkbox" name="fruit[Banana]" value="banana"> Banana
<input type="checkbox" name="fruit[Watermelon]" value="watermelon"> Watermelon
<br>
<input type="submit" value="Save" name="btnsave">
</form>
</body>
</html>
include("connection.php");
$chkbox = array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
if(isset($_POST['btnsave']))
{ $fruit = $_POST['fruit'];
$values = array();
foreach($collection as $selection )
{ if(in_array($selection, $fruit))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
} // end of foreach.
// MySQL statement.
$insert = "INSERT INTO table_location (orange, apple, grapefruit, banana, watermelon)
VALUES ({$values['orange']}, {$values['apple']}, {$values['grapefruit']}, {$values['banana']}, {$values['watermelon']})";
// MySQL statement to execute the INSERT statement above.
mysqli_query($dbconnect, $insert) or die('<br/>Error reading database: '.mysqli_error($dbconnect));
mysqli_close($dbconnect);
} // End of, if statement from the button check
?>
<html>
<head>
<title>Checkbox</title>
<head>
<title>HTML Checkbox</title>
</head>
<body>
<h2> Pick your most favorite fruits: </h2>
<form name="fruitcheckbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="fruit[Orange]" value="orange"> Orange
<input type="checkbox" name="fruit[Apple]" value="apple"> Apple
<input type="checkbox" name="fruit[Grapefruit]" value="grapefruit"> Grapefruit
<input type="checkbox" name="fruit[Banana]" value="banana"> Banana
<input type="checkbox" name="fruit[Watermelon]" value="watermelon"> Watermelon
<br>
<input type="submit" value="Save" name="btnsave">
</form>
</body>
</html>
Gewijzigd op 30/10/2015 22:10:23 door - Ariën -
Welke fouten zie je? En kan je de code tussen code-tags plaatsen?
- Ariën - op 30/10/2015 21:49:17:
Welke fouten zie je? En kan je de code tussen code-tags plaatsen?
Notice: Undefined variable: collection on line 8
Warning: Invalid argument supplied for foreach() on line 8
Notice: Undefined index: orange
Notice: Undefined index: apple on line 17
Notice: Undefined index: grapefruiton line 17
Notice: Undefined index: banana on line 17
Notice: Undefined index: watermelon on line 17
Notice: Undefined variable: dbconnect on line 19
Warning: mysqli_query() expects parameter 1 to be mysqli, null given on line 19
Notice: Undefined variable: dbconnect on line 19
Warning: mysqli_error() expects parameter 1 to be mysqli, null given on line 19
Marcel Groot op 30/10/2015 22:03:32:
Notice: Undefined variable: collection on line 8
Warning: Invalid argument supplied for foreach() on line 8
Warning: Invalid argument supplied for foreach() on line 8
Deze variabele komt nergens vandaan, je array heet $chkbox wat niet echt een logische naam is. Daarom gaat de foreach() ook onderuit.
Quote:
Notice: Undefined index: orange
Notice: Undefined index: apple on line 17
Notice: Undefined index: grapefruiton line 17
Notice: Undefined index: banana on line 17
Notice: Undefined index: watermelon on line 17
Notice: Undefined index: orange
Notice: Undefined index: apple on line 17
Notice: Undefined index: grapefruiton line 17
Notice: Undefined index: banana on line 17
Notice: Undefined index: watermelon on line 17
De variabelen $values['orange'] zijn leeg. Kettingreactie op je foreach-probleem dus.
Quote:
Notice: Undefined variable: dbconnect on line 19
$dbconnect is nergens gedefineerd. Hoe ziet je connectie eruit?......
Quote:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given on line 19
Notice: Undefined variable: dbconnect on line 19
Warning: mysqli_error() expects parameter 1 to be mysqli, null given on line 19
Notice: Undefined variable: dbconnect on line 19
Warning: mysqli_error() expects parameter 1 to be mysqli, null given on line 19
En daaropvolgend komt je mysqli_query uit op NULL omdat er geen connectie is.
Gewijzigd op 30/10/2015 22:41:05 door - Ariën -
Hoe zou ik dat dan moeten verbeteren?
Hernoem je array naar $collection, en je bent al een stap verder.
- Ariën - op 31/10/2015 18:17:16:
Hernoem je array naar $collection, en je bent al een stap verder.
Notice: Undefined variable: collection on line 7
zo dus.
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
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
<?php
include("connection.php");
$collection= array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
$fruit = array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
if(isset($_POST['btnsave']))
{ $fruit = $_POST['fruit'];
$values = array($collection);
foreach($collection as $selection )
{ if(in_array($selection, $fruit))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
} // end of foreach.
// MySQL statement.
$insert = "INSERT INTO table_location (orange, apple, grapefruit, banana, watermelon)
VALUES ({$values['orange']}, {$values['apple']}, {$values['grapefruit']}, {$values['banana']}, {$values['watermelon']})";
// MySQL statement to execute the INSERT statement above.
mysqli_query($dbconnect, $insert) or die('<br/>Error reading database: '.mysqli_error($dbconnect));
mysqli_close($dbconnect);
} // End of, if statement from the button check
?>
<html>
<head>
<title>Checkbox</title>
<head>
<title>HTML Checkbox</title>
</head>
<body>
<h2> Pick your most favorite fruits: </h2>
<form name="fruitcheckbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="fruit[Orange]" value="orange"> Orange
<input type="checkbox" name="fruit[Apple]" value="apple"> Apple
<input type="checkbox" name="fruit[Grapefruit]" value="grapefruit"> Grapefruit
<input type="checkbox" name="fruit[Banana]" value="banana"> Banana
<input type="checkbox" name="fruit[Watermelon]" value="watermelon"> Watermelon
<br>
<input type="submit" value="Save" name="btnsave">
</form>
</body>
</html>
<?php
$dbhost = 'localhost';
$dbname = '';
$dbuser = '';
$dbpass = '';
$dbconnect = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $dbconnect);
?>
include("connection.php");
$collection= array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
$fruit = array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
if(isset($_POST['btnsave']))
{ $fruit = $_POST['fruit'];
$values = array($collection);
foreach($collection as $selection )
{ if(in_array($selection, $fruit))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
} // end of foreach.
// MySQL statement.
$insert = "INSERT INTO table_location (orange, apple, grapefruit, banana, watermelon)
VALUES ({$values['orange']}, {$values['apple']}, {$values['grapefruit']}, {$values['banana']}, {$values['watermelon']})";
// MySQL statement to execute the INSERT statement above.
mysqli_query($dbconnect, $insert) or die('<br/>Error reading database: '.mysqli_error($dbconnect));
mysqli_close($dbconnect);
} // End of, if statement from the button check
?>
<html>
<head>
<title>Checkbox</title>
<head>
<title>HTML Checkbox</title>
</head>
<body>
<h2> Pick your most favorite fruits: </h2>
<form name="fruitcheckbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="fruit[Orange]" value="orange"> Orange
<input type="checkbox" name="fruit[Apple]" value="apple"> Apple
<input type="checkbox" name="fruit[Grapefruit]" value="grapefruit"> Grapefruit
<input type="checkbox" name="fruit[Banana]" value="banana"> Banana
<input type="checkbox" name="fruit[Watermelon]" value="watermelon"> Watermelon
<br>
<input type="submit" value="Save" name="btnsave">
</form>
</body>
</html>
<?php
$dbhost = 'localhost';
$dbname = '';
$dbuser = '';
$dbpass = '';
$dbconnect = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $dbconnect);
?>
Warning: mysqli_query() expects parameter 1 to be mysqli, resource given on line 19 Warning:
mysqli_error() expects parameter 1 to be mysqli, resource given on line 19
- Ariën -:
Gelieve in het vervolg bij code de [code][/code]-tags gebruiken.
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Gewijzigd op 31/10/2015 19:05:34 door - Ariën -
Wat staat er in $dbconnect?
- Ariën - op 31/10/2015 19:07:29:
Wat staat er in $dbconnect?
mysql_connect($dbhost, $dbuser, $dbpass);
Ik heb overal de i weg gehaald en mysql van gemaakt.
Dus beter pas je gewoon de connectie aan naar MySQLi.