Jump to content

mysql_fetch_assoc() error help please


Rifts

Recommended Posts

after submitting my dropdown box form i get Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\homepage\google.php on line 146

 

the php form im getting $_POST from (the dropdown box):

 

<form id="loginForm" name="drop" method="post" action="google.php">
<?php
      mysql_connect('localhost','root','');
      if (!isset($_POST['email'])) {
        $q = mysql_query("SELECT * FROM members");
        echo "<select name='email'>";
        while ($row = mysql_fetch_assoc($q)) {
          echo "<option value='{$row['email']}'>{$row['firstname']}</option>";
        }
        echo "</select>";
      }else {
        print_r($_SERVER);
        print_r($_POST);
      }
    ?>
<input type="submit" name="submit" value="Submit Now" />

 

and here is the php file which is giving my the error:

<?php
      mysql_connect('localhost','root','');
      if (!isset($_POST['email'])) {
        $q = mysql_query("SELECT * FROM members");
        echo "<select name='email'>";
        while ($row = mysql_fetch_assoc($q)) {
          echo "<option value='{$row['email']}'>{$row['firstname']}</option>";
        }
        echo "</select>";
      }else {
        $row = mysql_fetch_assoc(mysql_query("SELECT * FROM members WHERE firstname = '{$_POST['email']}'"));
    
        print_r($row);
      }
    ?>

 

like 146 is

$row = mysql_fetch_assoc(mysql_query("SELECT * FROM members WHERE firstname = '{$_POST['email']}'"));

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/
Share on other sites

<?php
      mysql_connect('localhost','root','');
      mysql_select_db("clients");

      if (!isset($_POST['email'])) {
        $q = mysql_query("SELECT * FROM members");
        echo "<select name='email'>";
        while ($row = mysql_fetch_assoc($q)) {
          echo "<option value='{$row['email']}'>{$row['firstname']}</option>";
        }
        echo "</select>";
      }else {
        $row = mysql_fetch_assoc(mysql_query("SELECT * FROM members WHERE firstname = '{$_POST['email']}'"));
    
        print_r($row);
      }
    ?>

 

Should do it.

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.