onthespot Posted September 3, 2009 Share Posted September 3, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/172966-solved-mass-pm/ Share on other sites More sharing options...
ignace Posted September 3, 2009 Share Posted September 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911609 Share on other sites More sharing options...
onthespot Posted September 3, 2009 Author Share Posted September 3, 2009 Must be a database issue then, will look into it. Will this create a message for every username in the user table? Quote Link to comment https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911612 Share on other sites More sharing options...
onthespot Posted September 3, 2009 Author Share Posted September 3, 2009 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911618 Share on other sites More sharing options...
MatthewJ Posted September 3, 2009 Share Posted September 3, 2009 Shouldn't NOW() be the last item in your values? Quote Link to comment https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911622 Share on other sites More sharing options...
onthespot Posted September 3, 2009 Author Share Posted September 3, 2009 There were a few isssues, i have sorted it now and it works. Quote Link to comment https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911625 Share on other sites More sharing options...
JonnoTheDev Posted September 3, 2009 Share Posted September 3, 2009 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"); Quote Link to comment https://forums.phpfreaks.com/topic/172966-solved-mass-pm/#findComment-911626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.