Jump to content


Photo

PHP mailer + update mysql database


  • Please log in to reply
4 replies to this topic

#1 bombardos

bombardos
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 September 2005 - 01:46 PM

Hi,
First time here, long time geek.

I've been mulling over a problem for the last couple of days, and thought it was time to look for a little help in the right direction.

Basically, I have an admin page with a list of registered users details in a dynamic table. In one of the fields, called "status", I have 2 buttons each in their own form that when one is clicked, goes to a mailer1.php and is supposed to send the email in mailer1.php to the user in the row of the dynamic table and update the status field in the mysql database. And when the other is clicked, goes to mailer2.php and does the same.

The forms with the buttons is here http://croc.ftw.net.nz/extras/form.txt and works as far as going to the mailers.php

The mailers.php of which there are 2 different versions (out of the many that I have tried :/ ) are here http://croc.ftw.net.nz/extras/2.txt and here http://croc.ftw.net.nz/extras/3.txt

They both disply no errors when initiated, but then they both do nothing, niether send the email, nor update the database.

Any directional help would be appreciated. Am I going in the right direction? Can you see any huge errors? Is there lots of code missing? Need any more info?

#2 bombardos

bombardos
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 September 2005 - 11:53 PM

Also, Ive tried adding the Dreamweaver recordset to the page which adds

<?php require_once('../Connections/dbcon.php'); ?>
<?php
mysql_select_db($database_dbcon, $dbcon);
$query_Recordset1 = "SELECT * FROM users";
$Recordset1 = mysql_query($query_Recordset1, $dbcon) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
to the top of the page, and
<?php
mysql_free_result($Recordset1);
?>
to the bottom, but then I get the error "Warning: mysql_free_result(): 7 is not a valid MySQL result resource in /home/croc/public_html/admin/mailerApprove.php on line 64

Line 64 is the mysql_free_result($Recordset1);

#3 Mattyspatty

Mattyspatty
  • Members
  • PipPipPip
  • Advanced Member
  • 76 posts
  • LocationEngland :D

Posted 21 September 2005 - 11:21 AM

*slap*

name="Submit" on your mailing.php

but on mailing1 and 2 u used

$_POST['submit']

CAPITALS MATTER!!
ok, so my PHP is a bit rusty... my replies are 90% ok.
the other 10% either have syntax errors or are the "hard solution"
http://www.php.net  http://www.google.com - Are your friends!

I have a C++ problem with 'keybd_event' in certain applications. if you can help me PM me! :P
Needs motivation to create another quick cash website. I need a new TV

#4 bombardos

bombardos
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 September 2005 - 11:53 AM

Yes I noticed that after posting and changed it in the form from capital S to lowercase. Made no difference, so reshuffled it a little and am now here:
<? 
// Update info on the Database. 
mysql_connect($myhost,$myusername,$mypass); 
@mysql_select_db($dbname); 
$sql = mysql_query("UPDATE users SET approved='No' WHERE 'userid' = '$userid'") 
        or die (mysql_error()); 
       
// Define post fields into simple variables. 
$userid = $_POST['userid']; 
$username = $_POST['username']; 
$name = $_POST['name']; 
$email = $_POST['email']; 
$approved = $_POST['approved']; 

if(!$sql){ 
    echo 'error....blah.'; 
} else { 
if(isset($_POST['submit'])) { 
    $userid = $_POST['hiddenField']; 
    // Email the user! 
    $subject = "subject in here"; 
    $message = "Hi $username, blah blah blah 
with the following information: 

Username: $username 
Real Name: $name 
Email: $email 
Clan: $clan 

Body of messege. 
blah blah blah 

This is an automated response, please do not reply!"; 
      
    mail($email, $subject, $message, 
        "From: Me <me@me.com"); 
      } 
    include 'admin.php'; 
} 

?>
which now gives me a "No Database Selected". So, that would explain it not updating the database O_o, but its confused me as to why its not selecting the database.

#5 bombardos

bombardos
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 23 September 2005 - 12:50 PM

All fixed and working now.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users