Jump to content

[SOLVED] Mass PM


onthespot

Recommended Posts

Hello. I have been working on a mass PM function, where the message is sent out to every member of the site.

 

The form

<form action="masspm.php" method="POST">
<input type="text" name="sub12" />
<textarea name="mess12" rows="2" cols="30" ></textarea>
<input type="submit" align="right" name="submit" value="Mass PM">
</form>

 

The masspm.php

<?php
$mess12=$_POST['mess12'];
$sub12=$_POST['sub12'];

$query = "SELECT username FROM users";
$result = mysql_query($query);

while($data = mysql_fetch_assoc($result))
{
$user12=$row['username'];
}
$masspm=mysql_query("INSERT INTO messages VALUES(NULL, 'Virtual-soccer', '$user12', '$sub12', '$mess12', '0')");
echo"Mass Pm have been sent";
  ?>

 

This isn't currently inserting anything into the database, could anyone help me with this?

Link to comment
https://forums.phpfreaks.com/topic/172966-solved-mass-pm/
Share on other sites

while($data = mysql_fetch_assoc($result))

{

$user12=$row['username'];

$masspm=mysql_query("INSERT INTO messages VALUES(NULL, 'Virtual-soccer', '$user12', '$sub12', '$mess12', '0')");

}

 

This isn't currently inserting anything into the database, could anyone help me with this?

 

Not true it inserted atleast one row unless the query failed.

 

Link to comment
https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911609
Share on other sites

<?php
$mess12=$_POST['mess12'];
$sub12=$_POST['sub12'];

$query = "SELECT username FROM users";
$result = mysql_query($query);

while($data = mysql_fetch_assoc($result))
{
$user12=$row['username'];
$masspm=mysql_query("INSERT INTO messages (from_user, to_user, message_title, message_contents,
message_date) VALUES ('Virtual-soccer', '$user12', '$sub12', '$mess12', now(), '0');");

}
echo"Mass Pm have been sent";
  ?>

 

Can anyone see any errors here?

Link to comment
https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911618
Share on other sites

Yes $row does not exist, should be

$user12 = $data['username'];

 

However you could have performed this in 1 query without have to use (num users +1) queries. No loops needed. Replace value field names with correct names:

mysql_query("INSERT INTO messages (field1,field2,field3,field4,field5,field6) SELECT NULL, 'Virtual-soccer', username FROM users, '".$sub12."', '".$mess12."', 0");

Link to comment
https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911626
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.