chatbox
Zou je je antwoord kunnen verduidelijken, je hebt dit al vaker gezegd, maar ik kom er niet verder mee.
Misschien is het handig om je code eerst even goed in te springen.
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
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
<?php
$conn=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
if(isset($_GET['id']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
$insert1 = "INSERT INTO chat (id,msg,timestamp,displayed)
VALUES ('".$_GET['id']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE id= $id and displayed=0";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."]".$str_msg;}
}
else
{
echo "Failed to select users in chat: " . mysqli_error($conn);
}
}
else if(isset($_GET['id']))
{
$query = "SELECT * FROM users WHERE id = $id and displayed=0";
$result = mysqli_query($conn,$query) or die ("Error in query: $query. ".mysqli_error());
$num_rows = mysqli_num_rows($result);
if ($num_rows)
{
while($new_msg = mysqli_fetch_array($result))
echo "<br><b>User </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
}
}
else
{
echo "Failed to select users in chaffft: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
$conn=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
if(isset($_GET['id']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
$insert1 = "INSERT INTO chat (id,msg,timestamp,displayed)
VALUES ('".$_GET['id']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE id= $id and displayed=0";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."]".$str_msg;}
}
else
{
echo "Failed to select users in chat: " . mysqli_error($conn);
}
}
else if(isset($_GET['id']))
{
$query = "SELECT * FROM users WHERE id = $id and displayed=0";
$result = mysqli_query($conn,$query) or die ("Error in query: $query. ".mysqli_error());
$num_rows = mysqli_num_rows($result);
if ($num_rows)
{
while($new_msg = mysqli_fetch_array($result))
echo "<br><b>User </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
}
}
else
{
echo "Failed to select users in chaffft: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
De Script_page.php code.
1. Ik krijg als ik naar de script_page.php pagina open krijg ik:
Failed to select users in chat.
hoe verander ik dat.
2. open ik de index1.php pagina dan krijg ik:
Failed to select users in chaffft
Kan iemand duidelijk aangeven waar het hem in zit?
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
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
<?php
$conn = mysqli_connect("localhost", "root", "superbart", "minimail");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_GET['id'])) {
$id = intval($_GET['id']);
// getting info from db
}
if (isset($_GET['id'])) {
if (isset($_GET['content'])) {
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'] . ":" . $time['minutes'] . ":" . $time['seconds'];
$insert1 = "INSERT INTO chat (id,msg,timestamp,displayed)
VALUES ('" . $_GET['id'] . "', '" . addslashes($str_msg) . "', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE id= $id and displayed=0";
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($result)) {
echo "<br><b>User" . $row['username'] . " </b>";
}
$result = mysqli_query($conn, $insert1);
while ($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[" . $t_stamp . "]" . $str_msg;
}
} else {
echo "Failed to select users in chat: " . mysqli_error($conn);
}
} else if (isset($_GET['id'])) {
$query = "SELECT * FROM users WHERE id = $id and displayed=0";
$result = mysqli_query($conn, $query) or die("Error in query: $query. " . mysqli_error());
$num_rows = mysqli_num_rows($result);
if ($num_rows) {
while ($new_msg = mysqli_fetch_array($result))
echo "<br><b>User </b>[" . $new_msg['timestamp'] . "] <b>: </b></font>" . stripslashes($new_msg['msg']);
}
} else {
echo "Failed to select users in chaffft: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
$conn = mysqli_connect("localhost", "root", "superbart", "minimail");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_GET['id'])) {
$id = intval($_GET['id']);
// getting info from db
}
if (isset($_GET['id'])) {
if (isset($_GET['content'])) {
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'] . ":" . $time['minutes'] . ":" . $time['seconds'];
$insert1 = "INSERT INTO chat (id,msg,timestamp,displayed)
VALUES ('" . $_GET['id'] . "', '" . addslashes($str_msg) . "', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE id= $id and displayed=0";
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($result)) {
echo "<br><b>User" . $row['username'] . " </b>";
}
$result = mysqli_query($conn, $insert1);
while ($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[" . $t_stamp . "]" . $str_msg;
}
} else {
echo "Failed to select users in chat: " . mysqli_error($conn);
}
} else if (isset($_GET['id'])) {
$query = "SELECT * FROM users WHERE id = $id and displayed=0";
$result = mysqli_query($conn, $query) or die("Error in query: $query. " . mysqli_error());
$num_rows = mysqli_num_rows($result);
if ($num_rows) {
while ($new_msg = mysqli_fetch_array($result))
echo "<br><b>User </b>[" . $new_msg['timestamp'] . "] <b>: </b></font>" . stripslashes($new_msg['msg']);
}
} else {
echo "Failed to select users in chaffft: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
1) Als je nu even een lineaal pakt, en naar de accolades kijkt, dan zie je dat die eerste foutmelding opgeroepen wordt na:
if (isset($_GET['content'])) {
Dit lijkt niet te kloppen, je zult hierbij moeten kijken naar je $result.
2) Idem dito voor tweede error.
met andere woorden: Je structuur klopt niet. Mogelijk omdat deze voorheen niet goed ingesprongen was, waardoor je het overzicht kwijtraakt.
Gewijzigd op 17/03/2015 18:44:07 door - Ariën -
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
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
<?php
$conn=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
if(isset($_GET['id']))
{
$str_msg = stripslashes($_GET['id']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
$insert1 = "INSERT INTO chat (id,msg,timestamp,displayed)
VALUES ('".$_GET['id']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE id= $id and displayed=0";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."]".$str_msg;}
$query1 = "SELECT * FROM users WHERE id = $id and displayed=0";
$result1 = mysqli_query($conn,$query1) or die ("Error in query: $query1. ".mysqli_error());
$num_rows = mysqli_num_rows($result1);
if ($num_rows)
{
while($new_msg = mysqli_fetch_array($result))
echo "<br><b>User </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
}
}
else
{
echo "Failed to select users in chaffft: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
$conn=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
if(isset($_GET['id']))
{
$str_msg = stripslashes($_GET['id']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
$insert1 = "INSERT INTO chat (id,msg,timestamp,displayed)
VALUES ('".$_GET['id']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE id= $id and displayed=0";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."]".$str_msg;}
$query1 = "SELECT * FROM users WHERE id = $id and displayed=0";
$result1 = mysqli_query($conn,$query1) or die ("Error in query: $query1. ".mysqli_error());
$num_rows = mysqli_num_rows($result1);
if ($num_rows)
{
while($new_msg = mysqli_fetch_array($result))
echo "<br><b>User </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
}
}
else
{
echo "Failed to select users in chaffft: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
Die melding hoort bij een controle op je $result
Natuurlijk moet uiteindelijk ook bij deze chat het zo zijn dat je je naam niet hoeft in te vullen maar hij dat automatisch invult etc. Maar daar ga ik later mee aan de slag.