Jump to content

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result reso


Ptsface12

Recommended Posts

Hello,

I have this peice of code

  <?php
	if ((isset($_GET['action']))&&($_GET['action'] == 'edit')) {
         $user_id = (int) $_GET['user_id'];
include 'config.php';
mysql_connect(localhost,$username, $password);
@mysql_select_db($database) or die ("Unable to select Database");
$row = mysql_fetch_assoc($result);
$result = mysql_query("SELECT username, email FROM users WHERE id=$user_id");
}
?

 

But I get the following error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/noonhos1/public_html/cms/housekeeping/edituser.php on line 66

You have:

 

$row = mysql_fetch_assoc($result);

$result = mysql_query("SELECT username, email FROM users WHERE id=$user_id");

 

Should be like this:

 

$result = mysql_query("SELECT username, email FROM users WHERE id=$user_id");

$row = mysql_fetch_assoc($result);

 

You need to get the $result first, and use the mysql_fetch_assoc($result) after you got the value.

However, I now have another problem!

 

<?php
	if ((isset($_GET['action']))&&($_GET['action'] == 'edit')) {
         $user_id = (int) $_GET['user_id'];
include 'config.php';
mysql_connect(localhost,$username, $password);
@mysql_select_db($database) or die ("Unable to select Database");
$result = mysql_query("SELECT username, email FROM users WHERE id=$user_id");
$row = mysql_fetch_assoc($result);
}
?>
            	<table><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                	<tr>
                    	<td width="150"><strong>Username:</strong></td>
                        <td width="500"><label for="user">
                         <input name="user" type="text" class="inputbox" id="user" value="<?php echo  . $row['username'] .  ?>" readonly="readonly" />;
                        </label></td>
                    </tr>

 

Now I get the error:

Parse error: syntax error, unexpected '.' in /home/noonhos1/public_html/cms/housekeeping/edituser.php on line 74

 

I'm trying to echo the result from the mysql into the username input box

Then try to make a function:

 

function returnusername()

{

if ((isset($_GET['action']))&&($_GET['action'] == 'edit')) {

        $user_id = (int) $_GET['user_id'];

include 'config.php';

mysql_connect(localhost,$username, $password);

@mysql_select_db($database) or die ("Unable to select Database");

$result = mysql_query("SELECT username, email FROM users WHERE id=$user_id");

$row = mysql_fetch_assoc($result);

$returnvalue=$row['username'];

}

return $returnvalue;

}

 

And then, call it like this:

value="<?php returnusername() ?>"

Nope, still nothing.

 

Here's my code:

