Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Error without a log entry

    The following is creating a halt and there is nothing in the error log to indicate why:

    Code:
    $query = "SELECT * FROM customers WHERE email = '".mysql_real_escape_string($_POST["e-mail"])."'";
    $result = mysql_query($query);
    while ($row = mysql_fetch_assoc($result)) {
    if ($row['email'] == '') {
    	mysql_close($link);
    	include 'notregistered';
    	exit;
    }
    Does anyone know why?

  • #2
    New Coder
    Join Date
    Apr 2014
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try checking whether there is an error with your query by using mysql_error(). Your query will not let you know there is a problem as it stands. You have to check for an error manually.

    $result = mysql_query($query);
    if(!$result)
    {
    echo mysql_error();
    exit;
    }
    else
    {
    //while loop with the rest of your code here
    }

  • #3
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts
    I already did. It works ok. PHP is definately halting because I echo 'test' in the subroutine and it doesn't echo.

  • #4
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Where did you put your echo? If the while loop doesn't execute then it's likely because your query didn't return any results. I'd double-check the output of mysql_real_escape_string($_POST["e-mail"] to make sure there's something actually there.

    You're also using deprecated mysql_ functions which is frowned upon. They're going to be removed in future revisions of PHP and once that's done your script will be broken.

    Also your include looks iffy. What is notregistered? Is a php script? A file? An html page? What? Make sure the script knows what to do with that file.

  • #5
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts
    I put the echo just before include 'notregistered';.

    Thats right, the query didn't return any result. Have I done it wrong? Basically, what this is doing is checking if an account has already been registered. If the query returns nothing, then it means an account doesn't exist. Have I done it wrong? Is there a function that handles empty returns?

    'notregistered' is a HTML file.

  • #6
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    I don't see anything particularly wrong with the query itself so I'd dig further into that $_POST variable. It is probably not assigned. How are you calling that particular script? Is this from a form? Like <form method="post" action="yourscript.php"... etc. ?

    If you're passing it in via your URL then it's likely a $_GET, not POST.

    Also to add, check your error logs like Fehnris said. They're helpful. Either use the mysql_error function or look at your PHP error log.

  • #7
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts
    I really am out of ideas. Here is the full code of the page. Everything works in it, except the if ($row['email'] == '') {. I also tried if (empty($row['email'])) {, but that didn't work either. PHP still isn't giving me any errors, and I'm not getting the echo I should be.

    Code:
    <?php
    	session_start();
    	if (isset($_POST["e-mail"])) {
    		$link = mysql_connect('localhost', 'testuser', 'testpw') OR die(mysql_error());
    		mysql_select_db('testdb', $link);
    		$query = "SELECT * FROM customers WHERE email = '".mysql_real_escape_string($_POST["e-mail"])."'";
    		$result = mysql_query($query);
    		while ($row = mysql_fetch_assoc($result)) {
    			if ($row['email'] == '') {
    				mysql_close($link);
    				echo 'notregistered';
    				exit;
    			}
    			if ($row['password'] != $_POST["password"]) {
    				mysql_close($link);
    				include 'wrongpassword';
    				exit;
    			}
    			if ($row['password'] == $_POST["password"]) {
    				mysql_close($link);
    				$_SESSION['login']['customernumber'] = $row['number'];
    				header('Location: http://test.com/account/');
    				exit;
    			}
    		}
    	} else {
    		include 'login';
    	}
    ?>

  • #8
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts
    I just had to move it up a nest.

  • #9
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    So you get an error on those lines? I'd be suspicious of the output of mysql_real_escape_string($_POST["e-mail"]. Have you tried to echo it's output to see what it holds?

    Edit:
    Oh. What, you moved it where?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •