Jump to content

Recommended Posts

Hi guys. I am having a little trouble here.

 

I have coded a very simple login script yet I'm having trouble displaying an error message or restricting access if the MySQL query does not exactly match the users input.

 

Here is the part of the code I'm having trouble manipulating:

 


$data = mysql_query("SELECT * FROM financialone WHERE id = '$unique_id' and First_Name = '$fname' ") or die(mysql_error());

$fetch = mysql_fetch_array( $data );

$output = $fetch['Surname'];

 

Now the code works as when I type in the the details of the two columns that match the row, I can 'fetch' any data from that row. My problem is that when I do not type the correct details, nothing happens, it simply doesn't fetch the data.

 

How can I have it so that someone is either directed to another page, restricted access to a page or the page is displayed again with error messages?

 

I'm suspecting it's a simple if statement, yet I have no idea how to cod it.

 

So basically how do I say to php and mysql:

if {
data matches;
fetch data;
}
if{
data doesn't match;
display error, redirect, restrict;
}

 

Thank you for any help with this.

 

Regards,

 

Damien.

 

Sadly, that hasn't worked.

 

Here's what I did


if ($num >= 0){ 
$fetch = mysql_fetch_array( $data );
} else {
echo "Wrong Login Information";
}

 

It didn't do anything though, the data just wasn't fetched. There's no error messages either, even though it's not retrieving data.

 

Does anyone have any other solutions?

 

I need a match if statement.

 

like:

if { 
$comlumn1 and $column2 retrieve data;
login;
}
else{
echo "error logging in";
}

 

Any other thoughts?

 

Thanks for your help.

 

 

I have no idea.

 

Is there no other way to directly ask for the two columns to match?

 

I'll keep trying with the above script and search around. Hopefully I'll get it sorted soon.

 

Thanks for your input.

Yes, now I know what you mean.

 

It prints

 

SELECT * FROM financialone WHERE id = 'myid' and First_Name = 'Damien'

 

------

I can then fetch data from any column in that row. But that isn't the problem. The problem is finding a way to say - if 'myid' and 'Damien' are not BOTH present in that row THEN fail.

 

Any ideas?

 

Thanks.

change this

if ($num >= 0){ 
$fetch = mysql_fetch_array( $data );
} else {
echo "Wrong Login Information";
}

 

to

if ($num > 0){ 
$fetch = mysql_fetch_array( $data );
} else {
echo "Wrong Login Information";
}

so if 1 or row is returned fetch the data

else if no row is returned print the error message

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.