berichten systeem werkt niet meer
Ik heb een berichten systeem waarbij je een bericht naar een username kan sturen, maar na dat ik dingen veranderd heb doet hij het onverwachts niet meer. ik merk dat er steeds al het een en ander mis gaat
dit is mijn pagina, ik weet 90% zeker dat hier de fout zit, maar kan hem echt nergens vinden... ben al een tijdje aan t kijken en proberen..
als je wil kijken wat hoe en wat werkt: http://web-stars.nl/
je kan een nieuwe account maken of gebruikersnaam: fabian wachtwoord: fabian gebruiken.
de error is:
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
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
<?php
include('profielhead.php');
if(isset($_SESSION['username']))
{
$form = true;
$otitle = '';
$orecip = '';
$omessage = '';
if(isset($_POST['title'], $_POST['recip'], $_POST['message']))
{
$otitle = $_POST['title'];
$orecip = $_POST['recip'];
$omessage = $_POST['message'];
if(get_magic_quotes_gpc())
{
$otitle = stripslashes($otitle);
$orecip = stripslashes($orecip);
$omessage = stripslashes($omessage);
}
if($_POST['title']!='' and $_POST['recip']!='' and $_POST['message']!='')
{
$title = mysql_real_escape_string($otitle);
$recip = mysql_real_escape_string($orecip);
$message = mysql_real_escape_string(nl2br(htmlentities($omessage, ENT_QUOTES, 'UTF-8')));
$dn1 = mysql_fetch_array(mysql_query('select count(id) as recip, id as recipid, (select count(*) from pm) as npm from users where username="'.$recip.'"'));
if($dn1['recip']==1)
{
if($dn1['recipid']!=$_SESSION['userid'])
{
$id = $dn1['npm'];
if(mysql_query('insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", "1", "'.$title.'", "'.$_SESSION['userid'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no")'))
{
?>
<div class="message">Het bericht is verstuurd<br />
<a href="list_pm.php">berichten</a></div>
<?php
$form = false;
}
else
{
$error = 'Er is een fout opgetreden, neem contact op met webstars.';
}
}
else
{
$error = 'You cannot send a PM to yourself.';
}
}
else
{
$error = 'The recipient of your PM doesn\'t exist.';
}
}
else
{
$error = 'A field is not filled.';
}
}
elseif(isset($_GET['recip']))
{
$orecip = $_GET['recip'];
}
if($form)
{
if(isset($error))
{
echo '<div class="message">'.$error.'</div>';
}
?>
<div class="col-md-5">
<form action="new_pm.php" method="post">
<div class="form-group">
<label for="recip">gebruikersnaam <small>(ontvanger)</small></label>
<input type="text" name="recip" class="form-control" id="recip" value="<?php echo htmlentities($orecip, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="form-group">
<label for="title">onderwerp</label>
<input type="text" name="title" class="form-control" id="title"value="<?php echo htmlentities($otitle, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="form-group">
<label for="message">bericht</label>
<textarea name="message" rows="10" cols="50" class="form-control" id="message"><?php echo htmlentities($omessage, ENT_QUOTES, 'UTF-8'); ?></textarea>
</div>
<input type="submit" value="Submit" class="btn btn-primary"/> <input type="button" onclick="javascript:document.location='http://web-stars.nl/account/list_pm.php';" value="terug" class="btn btn-default"/>
</div>
</form>
</div>
<?php
}
}
else
{
?>
<div class="message">You must be logged to access this page.</div>
<?php
}
?>
</div>
</body>
</html>
include('profielhead.php');
if(isset($_SESSION['username']))
{
$form = true;
$otitle = '';
$orecip = '';
$omessage = '';
if(isset($_POST['title'], $_POST['recip'], $_POST['message']))
{
$otitle = $_POST['title'];
$orecip = $_POST['recip'];
$omessage = $_POST['message'];
if(get_magic_quotes_gpc())
{
$otitle = stripslashes($otitle);
$orecip = stripslashes($orecip);
$omessage = stripslashes($omessage);
}
if($_POST['title']!='' and $_POST['recip']!='' and $_POST['message']!='')
{
$title = mysql_real_escape_string($otitle);
$recip = mysql_real_escape_string($orecip);
$message = mysql_real_escape_string(nl2br(htmlentities($omessage, ENT_QUOTES, 'UTF-8')));
$dn1 = mysql_fetch_array(mysql_query('select count(id) as recip, id as recipid, (select count(*) from pm) as npm from users where username="'.$recip.'"'));
if($dn1['recip']==1)
{
if($dn1['recipid']!=$_SESSION['userid'])
{
$id = $dn1['npm'];
if(mysql_query('insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", "1", "'.$title.'", "'.$_SESSION['userid'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no")'))
{
?>
<div class="message">Het bericht is verstuurd<br />
<a href="list_pm.php">berichten</a></div>
<?php
$form = false;
}
else
{
$error = 'Er is een fout opgetreden, neem contact op met webstars.';
}
}
else
{
$error = 'You cannot send a PM to yourself.';
}
}
else
{
$error = 'The recipient of your PM doesn\'t exist.';
}
}
else
{
$error = 'A field is not filled.';
}
}
elseif(isset($_GET['recip']))
{
$orecip = $_GET['recip'];
}
if($form)
{
if(isset($error))
{
echo '<div class="message">'.$error.'</div>';
}
?>
<div class="col-md-5">
<form action="new_pm.php" method="post">
<div class="form-group">
<label for="recip">gebruikersnaam <small>(ontvanger)</small></label>
<input type="text" name="recip" class="form-control" id="recip" value="<?php echo htmlentities($orecip, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="form-group">
<label for="title">onderwerp</label>
<input type="text" name="title" class="form-control" id="title"value="<?php echo htmlentities($otitle, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="form-group">
<label for="message">bericht</label>
<textarea name="message" rows="10" cols="50" class="form-control" id="message"><?php echo htmlentities($omessage, ENT_QUOTES, 'UTF-8'); ?></textarea>
</div>
<input type="submit" value="Submit" class="btn btn-primary"/> <input type="button" onclick="javascript:document.location='http://web-stars.nl/account/list_pm.php';" value="terug" class="btn btn-default"/>
</div>
</form>
</div>
<?php
}
}
else
{
?>
<div class="message">You must be logged to access this page.</div>
<?php
}
?>
</div>
</body>
</html>
Gewijzigd op 30/06/2015 16:39:07 door Fabian webstars
De standaard MySQL-extensie is al 10 jaar verouderd en wordt op korte termijn definitief uitgerangeerd.
ik ga straks van mysql(i)query naar php oop pdo stappen. maar alles op zijn tijd he
@aar ik heb de error reporting er bij staan gebeurd helemaal niks. heb de if(mysql_query(insert veranderd maar $sql = 'insert ...... ';
is dit goed?
Code (php)
1
$sql = 'insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", 1, "'.$title.'", "'.$_SESSION['userid'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no")';
de 1 is zonder quotes en zie de $sql
Gewijzigd op 30/06/2015 17:03:56 door Fabian webstars
Gewijzigd op 30/06/2015 17:09:42 door - Ariën -
had iets fout gedaan :p
ik maak deze pagina wel ff in mysli dan post ik hem straks
Gewijzigd op 30/06/2015 17:16:15 door Fabian webstars
Gewijzigd op 30/06/2015 18:06:22 door Fabian webstars
$recip bestaat niet.
Gewijzigd op 30/06/2015 19:42:54 door Fabian webstars
Je moet je query wel uitvoeren en fetchen voordat je de inhoud kan gebruiken.
Code (php)
1
2
3
4
5
6
2
3
4
5
6
$dn1 = 'SELECT count(id) as recip, id as recipid, (select count(*) from pm) as npm from users where username="'.$recip.'"';
$id = mysqli_real_escape_string($link, $dn1['npm']+1);
$sql = 'insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", 1, "'.$title.'", "'.$_SESSION['userid'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no")';
Zoals ik al zei voer je de query nergens uit (mysqli_query() ), en fetch je hem ook niet.
zou je me kunnen helpen daar mee?
de error is: Warning: Illegal string offset 'npm' in /home/web-stars.nl/www/account/new_pm.php on line 125 Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /home/web-stars.nl/www/account/new_pm.php on line 125 Warning: Illegal string offset 'recipid' in /home/web-stars.nl/www/account/new_pm.php on line 126
en met dat fetchen... sorry maar ik snap het echt niet
okey: en met dat fetchen... sorry maar ik snap het echt niet
Gewijzigd op 30/06/2015 18:46:57 door Fabian webstars
http://phptuts.nl/view/41/ en pad de functies aan naar mysqli.
Kijk anders eens hier: Toevoeging op 30/06/2015 19:39:45:
zou iemand het voor me kloppend kunnen maken? Ben er echt klaar mee :P heb het script een aantal dagen geleden veranderd waardoor ik er een dag daarna achter kwam dat het niet meer werkte en heb der echt onzettend veel uur ingestopt xD :( ben nog niet zo'n goede programmeur, maar ik vind het wel belangrijk dat alles wat ik online heb staan op mijn website klopt..
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
// laad connection in in $con
$sql = 'SELECT COUNT(id) AS recip, id AS recipid, (SELECT COUNT(*) FROM pm) AS npm FROM users WHERE username="'.$recip.'"';
$result = mysqli_query($con,$sql);
if($result) {
$data = mysqli_fetch_assoc($result);
echo $data['npm']+1;
} else {
// query mislukt toon hier een foutmelding zoals beschreven op:
// http://www.phphulp.nl/php/tutorial/data-verwerking/foutafhandeling-query-sql/735/
}
?>
// laad connection in in $con
$sql = 'SELECT COUNT(id) AS recip, id AS recipid, (SELECT COUNT(*) FROM pm) AS npm FROM users WHERE username="'.$recip.'"';
$result = mysqli_query($con,$sql);
if($result) {
$data = mysqli_fetch_assoc($result);
echo $data['npm']+1;
} else {
// query mislukt toon hier een foutmelding zoals beschreven op:
// http://www.phphulp.nl/php/tutorial/data-verwerking/foutafhandeling-query-sql/735/
}
?>
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
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
<?php
include 'profilehead.php';
error_reporting(E_ALL);
ini_set('display_errors', 'on');
if(isset($_SESSION['username'])) {
$form = TRUE;
$otitle = '';
$orecip = '';
$omessage = '';
if(isset($_POST['title'], $_POST['recip'], $_POST['message'])) {
$otitle = $_POST['title'];
$orecip = $_POST['recip'];
$omessage = $_POST['message'];
if(get_magic_quotes_gpc()) {
$otitle = stripslashes($otitle);
$orecip = stripslashes($orecip);
$omessage = stripslashes($omessage);
}
if(!empty($_POST['title']) && !empty($_POST['recip']) && !empty($_POST['message'])) {
$title = mysql_real_escape_string($otitle);
$recip = mysql_real_escape_string($recip);
$message = mysql_real_escape_string(nlbr(htmlentities($omessage, ENT_QUOTES, 'UTF-8')));
$res = mysql_query("SELECT count(id) AS recip, id AS recip, (SELECT count(*) FROM pm) AS npm FROM users WHERE username = '".$recip."'");
if($res) {
if(mysql_num_rows($res) > 0) {
$row = mysql_fetch_array($res);
if($row['recip'] == 1) {
if($row['recipid'] != $_SESSION['userid']) {
$id = (int)$row['npm'];
$uid = (int)$_SESSION['userid'];
$recipid = (int)$row['recipid'];
$res = mysql_query("INSERT INTO pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read) VALUES ($id, 1, '$title', $uid, $recipid, '$message', UNIX_TIMESTAMP(), 'yes', 'no')");
if($res) {
echo '<div class="message">Het bericht is verstuurd.<br /><a href="list_pm.php">Berichten</a></div>';
$form = FALSE;
}
else {
echo 'Query Error: ' . mysql_error();
}
}
else {
$error = 'You can\'t send a Private Message to yourself.';
}
}
else {
$error = 'The recipient of your Private Message doesn\'t exist.';
}
}
else {
echo 'Geen rijen gevonden.';
}
} else {
echo 'Query Fout: ' . mysql_error();
}
}
else {
$error = 'You must fill in all fields to send a Private Message.';
}
}
else if(isset($_GET['recip'])) {
$orecip = (int)$_GET['recip'];
}
if($form) {
if(isset($error)) {
echo '<div class="message">'.$error.'</div>';
}
?>
<div class="col-md-5">
<form action="new_pm.php" method="post">
<div class="form-group">
<label for="recip">gebruikersnaam <small>(ontvanger)</small></label>
<input type="text" name="recip" class="form-control" id="recip" value="<?php echo htmlentities($orecip, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="form-group">
<label for="title">onderwerp</label>
<input type="text" name="title" class="form-control" id="title"value="<?php echo htmlentities($otitle, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="form-group">
<label for="message">bericht</label>
<textarea name="message" rows="10" cols="50" class="form-control" id="message"><?php echo htmlentities($omessage, ENT_QUOTES, 'UTF-8'); ?></textarea>
</div>
<input type="submit" value="Submit" class="btn btn-primary"/> <input type="button" onclick="javascript:document.location = 'http://web-stars.nl/account/list_pm.php';" value="terug" class="btn btn-default"/>
</div>
</form>
</div>
<?php
}
} else {
echo '<div class="message">You must <a href="/login.php">Login</a> to access this page.</div>';
}
echo '</div></body></html>';[/code]
Ja 't is nog in mysql geschreven, maar kan makkelijk worden omgezet naar mysqli :)
include 'profilehead.php';
error_reporting(E_ALL);
ini_set('display_errors', 'on');
if(isset($_SESSION['username'])) {
$form = TRUE;
$otitle = '';
$orecip = '';
$omessage = '';
if(isset($_POST['title'], $_POST['recip'], $_POST['message'])) {
$otitle = $_POST['title'];
$orecip = $_POST['recip'];
$omessage = $_POST['message'];
if(get_magic_quotes_gpc()) {
$otitle = stripslashes($otitle);
$orecip = stripslashes($orecip);
$omessage = stripslashes($omessage);
}
if(!empty($_POST['title']) && !empty($_POST['recip']) && !empty($_POST['message'])) {
$title = mysql_real_escape_string($otitle);
$recip = mysql_real_escape_string($recip);
$message = mysql_real_escape_string(nlbr(htmlentities($omessage, ENT_QUOTES, 'UTF-8')));
$res = mysql_query("SELECT count(id) AS recip, id AS recip, (SELECT count(*) FROM pm) AS npm FROM users WHERE username = '".$recip."'");
if($res) {
if(mysql_num_rows($res) > 0) {
$row = mysql_fetch_array($res);
if($row['recip'] == 1) {
if($row['recipid'] != $_SESSION['userid']) {
$id = (int)$row['npm'];
$uid = (int)$_SESSION['userid'];
$recipid = (int)$row['recipid'];
$res = mysql_query("INSERT INTO pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read) VALUES ($id, 1, '$title', $uid, $recipid, '$message', UNIX_TIMESTAMP(), 'yes', 'no')");
if($res) {
echo '<div class="message">Het bericht is verstuurd.<br /><a href="list_pm.php">Berichten</a></div>';
$form = FALSE;
}
else {
echo 'Query Error: ' . mysql_error();
}
}
else {
$error = 'You can\'t send a Private Message to yourself.';
}
}
else {
$error = 'The recipient of your Private Message doesn\'t exist.';
}
}
else {
echo 'Geen rijen gevonden.';
}
} else {
echo 'Query Fout: ' . mysql_error();
}
}
else {
$error = 'You must fill in all fields to send a Private Message.';
}
}
else if(isset($_GET['recip'])) {
$orecip = (int)$_GET['recip'];
}
if($form) {
if(isset($error)) {
echo '<div class="message">'.$error.'</div>';
}
?>
<div class="col-md-5">
<form action="new_pm.php" method="post">
<div class="form-group">
<label for="recip">gebruikersnaam <small>(ontvanger)</small></label>
<input type="text" name="recip" class="form-control" id="recip" value="<?php echo htmlentities($orecip, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="form-group">
<label for="title">onderwerp</label>
<input type="text" name="title" class="form-control" id="title"value="<?php echo htmlentities($otitle, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="form-group">
<label for="message">bericht</label>
<textarea name="message" rows="10" cols="50" class="form-control" id="message"><?php echo htmlentities($omessage, ENT_QUOTES, 'UTF-8'); ?></textarea>
</div>
<input type="submit" value="Submit" class="btn btn-primary"/> <input type="button" onclick="javascript:document.location = 'http://web-stars.nl/account/list_pm.php';" value="terug" class="btn btn-default"/>
</div>
</form>
</div>
<?php
}
} else {
echo '<div class="message">You must <a href="/login.php">Login</a> to access this page.</div>';
}
echo '</div></body></html>';[/code]
Ja 't is nog in mysql geschreven, maar kan makkelijk worden omgezet naar mysqli :)
Gewijzigd op 30/06/2015 20:23:03 door RobertJan Doeternietoe
- zet magic_quotes_gpc standaard uit, dan hoef je hier niet op te controleren
- kopieer niet nodeloos variabelen ($_POST['var'] --> $var), dat schept alleen maar verwarring
- maak van pm.id een auto_increment id, want elke keer het eerstvolgende vrije nummer berekenen is een beetje loos
- maak gebruik van mysqli (de stap mysql > procedurele mysqli is echt niet zo groot)