PHP Logic Question
Posted: Fri Apr 09, 2010 10:10 pm
This is more of a logic question, then a solve this specific error problem because I'm sure it's going to come up again in the development of my website at http://www.jerrysmith.co.cc (man I love free plugs for my site
).
Okay so I have a functions.php file filled with a bunch of functions that I use across all pages of my website (databaseconnect, siteoption, ect, ect) but I'm running into a problem with one called getUserInfo. Through the login script required to view the page, it sets the username, among other data, into a session. I'm trying to run that session through the following php function and return the array to the page where I'll run it through a while statement to get the data into the page, but I'm having trouble
function getUserInfo
html/php form
Again I'm not looking for a specific fix, more of a overall answer so I can implement the function throughout the website later. "Give a man a fish he eats for a day, teach a man to fish he eats for a lifetime"
Okay so I have a functions.php file filled with a bunch of functions that I use across all pages of my website (databaseconnect, siteoption, ect, ect) but I'm running into a problem with one called getUserInfo. Through the login script required to view the page, it sets the username, among other data, into a session. I'm trying to run that session through the following php function and return the array to the page where I'll run it through a while statement to get the data into the page, but I'm having trouble
- Getting the username to run through the function (username required text displays)
- Getting the username metadata to be inserted into the hidden values of the form through a php echo (I know how to script it it's just not working)
Here is the getUserInfo function and the form where the UserInfo has to be displayed.Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in /home/jerrysmi/public_html/account/famchat/index.php on line 234
function getUserInfo
Code: Select all
function getUserInfo($username = ' '){
database_connect('Admin');
if(strlen($username > 0)) {
$sql = "SELECT * FROM `cmsusers` WHERE `username` ='$username'";
$result = mysql_query($sql);
/* Return result array */
$_SESSION['dbarray'] = mysql_fetch_array($result);
}
else {
$_SESSION['dbarray'] = 'Username required';
}
mysql_close();
} // getUserInfo
Code: Select all
<fieldset>
<p style="margin-left:auto; margin-right:auto; text-align:center">
<legend>Add Comment</legend>
<?php
$username = $_SESSION['myusername'];
getUserInfo($username);
while ($dbarray = mysql_fetch_array($_SESSION['dbarray'])) {?>
<form name="chat" action="script.php" method="post">
<input type="hidden" name="famchat_author" value="<?php echo $dbarray['firstname'] . ' ' . $dbarray['surname'] ?>" />
<input type="hidden" name="famchat_timestamp" value="<?php echo(time(u)); ?>" />
<h3 id="nobottom">Your comment:</h3><br />
<textarea name="famchat_comment" id="MCEEditor" rows="10" style="width:100%"></textarea>
<br />
<input type="submit" name="submit" style="margin:0;padding:2px 5px;color:#666666" />
<input type="reset" style="margin:0;padding:2px 5px;color:#666666" />
</form>
<?php } unset($_SESSION['dbarray']); ?>
</fieldset>