chatbox
Pagina: « vorige 1 2 3 volgende »
Opvallend vind ik inmiddels het volgende. De chat is te zien via die Index.php, maar als ik naar de pagina ga met deze sql query`s etc. Krijg ik het volgende:
" Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 59
Failed to connect to MySQL:"
- SanThe - op 17/03/2015 16:35:04:
Als de GET niet bestaat ook geen $id.
Aar C op 17/03/2015 16:31:45:
Op het eerste ogenblik zie ik ook niet waarom die $id niet zou bestaan.
Als de GET niet bestaat ook geen $id.
Maar hij zegt:
Quote:
Achter de link staat ?id=1 en bovenaan de code staat....
Ik betwijfel eigenlijk of er echt wel een id= is meegegeven.
Toevoeging op 17/03/2015 16:41:05:
Bart de kinkelaar op 17/03/2015 16:36:03:
Opvallend vind ik inmiddels het volgende. De chat is te zien via die Index.php, maar als ik naar de pagina ga met deze sql query`s etc. Krijg ik het volgende:
" Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 59
Failed to connect to MySQL:"
" Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 59
Failed to connect to MySQL:"
Er mist een argument aan de functie. Die van de connectie.
Bart de kinkelaar op 17/03/2015 16:36:03:
De MQL`s zijn aangepast, font weggehaald. $conn was bij Index.php $con, dat is gelijkgetrokken.
Opvallend vind ik inmiddels het volgende. De chat is te zien via die Index.php, maar als ik naar de pagina ga met deze sql query`s etc. Krijg ik het volgende:
" Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 59
Failed to connect to MySQL:"
Opvallend vind ik inmiddels het volgende. De chat is te zien via die Index.php, maar als ik naar de pagina ga met deze sql query`s etc. Krijg ik het volgende:
" Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 59
Failed to connect to MySQL:"
mysqli_error( $conn );
http://localhost:8080/webwinkelcentrum/mmchat3/index1.php?id=1 Mijn link waarbij ik het id check.
Bij een vorige site werkte id wel. Waarschijnlijk mis ik een bepaald bestand die ik wel in het mapje vd vorige site heb, en niet hier. Ik ga t controleren.
Bij een vorige site werkte id wel. Waarschijnlijk mis ik een bepaald bestand die ik wel in het mapje vd vorige site heb, en niet hier. Ik ga t controleren.
php mysqli_error en zie de derde hit van boven
Alle php functies staan op php.net beschreven. Google gewoon op Notice: Undefined variable: id in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 44
hetgeen wat ik krijg als ik de mysql error verander in wat jij zei ( mysqli_error($con);
Ik kijk dalijk wel even op php.net
Toevoeging op 17/03/2015 16:53:37:
van die site word ik niet echt wat wijzer van wat de fout is, heb ik het idee.
Zet eens als test een vast $id=1; neer.
Gewijzigd op 17/03/2015 16:56:00 door - SanThe -
Die site is de complete referentie naar alle standaard php functies. Het laat je weten waarvoor een functie dient, welke parameters je moet opgeven, welke parameters optioneel zijn en wat de functie kan teruggeven. Daarnaast staan er voorbeelden bij. Onmisbaar dus
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$con=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
session_start(); // Start a new session?><?php
{
$id = 1;
// getting info from db
}
?>
$con=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
session_start(); // Start a new session?><?php
{
$id = 1;
// getting info from db
}
?>
hierbij is de error: Notice: Undefined variable: nrOfRows in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 47
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$con=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
session_start(); // Start a new session
if(isset($_GET['id']))
{
$id = 1;
// getting info from db
}
?>
$con=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
session_start(); // Start a new session
if(isset($_GET['id']))
{
$id = 1;
// getting info from db
}
?>
levert dezelfde code op als eerder in dit topic vermeld (undefined variable: id)
Gewijzigd op 17/03/2015 17:10:36 door - Ariën -
Dus de GET werkt niet/is leeg.
ik zag dat er naast "if(isset($_GET['id']))" ook "if(isset($_GET['get']))" stond. Toen ik dit aanpaste gaf hij aan Failed to connect to Mysql
Gewijzigd op 17/03/2015 17:11:38 door - Ariën -
Index1.php:
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
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
<?php session_start(); // Start a new session
$con=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Ajax Chat Script [User 1]</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript" src="functions.js"></script>
<script type="text/javascript">
</script>
<link href="styles.css" rel="stylesheet" type="text/css"></link>
<script language="JavaScript">
<!--
if (document.layers)
document.captureEvents(Event.KEYDOWN);
document.onkeydown =
function (evt) {
var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
if (keyCode == 13)
{
send_message('output_div','text_content','1');
}
}
//-->
</script>
</head>
<body onload="get_message('output_div','1')">
<center>
<div class="body-holder">
<div class="window">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><img src='images/header_01.jpg' height="34"></td>
<td background="images/header_02.jpg" >
</td>
<td background="images/header_02.jpg" width="100%">
<div id="window_title">MiniMail Chat</div>
</td>
<td background="images/header_02.jpg" >
<img src="images/tipclose.gif" width="20" height="15" onclick="javascript:window.opener='x';window.close()";>
</td>
<td><img src='images/header_03.jpg'></td>
</tr>
</table>
</div>
<div id="tools">
<?php
$res_smilies = mysql_query("select * from smilies");
$count = 0;
echo "<table cellspacing=1 border=0 cellpadding=1>\n<tr>";
while($row_smilies = mysql_fetch_array($res_smilies))
{
if($count == 4)
{
echo "</tr><tr>";
$count=0;
}
echo "\n<td align='center' width='35'>\n <a href='#' alt='".$row_smilies['image_code']."' onclick=\"add_code('".($row_smilies['image_code'])."');\" border=\"0\"><img src=\"images/".$row_smilies['id'].".gif\" border=\"0\"></a>\n</td>";
$count ++;
}
echo "</table>";
?>
</div>
<div class="main_container">
<div class="output-div-container">
<div id="output_div" onclick="show_smilies()">
</div>
</div>
<table border="0" width="504" class="tool_table">
<tr>
<td width="20"><a href="#" onclick="show_smilies('tool')"><img src="images/1.gif" border="0"></a></td>
<td></td>
</tr>
</table>
<div class="input-div">
<textarea type="text" id="text_content" onclick="show_smilies()" size="40" ></textarea>
<input type="submit" value="send" onclick="send_message('output_div','text_content','1')">
</div>
</div>
</div>
</center>
<?php
$sql = "select * FROM users";
$result = mysqli_query($con, $sql) or die ( mysql_error() );
$nrOfRows = mysqli_num_rows($result);
if ($nrOfRows > 0)
{
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td><b><center>Alle gebruikers:</center></b></td>";
echo "<td><b><center>" . $row['username'] . "</center></b></td>";
echo "</tr>";
}
echo "</table>";
}
else
{
header("Location:NietIngelogd.php");
}
mysqli_close($con);?>
</body>
</html>
$con=mysqli_connect("localhost","root","superbart","minimail");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Ajax Chat Script [User 1]</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript" src="functions.js"></script>
<script type="text/javascript">
</script>
<link href="styles.css" rel="stylesheet" type="text/css"></link>
<script language="JavaScript">
<!--
if (document.layers)
document.captureEvents(Event.KEYDOWN);
document.onkeydown =
function (evt) {
var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
if (keyCode == 13)
{
send_message('output_div','text_content','1');
}
}
//-->
</script>
</head>
<body onload="get_message('output_div','1')">
<center>
<div class="body-holder">
<div class="window">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><img src='images/header_01.jpg' height="34"></td>
<td background="images/header_02.jpg" >
</td>
<td background="images/header_02.jpg" width="100%">
<div id="window_title">MiniMail Chat</div>
</td>
<td background="images/header_02.jpg" >
<img src="images/tipclose.gif" width="20" height="15" onclick="javascript:window.opener='x';window.close()";>
</td>
<td><img src='images/header_03.jpg'></td>
</tr>
</table>
</div>
<div id="tools">
<?php
$res_smilies = mysql_query("select * from smilies");
$count = 0;
echo "<table cellspacing=1 border=0 cellpadding=1>\n<tr>";
while($row_smilies = mysql_fetch_array($res_smilies))
{
if($count == 4)
{
echo "</tr><tr>";
$count=0;
}
echo "\n<td align='center' width='35'>\n <a href='#' alt='".$row_smilies['image_code']."' onclick=\"add_code('".($row_smilies['image_code'])."');\" border=\"0\"><img src=\"images/".$row_smilies['id'].".gif\" border=\"0\"></a>\n</td>";
$count ++;
}
echo "</table>";
?>
</div>
<div class="main_container">
<div class="output-div-container">
<div id="output_div" onclick="show_smilies()">
</div>
</div>
<table border="0" width="504" class="tool_table">
<tr>
<td width="20"><a href="#" onclick="show_smilies('tool')"><img src="images/1.gif" border="0"></a></td>
<td></td>
</tr>
</table>
<div class="input-div">
<textarea type="text" id="text_content" onclick="show_smilies()" size="40" ></textarea>
<input type="submit" value="send" onclick="send_message('output_div','text_content','1')">
</div>
</div>
</div>
</center>
<?php
$sql = "select * FROM users";
$result = mysqli_query($con, $sql) or die ( mysql_error() );
$nrOfRows = mysqli_num_rows($result);
if ($nrOfRows > 0)
{
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td><b><center>Alle gebruikers:</center></b></td>";
echo "<td><b><center>" . $row['username'] . "</center></b></td>";
echo "</tr>";
}
echo "</table>";
}
else
{
header("Location:NietIngelogd.php");
}
mysqli_close($con);?>
</body>
</html>
Script_page.php:
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
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
<?php
$con=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
}?>
<?php
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 (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE user_id= $id";
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($con,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error($con);
}
}
else if(isset($_GET['id']))
{
$query = "SELECT * FROM users WHERE user_id= $id";
$result = mysqli_query($con,$query) or die (mysql_error());
$num_rows = mysqli_num_rows($result);
if ($nrOfRows)
{
while($new_msg = mysqlifetch_array($result))
echo "<br><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$query = "select * from users where user_id= $id";
$result = mysqli_query($query);
}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error($con);
}
function add_smilies($str_msg)
{
$get_smiles = mysqli_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysqli_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysql_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysql_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
?>
$con=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
}?>
<?php
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 (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE user_id= $id";
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($con,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error($con);
}
}
else if(isset($_GET['id']))
{
$query = "SELECT * FROM users WHERE user_id= $id";
$result = mysqli_query($con,$query) or die (mysql_error());
$num_rows = mysqli_num_rows($result);
if ($nrOfRows)
{
while($new_msg = mysqlifetch_array($result))
echo "<br><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$query = "select * from users where user_id= $id";
$result = mysqli_query($query);
}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error($con);
}
function add_smilies($str_msg)
{
$get_smiles = mysqli_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysqli_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysql_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysql_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
?>
Waar gaat het fout?
Je zet $id (is GET) onbeveiligd in een query.
Ik zie header() middenin de html.
Begin eens met logica in je script te brengen.
Code (php)
Het een heeft geen biet te maken met het ander. Daarom is je mysqli_error() naar alle waarschijnlijkheid ook leeg: er is helemaal geen database-fout aanwezig op dat moment.
Oplossing: geef toepasselijke foutmeldingen in plaats van deze nietszeggende (en foutieve) boodschappen.
Daaruit bleek dat de fout nog steeds hierin 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
}
}
else if(isset($_GET['id']))
{
$query = "SELECT * FROM users WHERE user_id= $id";
$result = mysqli_query($conn,$query) or die (mysli_error());
$num_rows = mysqli_num_rows($result);
if ($nrOfRows)
{
while($new_msg = mysqlifetch_array($result))
echo "<br><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$query = "select * from users where user_id= $id";
$result = mysqli_query($query);
}
}
else
{
echo "Failed to connect to MySQL" . mysqli_error($conn);
}
function ?>
}
}
else if(isset($_GET['id']))
{
$query = "SELECT * FROM users WHERE user_id= $id";
$result = mysqli_query($conn,$query) or die (mysli_error());
$num_rows = mysqli_num_rows($result);
if ($nrOfRows)
{
while($new_msg = mysqlifetch_array($result))
echo "<br><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$query = "select * from users where user_id= $id";
$result = mysqli_query($query);
}
}
else
{
echo "Failed to connect to MySQL" . mysqli_error($conn);
}
function ?>
9 ..$nrOfRows => onbekende variabele.
11 ..mysqlifetch_array() => onbekende function.
13..14.. zinloos.
Gewijzigd op 17/03/2015 18:08:01 door - SanThe -
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
$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 (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['id']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE user_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."] <b>: </b></font>".$str_msg;}
}
else
{
echo "Failed to select users in chat: " . mysqli_error();
}
}
else if(isset($_GET['id']))
{
$query = "SELECT * FROM users WHERE user_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 ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
}
}
else
{
echo "o";
}
function add_smilies($str_msg)
{
$get_smiles = mysqli_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysqli_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysli_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysli_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
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 (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['id']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "SELECT * FROM users WHERE user_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."] <b>: </b></font>".$str_msg;}
}
else
{
echo "Failed to select users in chat: " . mysqli_error();
}
}
else if(isset($_GET['id']))
{
$query = "SELECT * FROM users WHERE user_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 ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
}
}
else
{
echo "o";
}
function add_smilies($str_msg)
{
$get_smiles = mysqli_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysqli_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysli_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysli_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
mysqli_close($conn);
?>
Op de plaats van de echo 'o' is dus bekend dat $_GET['id'] NIET bestaat.