how I can retain the preset values in $row

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

how I can retain the preset values in $row

Post by cneeds »

Hi

I'm new here and to php!

In the code
$row['user_first_name'] = $userID;
$row['user_last_name'] = '. Please complete this form to register';
$result = mysqli_query($link, 'SELECT * FROM users_table WHERE user_ID="' . $userID . '" And user_entity="' . $entity . '" And user_password="' . $password . '"');
if ($result) {
$row = mysqli_fetch_array($result);
}

$row seems to get cleared even when $result is false, so I never see 'Please complete this form to register'.

Please show me how I can retain the preset values in $row if nothing is returned by the sql query.

Best regards

Chris
jazzercising011
Forum Newbie
Posts: 9
Joined: Tue Sep 14, 2010 4:47 am

Re: how I can retain the preset values in $row

Post by jazzercising011 »

you have got this thing all out of whack! You cant really assign things to $row[' '] because once you run the query, it will clear itself. Try using this format instead.

$result = mysqli_query($link, 'SELECT * FROM users_table WHERE user_ID="' . $userID . '" And user_entity="' . $entity . '" And user_password="' . $password . '"');

while($row = mysql_fetch_array($result))
{
$blah = $row['blah'];
}
PradeepKr
Forum Newbie
Posts: 14
Joined: Wed Aug 11, 2010 8:29 am

Re: how I can retain the preset values in $row

Post by PradeepKr »

Why are you using same variable before the SQL execution and also for extracting result?

Use differnt variables,

Code: Select all

$var['user_first_name'] = $userID;
$var['user_last_name'] = '. Please complete this form to register';
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

Re: how I can retain the preset values in $row

Post by cneeds »

@ PradeepKr
Why are you using same variable before the SQL execution and also for extracting result?
The idea was, if the query didn't find anything, $row would be loaded with alternate text to be displayed.

I think I'm having a problem with unsuccessful query, successful query that didn't find anything and successful query that finds a row.

Are these three different conditions?

What does

Code: Select all

   if ($result = mysqli_query($link, 'SELECT * FROM sof4prof_users WHERE user_ID="' . $userID . '" And user_entity="' . $entity . '" And user_password="' . $password . '"')) {
return if
a) the query doesn't find anything
b) the query has bad syntax
?

Chris
Post Reply