Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 5th, 2006, 11:50 AM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default $sql not returning results, this cant be this hard

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
Code:
<input type="submit" name="kt_login1" id="kt_login1" value="Login" />
In the page that opens as a result of loggin in:
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>
In the page that is to contain the update record form:
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(); ?>
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.

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 really appreciate some direction here. Many thanks in advance.






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL returning odd results jakeone SQL Language 1 November 13th, 2006 05:07 AM
Stored Procedures returning no results to access 50bmg_de SQL Server 2000 5 February 21st, 2006 04:58 AM
Temp Table Query not returning results to page rlull SQL Server 2000 1 November 15th, 2005 04:50 PM
Query returning 0 results although SQL is valid aquagal77 Classic ASP Databases 4 March 31st, 2005 11:06 AM
Query not returning correct results from database Jams30 PHP Databases 5 November 7th, 2003 08:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.