Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 28th, 2006, 06:39 PM
Registered User
 
Join Date: Nov 2006
Location: manchester, , United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default mailling list:mysql_num_rows(): supplied argument

Dear helpers,

I am a newer for PHP work, I tried to build up a online mailling list and copy the code from the book and upload to the server but got following error message:
 mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/4betteruk/public_html/mails/user_transact.php on line 37

Warning: Cannot modify header information - headers already sent by (output started at /home/4betteruk/public_html/mails/user_transact.php:37) in /home/4betteruk/public_html/mails/user_transact.php on line 132

the codes which i used are:

<?php
require('config.php');
require('class.SimpleMail.php');

$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
  or die('Could not connect to MySQL database. ' . mysql_error());

mysql_select_db(SQL_DB, $conn);

$headers = "From: " . ADMIN_EMAIL . "\r\n";

if (isset($_REQUEST['action'])) {
  switch ($_REQUEST['action']) {
    case 'Remove':
      $sql = "SELECT user_id FROM ml_users " .
             "WHERE email='" . $_POST['email'] . "'";
      $result = mysql_query($sql, $conn);

      if (mysql_num_rows($result)) {
        $row = mysql_fetch_array($result);
        $user_id = $row['user_id'];
        $url = "http://" . $_SERVER['HTTP_HOST'] .
               dirname($_SERVER['PHP_SELF']) .
               "/remove.php?u=" . $user_id .
               "&ml=" . $_POST['ml_id'];
        header("Location: $url");
        exit();
      }
      $redirect = 'user.php';
      break;

    case 'Subscribe':
      $sql = "SELECT user_id FROM ml_users " .
             "WHERE email='" . $_POST['email'] . "'";
      $result = mysql_query($sql, $conn);

     if (!mysql_num_rows($result)) { $sql = "INSERT INTO ml_users " .
               "(firstname,lastname,email) ".
               "VALUES ('" . $_POST['firstname'] . "'," .
               "'" . $_POST['lastname'] . "'," .
               "'" . $_POST['email'] . "')";
        $result = mysql_query($sql, $conn);
        $user_id = mysql_insert_id($conn);
      } else {
        $row = mysql_fetch_array($result);
        $user_id = $row['user_id'];
      }

      $sql = "INSERT INTO ml_subscriptions (user_id,ml_id) " .
             "VALUES ('" . $user_id . "','" . $_POST['ml_id'] . "')";
      mysql_query($sql, $conn);

      $sql = "SELECT listname FROM ml_lists " .
             "WHERE ml_id=" . $_POST['ml_id'];
      $result = mysql_query($sql, $conn);
      $row = mysql_fetch_array($result);
      $listname = $row['listname'];

      $url = "http://" . $_SERVER['HTTP_HOST'] .
             dirname($_SERVER['PHP_SELF']) .
             "/user_transact.php?u=" . $user_id .
             "&ml=" . $_POST['ml_id'] . "&action=confirm";

      $subject = 'Mailing list confirmation';
      $body = "Hello " . $_POST['firstname'] . "\n" .
              "Our records indicate that you have subscribed to " .
             "the " . $listname . " mailing list.\n\n" .
              "If you did not subscribe, please accept our " .
              "apologies. You will not be subscribed if you do " .
              "not visit the confirmation URL.\n\n" .
              "If you subscribed, please confirm this by visiting " .
              "the following URL:\n" . $url;

      $mailmsg = new SimpleMail();
      $mailmsg->send($_POST['email'],$subject,$body,$headers);

      $redirect = "thanks.php?u=" . $user_id . "&ml=" .
                  $_POST['ml_id'] . "&t=s";
      break;

    case 'confirm':
      if (isset($_GET['u'], $_GET['ml'])) {
        $sql = "UPDATE ml_subscriptions SET pending=0 " .
               "WHERE user_id=" . $_GET['u'] .
               " AND ml_id=" . $_GET['ml'];
        mysql_query($sql, $conn);

        $sql = "SELECT listname FROM ml_lists " .
               "WHERE ml_id=" . $_GET['ml'];
        $result = mysql_query($sql, $conn);

        $row = mysql_fetch_array($result);
        $listname = $row['listname'];

        $sql = "SELECT * FROM ml_users " .
               "WHERE user_id='" . $_GET['u'] . "'";
        $result = mysql_query($sql, $conn);
        $row = mysql_fetch_array($result);
        $firstname = $row['firstname'];
        $email = $row['email'];

        $url = "http://" . $_SERVER['HTTP_HOST'] .
               dirname($_SERVER['PHP_SELF']) .
               "/remove.php?u=" . $_GET['u'] .
               "&ml=" . $_GET['ml'];

        $subject = 'Mailing List Subscription Confirmed';
        $body = "Hello " . $firstname . ",\n" .
                "Thank you for subscribing to the " .
                $listname . " mailing list. Welcome!\n\n" .
                "If you did not subscribe, please accept our " .
                "apologies.\n".
                "You can remove this subscription immediately by ".
                "visiting the following URL:\n" . $url;

        $mailmsg = new SimpleMail();
        $mailmsg->send($email,$subject,$body,$headers);

        $redirect = "thanks.php?u=" . $_GET['u'] . "&ml=" .
                    $_GET['ml'] . "&t=s";
      } else {
        $redirect = 'user.php';
      }
      break;

    default:
      $redirect = 'user.php';
  }
}

header('Location: ' . $redirect);
?>


please note,

1. the line below is the line of 37:

 if (!mysql_num_rows($result)) {

2. the line below is the line of 132:

header('Location: ' . $redirect);

please help

James



Reply With Quote
  #2 (permalink)  
Old December 6th, 2006, 11:42 AM
Authorized User
 
Join Date: Nov 2006
Location: Bhopal, MP, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to talk2leo
Default

try it like
1. if(musql_num_rows($result)<1){///code
}else{
2.
heager("Location: $redirect");

it should work

Success is Never Ending,,Filure is Never Fimal
Reply With Quote
  #3 (permalink)  
Old December 6th, 2006, 11:45 AM
Authorized User
 
Join Date: Nov 2006
Location: Bhopal, MP, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to talk2leo
Default

2.header("Location: $redirect");

not header ok
i made typing mistake

Success is Never Ending,,Filure is Never Fimal
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid argument supplied for foreach() codejockey Beginning PHP 4 September 24th, 2010 04:40 AM
mysql_num_rows() => Giving Error? Cybot MySQL 4 September 12th, 2006 01:07 PM
fwrite(): supplied argument is not a valid stream Adam H-W Beginning PHP 3 January 20th, 2006 02:09 AM
Warning: mysql_num_rows()... mgway Beginning PHP 3 July 11th, 2005 08:17 PM
Tablename argument chloe Access VBA 7 March 24th, 2004 12:20 AM



All times are GMT -4. The time now is 08:10 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.