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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.