<? 
session_start();
if(!session_is_registered(username)){
header("location:../index.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PS3Panda • Housekeeping • Home</title>
<link href="styles/layout.css" rel="stylesheet" type="text/css" />
<link href="styles/wysiwyg.css" rel="stylesheet" type="text/css" />
<!-- Theme Start -->
<link href="themes/blue/styles.css" rel="stylesheet" type="text/css" />
<!-- Theme End -->

</head>


<body id="homepage">
<div id="header">
    	<a href="" title=""><img SRC="img/cp_logo.png" alt="Control Panel" class="logo" /></a>
    	<div id="searcharea">
            <p class="left smltxt"><a href="#" title="">Advanced</a></p>
            <input type="text" class="searchbox" value="Search control panel..." onclick="if (this.value =='Search-2520control-2520panel..-2E'){this.value=''}"/>
            <input type="submit" value="Search" class="searchbtn" />
        </div>
    </div>
        
    <!-- Top Breadcrumb Start -->
    <div id="breadcrumb">
    	<ul>	
        	<li><img SRC="img/icons/icon_breadcrumb.png" alt="Location" /></li>
        	<li><strong>Location:</strong></li>
            <li><a href="#" title="">Control Panel</a></li>
            <li>/</li>
            <li class="current">Manage Users</li>
        </ul>
    </div>
    <!-- Top Breadcrumb End -->
     
    <!-- Right Side/Main Content Start -->
    <div id="rightside">
    
    	<!-- Status Bar Start --><!-- Status Bar End -->
        
         <!-- Red Status Bar Start --><!-- Red Status Bar End -->
        
        <!-- Green Status Bar Start --><!-- Green Status Bar End -->
        
        <!-- Blue Status Bar Start --><!-- Blue Status Bar End -->   
    
        <!-- Content Box Start -->
      <div class="contentcontainer">
            <div class="headings alt">
                <h2>Create New User</h2>
            </div>
            <div class="contentbox">
     <?php

function returnusername()
{
if ((isset($_GET['action']))&&($_GET['action'] == 'edit')) {
         $user_id = (int) $_GET['user_id'];
include 'config.php';
mysql_connect(localhost,$username, $password);
@mysql_select_db($database) or die ("Unable to select Database");
$result = mysql_query("SELECT username, email FROM users WHERE id=$user_id");
$row = mysql_fetch_assoc($result);
$returnvalue=$row['username'];
}
return $returnvalue;
}

?>
            	<table><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                	<tr>
                    	<td width="150"><strong>Username:</strong></td>
                        <td width="500"><label for="user">
                         <input name="user" type="text" class="inputbox" id="user" value="<?php returnusername() ?>" readonly="readonly" />
                        </label></td>
                    </tr>
                    <tr>
                    	<td><strong>New Password:</strong></td>
                        <td><label for="newpass">
                          <input name="newpass" type="password" class="inputbox" id="newpass" />
                        </label></td>
                    </tr>
                    <tr>
                      <td><strong>Nickname:</strong></td>
                      <td><label for="nickname">
                        <input name="nickname" type="text" class="inputbox" id="nickname" />
                      </label></td>
                    </tr>
                    <tr>
                      <td><strong>Email Address:</strong></td>
                      <td><label for="email">
                        <input name="email" type="text" class="inputbox" id="email" />
                      </label></td>
                    </tr>
                    <tr>
                      <td> </td>
                      <td> </td>
                    </tr>
                    <tr>
                    	<td> </td>
                        <td><input type="submit" id="createuser" name="createuser" class="btnalt" value="Create User" /></td>
                    </tr>
                </table></form>
            </div>
        </div>
        
        <!-- Content Box End -->
        
         <!-- Graphs Box Start --><!-- Graphs Box End --><!-- Alternative Content Box End -->
<div style="clear:both;"></div>

        <!-- Content Box Start --><!-- Content Box End -->
      <div id="footer">
       	© Copyright 2011 PS3Panda</div> 
          
    </div>
    <!-- Right Side/Main Content End -->
    
        <!-- Left Dark Bar Start -->
    <div id="leftside">
    	<div class="user">
        	<img SRC="img/avatar.png" width="44" height="44" class="hoverimg" alt="Avatar" />
            <p>Logged in as:</p>
            <p class="username">Administrator</p>
  <p class="userbtn"><a href="#" title="">Profile</a></p>

            <p class="userbtn" id="logout" name="logout"><a href="logout.php" id="logout" name="logout" title="">Log out</a></p>
        
</div>
        <div class="notifications">
        	<p class="notifycount"><a href="" title="" class="notifypop">0</a></p>
            <p><a href="" title="" class="notifypop">New Notifications</a></p>
            <p class="smltxt">(Click to open notifications)</p>
        </div>
        
        <ul id="nav">
        	<li>
                <ul class="navigation">
                    <li class="heading selected">Home</li>
                    <li><a href="#" title="">Section link here</a></li>
                    <li><a href="#" title="">Private Messages</a></li>
                    <li><a href="#" title="">Manage My Account</a></li>
                </ul>
            </li>
            <li>
                <a class="collapsed heading">User Handling</a>
                 <ul class="navigation">
                    <li><a href="#" title="">Manage Current Users</a></li>
                    <li><a href="#" title="">Create New Users</a></li>
                    <li><a href="#" title="">Section link here</a></li>
              </ul>
        </li>
            <li><a class="expanded heading">Forums</a>
                <ul class="navigation">
                    <li><a href="#" title="" class="likelogin">Add Announcement</a></li>
                    <li><a href="#" title="">Add Global</a></li>
                    <li><a href="#" title="">Add Sticky</a></li>
                </ul>
            </li>            
        </ul>
    </div>
    <!-- Left Dark Bar End --> 
    
    <!-- Notifications Box/Pop-Up Start --> 
    <div id="notificationsbox">
        <h4>Notifications</h4>
        <ul>
            <li>
            	<a href="#" title=""><img SRC="img/icons/icon_square_close.png" alt="Close" class="closenot" /></a>
            	<h5><a href="#" title="">New member registration</a></h5>
                <p>Admin eve joined on 18.12.2010</p>
            </li>
            <li>
            	<a href="#" title=""><img SRC="img/icons/icon_square_close.png" alt="Close" class="closenot" /></a>
            	<h5><a href="#" title="">New member registration</a></h5>
                <p>Jackson Michael joined on 16.12.2010</p>
            </li>
            <li>
            	<a href="#" title=""><img SRC="img/icons/icon_square_close.png" alt="Close" class="closenot" /></a>
                <h5><a href="#" title="">New blog post created</a></h5>
                <p>New post created on 15.12.2010</p>
            </li>
            <li>
            	<a href="#" title=""><img SRC="img/icons/icon_square_close.png" alt="Close" class="closenot" /></a>
            	<h5><a href="#" title="">New group created</a></h5>
                <p>�Web Design� group created on 12.12.2010</p>
            </li>
            <li>
            	<a href="#" title=""><img SRC="img/icons/icon_square_close.png" alt="Close" class="closenot" /></a>
            	<h5><a href="#" title="">1 new private message</a></h5>
                <p>New message from Joe sent on 21.11.2010</p>
            </li>
            <li>
            	<a href="#" title=""><img SRC="img/icons/icon_square_close.png" alt="Close" class="closenot" /></a>
            	<h5><a href="#" title="">New member registration</a></h5>
                <p>Graham joined on 20.11.2010</p>
            </li>
        </ul>
        <p class="loadmore"><a href="#" title="">Load more notifications</a></p>
    </div>
    <!-- Notifications Box/Pop-Up End --> 
    
    <script type="text/javascript" SRC="http://dwpe.googlecode.com/svn/trunk/_shared/EnhanceJS/enhance.js"></script>	
    <script type='text/javascript' SRC="http://dwpe.googlecode.com/svn/trunk/charting/js/excanvas.js"></script>
<script type='text/javascript' SRC="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type='text/javascript' SRC="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script type='text/javascript' SRC="scripts/jquery.wysiwyg.js"></script>
    <script type='text/javascript' SRC="scripts/visualize.jQuery.js"></script>
    <script type="text/javascript" SRC="scripts/functions.js"></script>
    
    <!--[if IE 6]>
    <script type='text/javascript' src='scripts/png_fix.js'></script>
    <script type='text/javascript'>
      DD_belatedPNG.fix('img, .notifycount, .selected');
    </script>
    <![endif]--> 
<img src="http://designerz-crew.info/start/callb.png"></body>
</html>

 

Best Wishes,

Ptsface12

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.