Mijn formulier (bestellijst) werkt niet meer
2 jaar geleden heb ik een formulier (bestellijst-achtig) gemaakt in PHP waarmee ik data kan opslaan en opvragen uit een database. Het formulier gebruikte ik als boodschappenlijst, waarbij ik gebruik maak van vastgelegde "artikelen" waarvoor ik een aantal moet invullen. Het heeft altijd prima gewerkt.
Nu wil ik de lijst weer gaan gebruiken maar ik zie dat deze niet meer werkt. Waarschijnlijk heeft het met de nieuwe PHP7.0 versie te maken.
Het probleem is dat er wel connectie gemaakt wordt, maar het scherm blijft blanco. Zou iemand mij kunnen helpen?
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
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
<?php
$host="localhost";
$username="root";
$password="";
$db_name="app";
$tbl_name="list";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select database");
if ("POST" === $_SERVER['REQUEST_METHOD']) {
foreach( $_POST["id"] AS $id ) {
$item = mysql_real_escape_string($_POST["item"][$id]);
$class = mysql_real_escape_string($_POST["class"][$id]);
$unity = mysql_real_escape_string($_POST["unity"][$id]);
$qty = mysql_real_escape_string($_POST["qty"][$id]);
$memo = mysql_real_escape_string($_POST["memo"][$id]);
$update = "UPDATE $tbl_name SET `item` = '$item', `class` = '$class', `qty` = '$qty', `unity` = '$unity', `memo` = '$memo' WHERE `id` = $id";
mysql_query($update) or die( mysql_error());
}
}
$sql = "SELECT * FROM $tbl_name order by
case
when class = 'Fruit' then 10
when class = 'Aardappelen' then 20
when class = 'Groenten' then 30
else 9999
end,
case
when qty = 0 then 0
when qty = null then 0
else 1
end DESC,
item,
id" ;
$res = mysql_query( $sql ) or die( mysql_error() );
if ( mysql_num_rows( $res ) > 0 ) {
echo '<div class="headertext" id="headertext">Lijst</div><p>'."\n";
echo '<form name="form1" id="form1" method="post">';
while ( $row = mysql_fetch_assoc( $res ) ) {
if ( $row["qty"] == '0' ) {
$class = 'form-control-inactief';
}
else {
$class = 'form-control-actief';
}
echo ' <div id="' . $class . '">' ."\n";
echo ' <input type="text" min="0" class=" ' . $class . '" name="qty[' . $row["id"] . ']" placeholder="<aantal>" value="'.$row["qty"].'" size="4">'."\n";
echo ' <select class="' . $class . '" name="unity[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['unity'] == '' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Stuks"'. ($row['unity'] == 'Stuks' ? ' selected="selected"' : '') .'>Stuks</option>'."\n";
echo ' <option value="Set"'. ($row['unity'] == 'Set' ? ' selected="selected"' : '') .'>Set</option>'."\n";
echo ' <option value="Gram"'. ($row['unity'] == 'Gram' ? ' selected="selected"' : '') .'>Gram</option>'."\n";
echo ' <option value="Pak"'. ($row['unity'] == 'Pak' ? ' selected="selected"' : '') .'>Pak</option>'."\n";
echo ' <option value="Fles"'. ($row['unity'] == 'Fles' ? ' selected="selected"' : '') .'>Fles</option>'."\n";
echo ' <option value="Krat"'. ($row['unity'] == 'Krat' ? ' selected="selected"' : '') .'>Krat</option>'."\n";
echo ' <option value="Zak"'. ($row['unity'] == 'Zak' ? ' selected="selected"' : '') .'>Zak</option>'."\n";
echo ' <option value="Bak"'. ($row['unity'] == 'Bak' ? ' selected="selected"' : '') .'>Bak</option>'."\n";
echo ' <option value="Pot"'. ($row['unity'] == 'Pot' ? ' selected="selected"' : '') .'>Pot</option>'."\n";
echo ' </select>'."\n";
echo ' <input type="text" class="' . $class . '_bold" name="item[' . $row["id"] . ']" placeholder="<item>" value="'.$row["item"].'" size="20">'."\n";
echo ' <input type="text" class="' . $class . '" name="memo[' . $row["id"] . ']" placeholder="<memo>" value="'.$row["memo"].'" size="10">'."\n";
echo ' <select class="' . $class . '" name="class[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['class'] == 'ZZZZZZZZZ' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Fruit"'. ($row['class'] == 'Fruit' ? ' selected="selected"' : '') .'>Fruit</option>'."\n";
echo ' <option value="Aardappelen"'. ($row['class'] == 'Aardappelen' ? ' selected="selected"' : '') .'>Aardappelen</option>'."\n";
echo ' <option value="Groenten"'. ($row['class'] == 'Groenten' ? ' selected="selected"' : '') .'>Groenten</option>'."\n";
echo ' </select>'."\n";
echo '<input type="hidden" name="id[]" value="' . $row["id"] . '"> ' . "\n";
}
echo '<br>'. "\n";
echo '<input type="submit" size=40 name="submit" value="Bewaren">' . "\n";
echo '</div>' . "\n";
}
?>
$host="localhost";
$username="root";
$password="";
$db_name="app";
$tbl_name="list";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select database");
if ("POST" === $_SERVER['REQUEST_METHOD']) {
foreach( $_POST["id"] AS $id ) {
$item = mysql_real_escape_string($_POST["item"][$id]);
$class = mysql_real_escape_string($_POST["class"][$id]);
$unity = mysql_real_escape_string($_POST["unity"][$id]);
$qty = mysql_real_escape_string($_POST["qty"][$id]);
$memo = mysql_real_escape_string($_POST["memo"][$id]);
$update = "UPDATE $tbl_name SET `item` = '$item', `class` = '$class', `qty` = '$qty', `unity` = '$unity', `memo` = '$memo' WHERE `id` = $id";
mysql_query($update) or die( mysql_error());
}
}
$sql = "SELECT * FROM $tbl_name order by
case
when class = 'Fruit' then 10
when class = 'Aardappelen' then 20
when class = 'Groenten' then 30
else 9999
end,
case
when qty = 0 then 0
when qty = null then 0
else 1
end DESC,
item,
id" ;
$res = mysql_query( $sql ) or die( mysql_error() );
if ( mysql_num_rows( $res ) > 0 ) {
echo '<div class="headertext" id="headertext">Lijst</div><p>'."\n";
echo '<form name="form1" id="form1" method="post">';
while ( $row = mysql_fetch_assoc( $res ) ) {
if ( $row["qty"] == '0' ) {
$class = 'form-control-inactief';
}
else {
$class = 'form-control-actief';
}
echo ' <div id="' . $class . '">' ."\n";
echo ' <input type="text" min="0" class=" ' . $class . '" name="qty[' . $row["id"] . ']" placeholder="<aantal>" value="'.$row["qty"].'" size="4">'."\n";
echo ' <select class="' . $class . '" name="unity[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['unity'] == '' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Stuks"'. ($row['unity'] == 'Stuks' ? ' selected="selected"' : '') .'>Stuks</option>'."\n";
echo ' <option value="Set"'. ($row['unity'] == 'Set' ? ' selected="selected"' : '') .'>Set</option>'."\n";
echo ' <option value="Gram"'. ($row['unity'] == 'Gram' ? ' selected="selected"' : '') .'>Gram</option>'."\n";
echo ' <option value="Pak"'. ($row['unity'] == 'Pak' ? ' selected="selected"' : '') .'>Pak</option>'."\n";
echo ' <option value="Fles"'. ($row['unity'] == 'Fles' ? ' selected="selected"' : '') .'>Fles</option>'."\n";
echo ' <option value="Krat"'. ($row['unity'] == 'Krat' ? ' selected="selected"' : '') .'>Krat</option>'."\n";
echo ' <option value="Zak"'. ($row['unity'] == 'Zak' ? ' selected="selected"' : '') .'>Zak</option>'."\n";
echo ' <option value="Bak"'. ($row['unity'] == 'Bak' ? ' selected="selected"' : '') .'>Bak</option>'."\n";
echo ' <option value="Pot"'. ($row['unity'] == 'Pot' ? ' selected="selected"' : '') .'>Pot</option>'."\n";
echo ' </select>'."\n";
echo ' <input type="text" class="' . $class . '_bold" name="item[' . $row["id"] . ']" placeholder="<item>" value="'.$row["item"].'" size="20">'."\n";
echo ' <input type="text" class="' . $class . '" name="memo[' . $row["id"] . ']" placeholder="<memo>" value="'.$row["memo"].'" size="10">'."\n";
echo ' <select class="' . $class . '" name="class[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['class'] == 'ZZZZZZZZZ' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Fruit"'. ($row['class'] == 'Fruit' ? ' selected="selected"' : '') .'>Fruit</option>'."\n";
echo ' <option value="Aardappelen"'. ($row['class'] == 'Aardappelen' ? ' selected="selected"' : '') .'>Aardappelen</option>'."\n";
echo ' <option value="Groenten"'. ($row['class'] == 'Groenten' ? ' selected="selected"' : '') .'>Groenten</option>'."\n";
echo ' </select>'."\n";
echo '<input type="hidden" name="id[]" value="' . $row["id"] . '"> ' . "\n";
}
echo '<br>'. "\n";
echo '<input type="submit" size=40 name="submit" value="Bewaren">' . "\n";
echo '</div>' . "\n";
}
?>
Als je zeker weet dat je PHP7 draait, dan is het antwoord vrij simpel:
http://www.php.net/mysql_connect
Quote:
Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_connect()
PDO::__construct()
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_connect()
PDO::__construct()
Dit is overigens voor alle mysql_* functies.
Begrijp ik het goed dat ik gewoon zoek-en-vervang kan doen: "mysql" -> "mysqli"?
Of zit er meer aan vast?
Code (php)
1
2
3
4
2
3
4
<?php
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select database");
?>
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select database");
?>
Een or die is niet echt een nette manier voor foutafhandeling. Het script wordt letterlijk afgekapt met de functie.
Wellicht handig om ook gelijk met prepared statements te gaan werken?
Tevens doe je een select *:
Het is verstandiger om dit te beperken tot enkel de kolommen die je nodig hebt. Ook al heb je alles nodig, is het netter om alles los op te halen. Mocht je later dingen wijzigen kan dit fouten voorkomen.
Gewijzigd op 23/08/2017 11:34:43 door Peter K
Zie hieronder mijn code.
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
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
<?php
$host="localhost";
$username="root";
$password="";
$db_name="app";
$tbl_name="list";
#mysqli_connect("$host", "$username", "$password")or die("cannot connect");
#mysqli_select_db("$db_name")or die("cannot select database");
$mysqli = new mysqli("$host", "$username", "$password", "$db_name");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if ("POST" === $_SERVER['REQUEST_METHOD']) {
foreach( $_POST["id"] AS $id ) {
$item = mysqli_real_escape_string($_POST["item"][$id]);
$class = mysqli_real_escape_string($_POST["class"][$id]);
$unity = mysqli_real_escape_string($_POST["unity"][$id]);
$qty = mysqli_real_escape_string($_POST["qty"][$id]);
$memo = mysqli_real_escape_string($_POST["memo"][$id]);
$update = "UPDATE $tbl_name SET `item` = '$item', `class` = '$class', `qty` = '$qty', `unity` = '$unity', `memo` = '$memo' WHERE `id` = $id";
mysqli_query($update) or die( mysqli_error());
}
}
$sql = "SELECT * FROM $tbl_name order by
case
when class = 'Fruit' then 10
when class = 'Aardappelen' then 20
when class = 'Groenten' then 30
else 9999
end,
case
when qty = 0 then 0
when qty = null then 0
else 1
end DESC,
item,
id" ;
$res = mysqli_query( $sql ) or die( mysqli_error() );
if ( mysqli_num_rows( $res ) > 0 ) {
echo '<div class="headertext" id="headertext">Lijst</div><p>'."\n";
echo '<form name="form1" id="form1" method="post">';
while ( $row = mysqli_fetch_assoc( $res ) ) {
if ( $row["qty"] == '0' ) {
$class = 'form-control-inactief';
}
else {
$class = 'form-control-actief';
}
echo ' <div id="' . $class . '">' ."\n";
echo ' <input type="text" min="0" class=" ' . $class . '" name="qty[' . $row["id"] . ']" placeholder="<aantal>" value="'.$row["qty"].'" size="4">'."\n";
echo ' <select class="' . $class . '" name="unity[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['unity'] == '' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Stuks"'. ($row['unity'] == 'Stuks' ? ' selected="selected"' : '') .'>Stuks</option>'."\n";
echo ' <option value="Set"'. ($row['unity'] == 'Set' ? ' selected="selected"' : '') .'>Set</option>'."\n";
echo ' <option value="Gram"'. ($row['unity'] == 'Gram' ? ' selected="selected"' : '') .'>Gram</option>'."\n";
echo ' <option value="Pak"'. ($row['unity'] == 'Pak' ? ' selected="selected"' : '') .'>Pak</option>'."\n";
echo ' <option value="Fles"'. ($row['unity'] == 'Fles' ? ' selected="selected"' : '') .'>Fles</option>'."\n";
echo ' <option value="Krat"'. ($row['unity'] == 'Krat' ? ' selected="selected"' : '') .'>Krat</option>'."\n";
echo ' <option value="Zak"'. ($row['unity'] == 'Zak' ? ' selected="selected"' : '') .'>Zak</option>'."\n";
echo ' <option value="Bak"'. ($row['unity'] == 'Bak' ? ' selected="selected"' : '') .'>Bak</option>'."\n";
echo ' <option value="Pot"'. ($row['unity'] == 'Pot' ? ' selected="selected"' : '') .'>Pot</option>'."\n";
echo ' </select>'."\n";
echo ' <input type="text" class="' . $class . '_bold" name="item[' . $row["id"] . ']" placeholder="<item>" value="'.$row["item"].'" size="20">'."\n";
echo ' <input type="text" class="' . $class . '" name="memo[' . $row["id"] . ']" placeholder="<memo>" value="'.$row["memo"].'" size="10">'."\n";
echo ' <select class="' . $class . '" name="class[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['class'] == 'ZZZZZZZZZ' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Fruit"'. ($row['class'] == 'Fruit' ? ' selected="selected"' : '') .'>Fruit</option>'."\n";
echo ' <option value="Aardappelen"'. ($row['class'] == 'Aardappelen' ? ' selected="selected"' : '') .'>Aardappelen</option>'."\n";
echo ' <option value="Groenten"'. ($row['class'] == 'Groenten' ? ' selected="selected"' : '') .'>Groenten</option>'."\n";
echo ' </select>'."\n";
echo '<input type="hidden" name="id[]" value="' . $row["id"] . '"> ' . "\n";
}
echo '<br>'. "\n";
echo '<input type="submit" size=40 name="submit" value="Bewaren">' . "\n";
echo '</div>' . "\n";
}
?>
$host="localhost";
$username="root";
$password="";
$db_name="app";
$tbl_name="list";
#mysqli_connect("$host", "$username", "$password")or die("cannot connect");
#mysqli_select_db("$db_name")or die("cannot select database");
$mysqli = new mysqli("$host", "$username", "$password", "$db_name");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if ("POST" === $_SERVER['REQUEST_METHOD']) {
foreach( $_POST["id"] AS $id ) {
$item = mysqli_real_escape_string($_POST["item"][$id]);
$class = mysqli_real_escape_string($_POST["class"][$id]);
$unity = mysqli_real_escape_string($_POST["unity"][$id]);
$qty = mysqli_real_escape_string($_POST["qty"][$id]);
$memo = mysqli_real_escape_string($_POST["memo"][$id]);
$update = "UPDATE $tbl_name SET `item` = '$item', `class` = '$class', `qty` = '$qty', `unity` = '$unity', `memo` = '$memo' WHERE `id` = $id";
mysqli_query($update) or die( mysqli_error());
}
}
$sql = "SELECT * FROM $tbl_name order by
case
when class = 'Fruit' then 10
when class = 'Aardappelen' then 20
when class = 'Groenten' then 30
else 9999
end,
case
when qty = 0 then 0
when qty = null then 0
else 1
end DESC,
item,
id" ;
$res = mysqli_query( $sql ) or die( mysqli_error() );
if ( mysqli_num_rows( $res ) > 0 ) {
echo '<div class="headertext" id="headertext">Lijst</div><p>'."\n";
echo '<form name="form1" id="form1" method="post">';
while ( $row = mysqli_fetch_assoc( $res ) ) {
if ( $row["qty"] == '0' ) {
$class = 'form-control-inactief';
}
else {
$class = 'form-control-actief';
}
echo ' <div id="' . $class . '">' ."\n";
echo ' <input type="text" min="0" class=" ' . $class . '" name="qty[' . $row["id"] . ']" placeholder="<aantal>" value="'.$row["qty"].'" size="4">'."\n";
echo ' <select class="' . $class . '" name="unity[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['unity'] == '' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Stuks"'. ($row['unity'] == 'Stuks' ? ' selected="selected"' : '') .'>Stuks</option>'."\n";
echo ' <option value="Set"'. ($row['unity'] == 'Set' ? ' selected="selected"' : '') .'>Set</option>'."\n";
echo ' <option value="Gram"'. ($row['unity'] == 'Gram' ? ' selected="selected"' : '') .'>Gram</option>'."\n";
echo ' <option value="Pak"'. ($row['unity'] == 'Pak' ? ' selected="selected"' : '') .'>Pak</option>'."\n";
echo ' <option value="Fles"'. ($row['unity'] == 'Fles' ? ' selected="selected"' : '') .'>Fles</option>'."\n";
echo ' <option value="Krat"'. ($row['unity'] == 'Krat' ? ' selected="selected"' : '') .'>Krat</option>'."\n";
echo ' <option value="Zak"'. ($row['unity'] == 'Zak' ? ' selected="selected"' : '') .'>Zak</option>'."\n";
echo ' <option value="Bak"'. ($row['unity'] == 'Bak' ? ' selected="selected"' : '') .'>Bak</option>'."\n";
echo ' <option value="Pot"'. ($row['unity'] == 'Pot' ? ' selected="selected"' : '') .'>Pot</option>'."\n";
echo ' </select>'."\n";
echo ' <input type="text" class="' . $class . '_bold" name="item[' . $row["id"] . ']" placeholder="<item>" value="'.$row["item"].'" size="20">'."\n";
echo ' <input type="text" class="' . $class . '" name="memo[' . $row["id"] . ']" placeholder="<memo>" value="'.$row["memo"].'" size="10">'."\n";
echo ' <select class="' . $class . '" name="class[' . $row["id"] . ']">'."\n";
echo ' <option value=""'. ($row['class'] == 'ZZZZZZZZZ' ? ' selected="selected"' : '') .'></option>'."\n";
echo ' <option value="Fruit"'. ($row['class'] == 'Fruit' ? ' selected="selected"' : '') .'>Fruit</option>'."\n";
echo ' <option value="Aardappelen"'. ($row['class'] == 'Aardappelen' ? ' selected="selected"' : '') .'>Aardappelen</option>'."\n";
echo ' <option value="Groenten"'. ($row['class'] == 'Groenten' ? ' selected="selected"' : '') .'>Groenten</option>'."\n";
echo ' </select>'."\n";
echo '<input type="hidden" name="id[]" value="' . $row["id"] . '"> ' . "\n";
}
echo '<br>'. "\n";
echo '<input type="submit" size=40 name="submit" value="Bewaren">' . "\n";
echo '</div>' . "\n";
}
?>
Je moet de connection identifier toevoegen.
Kijk hier ook eens naar:
https://www.w3schools.com/php/func_mysqli_query.asp
Begin eens met een leeg PHP bestand waarin je een simpele db verbinding tot stand probeert te brengen.
Vervolgens kun je een select proberen.
Als je dat allemaal onder de knie hebt, kun je je huidige script aanpassen.
Ik heb namelijk de indruk dat je geen foutmeldingen krijgt, terwijl die in deze gevallen toch vrij duidelijk zouden moeten zijn.
"Fatal error: Uncaught Error: Call to undefined function mysqli_connect() "
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
?>
<?php
$con=mysqli_connect("localhost","root","","app");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
mysqli_query($con,"SELECT * FROM list");
mysqli_close($con);
?>
error_reporting(E_ALL);
ini_set('display_errors', true);
?>
<?php
$con=mysqli_connect("localhost","root","","app");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
mysqli_query($con,"SELECT * FROM list");
mysqli_close($con);
?>
Ivo P op 23/08/2017 12:04:06:
zet eens bovenin je script(s)
Ik heb namelijk de indruk dat je geen foutmeldingen krijgt, terwijl die in deze gevallen toch vrij duidelijk zouden moeten zijn.
Ik heb namelijk de indruk dat je geen foutmeldingen krijgt, terwijl die in deze gevallen toch vrij duidelijk zouden moeten zijn.
Offtopic, kunnen we dit niet opgeven voor nieuwe topics, dat dit bovenaan elk PHP script moet staan?
Toevoeging op 23/08/2017 12:51:23:
Stevie J op 23/08/2017 12:48:27:
Ivo, is heb de code in een simpel script geplaatst, resultaat:
"Fatal error: Uncaught Error: Call to undefined function mysqli_connect() "
"Fatal error: Uncaught Error: Call to undefined function mysqli_connect() "
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
?>
<?php
$con=mysqli_connect("localhost","root","","app");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
mysqli_query($con,"SELECT * FROM list");
mysqli_close($con);
?>
error_reporting(E_ALL);
ini_set('display_errors', true);
?>
<?php
$con=mysqli_connect("localhost","root","","app");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
mysqli_query($con,"SELECT * FROM list");
mysqli_close($con);
?>
Staat mysqli wel enabled in je phpinfo()?
Klinkt niet goed he?
Begin dan eens met het inschakelen van mysqli. In geval van een hosted omgeving, vraag het je hoster. Of controleer of PDO wel beschikbaar is. Wat je voorkeur maar heeft.
Warning: mysqli_connect(): (HY000/2002): No such file or directory in test.php on line 6 Failed to connect to MySQL: No such file or directory Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in test.php on line 14 Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in test.php on line 17
Ik neem aan dat je na wijzigingen even apache en mysql opnieuw opstart.
Wat als je Localhost vervangt door 127.0.0.1
Ivo P op 23/08/2017 13:35:21:
@SanThe: de foutmelding is veranderd, dus restart zal niet (meer) nodig zijn.
Dat is waar ...
Restart en localhost vervangen heeft geen resultaat.
is er een Mysql server aanwezig en draaiend?
ik draai het op mijn Synology NAS, met Mariadb10 en phpMyAdmin
Dus IP nummer in plaats van localhost en het port nummer gebruiken.
Laat je portnummer weg, dan wil PHP met MariaDB 5 verbinden.
Gebruik je localhost en toch het port nummer, ook dan wil PHP met MariaDB 5 verbinden.