Sorry Dave, it might help to add a space before WHERE in the query
string as follows:
// Set the query string to a PHP variable
$Query = “SELECT * FROM " . $TableName . " WHERE username='” .
$username . “'”;
On Dec 21, 2009, at 10:14 AM, Mike B wrote:
Dave,
There are different ways to get information from a database but what
you are trying wouldn’t work because your code would not do
anything are you not getting any errors from it? anyway…I think the best thing to do is to get a book like PHP and MySQL Web
Development, ISBN 0-672-32525-X, there are several mistakes you are
making that would say you should read something on php and MySql.You can’t write query string like you have, the ‘=’ and the ‘,’ are
outside the string for example:‘firstname’=$firstname, ‘surname’=$surname
nor can you write a string like:
“Welcome back $firstname.” ".$surname"
you need to use a ‘.’ to join two php strings or you might get away
with “Welcome back $firstname $surname” but I personally would
use 'Welcome back ’ . $firstname . ‘ ’ . $surname; or 'Welcome
back ’ . $firstname . ’ ’ . $surname;If your query string was right then it wouldn’t do anything anyway
as you are not making the query properly, not sure what you where
using as a guide on this but change to something else… the book
above is money well spent.The following line is passing a query string to a variable
$Query=“SELECT * FROM $TableName WHERE username=‘$username’”;The following line using the query string in making a query to the
database, so in the this case there is no connection between your
query string and what you are using to make the query:$Result=mysql_db_query (‘firstname’=$firstname, ‘surname’=$surname);
Try using the following code:
This is by no means complete but it adds a little checking for
failing gracefully, you would need to add some security relative to
how secure you want your database and the pages to be that are being
accessed from giving entry to someone.if ($TableName && $username) { // Make the database connect here // NOTE: You need to place the include to your connection code or make the connection here // Set the query string to a PHP variable $Query = "SELECT * FROM " . $TableName . "WHERE username='" . $username . "'"; // Perform query $Result = @mysql_query($Query) or die ($Query, __LINE__, mysql_error()); $num_rows = @mysql_num_rows($Result); if ($num_rows==1) { // Are there any matches $row = mysql_fetch_array($the_rslt); $surname = stripslashes($row['surname']); $firstname = stripslashes($row['firstname']); print("Welcome back " . $firstname . " " . $surname); } else { print("No user listed"); } // Close the connection: mysql_close(Could have the conection here, depends on how you make the connection). mysql_close(); } else { print("No TableName or username"); }
HTH
On Dec 21, 2009, at 12:43 AM, DeltaDave wrote:
OK I am getting there but what I am trying to do is output the
$username that is currently being displayed as the full name of the
user which is stored in the table as firstname and surnameWhat I currently have is
{ print("Welcome back $username"); }
Instead I think I want something like
{ $Query="SELECT * FROM $TableName WHERE username='$username'"; $Result=mysql_db_query ('firstname'=$firstname, 'surname'=$surname); print("Welcome back $firstname." ".$surname"); }
But of course it doesn’t work.
Please point me in the right direction - I know this is pretty
basic but I have brain freeze to go with our wintry weather.David
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options