Jump to content

Select Query


supermerc

Recommended Posts

Hey,

 

I have my login script, and I added something to make it check if a few rows in the users table are empty and if they are the displays an alert box and redirects them somewhere and if they arnt empty it redirects them to the members page, but for some reason it doesnt see it as empty even if its empty.

 

here is my code

 

<?php
$query = mysql_query("select account, pass, loginupdated from users where owname='".$_SESSION['s_username']."'  LIMIT 1");
  if (mysql_num_rows($query) != 1) {

echo '<script type="text/javascript">

alert("Our records show us that you have yet to submit your account login, please do so now.");

location = "setpass.php";

</script>';


}
else
{
		header("Location: members.php"); 

	        exit();

}
?>

Link to comment
https://forums.phpfreaks.com/topic/61902-select-query/
Share on other sites

Are you trying to see if account, pass, and loginupdated are empty in a row that already exists?  If so, your method will not work.  If a row exists with the owname set, even if those fields are empty, a result will still be returned, hence mysql_num_rows() == 1.

 

You'll have to check if the fields are NULL or their default value, depending on how you've set up your table.

Link to comment
https://forums.phpfreaks.com/topic/61902-select-query/#findComment-308261
Share on other sites

Any number of ways -- try something like:

 

<?php

$query = "SELECT account IS NULL AND pass IS NULL AND loginupdated IS NULL AS incomplete FROM users WHERE owname='{$_SESSION['s_username']}' LIMIT 1";

$result = mysql_query($query) or die mysql_error();

if ($result && mysql_num_rows($result) && mysql_result($result,0) == 1):
?>
<script type="text/javascript">
alert("Our records show us that you have yet to submit your account login, please do so now.");
location = "setpass.php";
</script>
<?php
else header('Location: members.php');
endif;

?>

Link to comment
https://forums.phpfreaks.com/topic/61902-select-query/#findComment-308289
Share on other sites


<?php

$query = "SELECT account IS NULL AND pass IS NULL AND loginupdated IS NULL AS incomplete FROM users WHERE owname='{$_SESSION['s_username']}' LIMIT 1";

$result = mysql_query($query) or die (mysql_error());

if ($result && mysql_num_rows($result) && mysql_result($result,0) == 1) {
?>
<script type="text/javascript">
alert("Our records show us that you have yet to submit your account login, please do so now.");
location = "setpass.php";
</script>
<?php
} else {
header('Location: members.php');
}

?>

Link to comment
https://forums.phpfreaks.com/topic/61902-select-query/#findComment-308327
Share on other sites

Try this it may work. No guarantee's. I'd realy need to see the sign in HTML and the feilds in the database.

$query = mysql_query("select account, pass, loginupdated from users where owname='".$_SESSION['s_username']."'  LIMIT 1");
  if (mysql_num_rows($query) < 1) {

echo '<script type="text/javascript">

alert("Our records show us that you have yet to submit your account login, please do so now.");

location = "setpass.php";

</script>';


}
else
{
		header("Location: members.php"); 

	        exit();

}
?>

Link to comment
https://forums.phpfreaks.com/topic/61902-select-query/#findComment-308343
Share on other sites

Or put a colon after else in the original.

else: header('Location: members.php');

 

Apologies Wildbug, I'm not used to your syntax :)

 

I like the alternative syntax when dropping in and out of PHP between code so I don't have to look for a single little curly brace hiding in that mess -- I can just look for an "endif;" or whatever.

 

supermerc,

Maybe it's time you described your SQL table.  Will ALL of those fields be empty or just one or two of them?  Are any of those fields defined NOT NULL?

Link to comment
https://forums.phpfreaks.com/topic/61902-select-query/#findComment-308870
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.