I am new to php and have run into a brick wall. Any help would be appreciated
I need an update form on a page that will look to see if anything is entered in the users "welcome" field in their record and, if there is content, display it for editing / updating.
If there is nothing in the user's field enter "My Default Text" and use that to update the user's welcome field in their record.
Thus far I have the following.
In the login form
In the page that opens as a result of logging in:Code:<input type="submit" name="kt_login1" id="kt_login1" value="Login" />
In the page that is to contain the update record form:PHP Code:<? session_start();
if (isset($_POST['kt_login1'])):
$_SESSION['kt_login_user'] = $_POST['kt_login_user'];
$_SESSION['kt_name'] = $_POST['kt_name'];
endif;
?>
<p>Hello <? echo $_SESSION['kt_name'] ?> Choose a link to update a part of your records...</p>
I have created 2 users, one with content in the welcome field of their record and the other with a blank welcome field in the welcome field of their record.PHP Code:<? session_start();
if (!isset($_SESSION['kt_login_user'])):
$_SESSION['kt_login_user'] = "Anonymous";
$_SESSION['kt_name'] = $_POST['kt_name'];
$_SESSION['kt_welcome'] = $_POST['kt_welcome'];
endif;
?>
<p>Hello <? echo $_SESSION['kt_name'] ?> Yada yadda...</p>
<?php $sql = "SELECT 'welcome' FROM `users` WHERE `id` = $kt_login_user";
$qry = mysql_query($sql);
if(@mysql_num_rows($qry) > 0)
{
while($r = mysql_fetch_array($qry))
{
$kt_welcome = $r[1];
}
}
else
{
$kt_welcome = "My default text";
}
?>
<textarea name="welcome" cols="80" rows="20"><?php echo $_SESSION['kt_welcome']; ?></textarea>
<?php mysql_close(); ?>
What is happening at the moment is
1 - The "echo $_SESSION['kt_name" is returning the name of the logged in user (as expected)
2 - the only thing that is being returned in the textarea is My default text. The contents of the user with pre-existing data in his welcome field is not being returned in spite of being logged in.
I am coming to honestly believe that PHP was developed to drive me nuts.
I would appreciate some direction here. Many thanks in advance.



Reply With Quote


Bookmarks