Jump to content
Larry Ullman's Book Forums

StephenM

Members
  • Posts

    59
  • Joined

  • Last visited

Posts posted by StephenM

  1. I entered in the below code into terminal and got the error below in red.  Not sure where the error is?  I double checked it but operating on minimal sleep so maybe a dumb error...

    INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES    
    ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
    ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()),
    ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()),
    ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
    
    
    

    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES

    ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),

    ('Paul'' at line 1

     

    I tested this code and it worked for me without changing your code.

    So I'm not sure why either.

  2. I am not sure what is wrong either but here are some suggestions of things to have a second look at:

     

    See at the end of your code, an extra bracket looks out of place and I wonder is it messing things up?

    	exit();
    }else{//IF THE EMAIL ADDRESS IS ALREADY REGISTERED
    echo '<p class="error">The email address is not acceptable because it is already registered</p>';
    }
    	}
    

    Another security issue consider is lack of filtering of the email variable although I don't think this is your current problem

    (you didn't use real escape string function here)

    	// Check for an email address:
    	if (empty($_POST['email'])) {
    		$errors[] = 'You forgot to enter your email address.';
    	} else {
    		$e = trim($_POST['email']);
    	}
    

    And finally, it could really help to follow Larry's advice and see what the query is.

    To help that, you could temporarily remove the header and exit functions yourself so the data is echoed to the page and you can see it without the page moving off somewhere else.

    Perhaps something along these lines:

    	if (empty($errors)) { // If everything is OK
    
    //DETERMINE WHETHER THE EMAIL ADDRESS HAS ALREADY BEEN REGISTERED	
    
    $q = "SELECT user_id FROM users WHERE email = '$e'";
    
    		$result = mysqli_query ($dbcon, $q);
    
    
    echo '<h1>'; // TEMPORARY TO SEE QUERY - remove this line later
    echo $q; // TEMPORARY TO SEE QUERY - run this query in phpmyadmin and remove this line later
    echo '</h1>'; // TEMPORARY TO SEE QUERY - remove this line later
     
    if (mysqli_num_rows($result) == 0){//The mail address has not been registered already therefore...	
    
    // Register the user in the users table
    
    		$q = "INSERT INTO users (user_id, title, fname, lname, email, psword, registration_date, uname, class, addr1, addr2, city, county, pcode, phone, paid) VALUES (' ', '$title', '$fn', '$ln', '$e', SHA1('$p'), NOW(), '$uname', '$class', '$ad1', '$ad2', '$cty', '$cnty', '$pcode', '$ph', '$pd' )";
    		
    		$result = @mysqli_query ($dbcon, $q); // Run the query.
    
    		if ($result) { // If it ran OK.
    		header ("location: register-thanks.php"); 
    		exit();
    		} else { // If it did not run OK
    		// Error message:
    			echo '<h2>System Error</h2>
    			<p class="error">Registration failed because of a system error. We apologize for the inconvenience.</p>'; 
    			// Debugging message:
    			echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>';
    		} // End of if ($result)
    		mysqli_close($dbcon); // Close the database connection
    		// Include the footer and stop the script
    		include ('footer.php'); 
    		exit();
    }
    else
    {
    //IF THE EMAIL ADDRESS IS ALREADY REGISTERED
    echo '<p class="error">The email address is not acceptable because it is already registered</p>';
    		echo '<h2>Error!</h2>
    		<p class="error">The following error(s) occurred:<br>';
    foreach ($errors as $msg)
     {
     // Print each error.
    			echo " - $msg<br>\n";
    }
    		
    echo '</p><h3>Please try again.</h3><p><br></p>';
    
    }// End of if (empty($errors))
    
    }
    
    • Upvote 1
  3. I can't find anything obvious wrong.

     

    In your login.php, what argument is inside the redirect_user() function.

    At the moment, you are being redirected to index.php. This is the default setting for the redirect_user() function.

    What you need to have is redirect_user('loggedin.php')

    Can you confirm what code you have running on the server for redirect_user()?

  4. But there should be only one row of results since this user has selected just one county --> i'm not sure if that is the problem.

     

    $tresult is an associative array but you have not referenced any values in the array.

     

    $q = "SELECT title, description, image, x_id FROM x_representatives WHERE county_id = '$tresult' ORDER BY $order_by LIMIT $start, $display";

     

    perhaps it should be something like:

     

    $county = $tresult['county_id'];

     

    $q = "SELECT title, description, image, x_id FROM x_representatives WHERE county_id = '$county' ORDER BY $order_by LIMIT $start, $display";

     

    I could have some syntax errror here above but you see the idea I'm getting at.

    • Upvote 1
  5. Hi Hartley,

    Thanks, padding was the issue. I hadn't expected that since I didn't add any whitespace.

    I had already checked for the type but that was not the issue.

    Was it whitespace around "CORRECT" or is it apostrophes?

    Do you know why? [ I wasn't expecting that at all]

     

    Thanks again for your assistance, here is the code with the solution:

    			options.success = function(response) {
    
                    console.log(response); // I see CORRECT in the console.
    
                    console.log(response.length); // returns 9
    
                    console.log(typeof response); // returns string
    
                    var trimmed_response = $.trim(response);
    
                    console.log(trimmed_response.length); // returns 7
    
    				// Worked:
    
                    switch(trimmed_response)
                    {
                        case "CORRECT":
                        console.log('I can see the response!'); //works
                        // Hide the form:
                        $('#login').hide();
                        // Show a message:
                        $('#results').removeClass('error');
                        $('#results').text('You are now logged in!');
                        break;
    
                        case 'INCORRECT':
                        console.log('I can see the response!'); //works
                        $('#results').text('The submitted credentials do not match those on file!');
                        $('#results').addClass('error');
                        break;
    
                        case 'INCOMPLETE':
                        $('#results').text('Please provide an email address and a password!');
                        $('#results').addClass('error');
                        break;
    
                        case 'INVALID_EMAIL':
                        console.log('I can see the response!'); //works
                        $('#results').text('Please provide a valid email address!');
                        $('#results').addClass('error');
                        break;
    
                        default :
                            console.log('why can i not see the response?'); // successfully executed
                    }
    
                    console.log('got this far');
    				
    			}; // End of success.
    			options.url = 'login_ajax.php';
    
  6. Hi all,

     

    I've hit a roadblock and I can't debug this issue. Infact, I'm amazed that it's not working. It seems like something trivial but i can't see it.

     

    So in chapter 15, there is an AJAX request and everything works fine except the switch statement is not working as I would expect and as a result, the jQuery code is not being executed.

     

    The console returns CORRECT so this means the response is returned from the php file successfully but I can't figure out why the switch statement doesn't take this response variable and compare it with the case statements.

     

    Can anyone see what is wrong?

    			options.success = function(response) {
    
                    console.log(response); // I see CORRECT in the console.
    
                    switch(response)
                    {
                        case 'CORRECT':
                        console.log('I can see the response!'); //fails
                        // Hide the form:
                        $('#login').hide();
                        // Show a message:
                        $('#results').removeClass('error');
                        $('#results').text('You are now logged in!');
                        break;
    
                        case 'INCORRECT':
                        console.log('I can see the response!'); //fails
                        $('#results').text('The submitted credentials do not match those on file!');
                        $('#results').addClass('error');
                        break;
    
                        case 'INCOMPLETE':
                        console.log('I can see the response!'); //fails
                        $('#results').text('Please provide an email address and a password!');
                        $('#results').addClass('error');
                        break;
    
                        case 'INVALID_EMAIL':
                        console.log('I can see the response!'); //fails
                        $('#results').text('Please provide a valid email address!');
                        $('#results').addClass('error');
                        break;
    
                        default :
                            console.log('why can i not see the response?'); // successfully executed
                    }
    
                    console.log('got this far'); // successfully exectued 
    				
    			}; // End of success.
    			options.url = 'login_ajax.php';
    
  7. Also, perhaps you can point out the differences between the code that worked and the code that didn't work. That should help figure out what the problem is.

     

    And by the way, there is a comma here at the end of your array.

     

    $allowed = array ('application/pdf', 'application/DXF','application/dxf', 'application/DWG', 'application/dwg','image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png',);

    • Upvote 1
  8. thanks for the replies antonio, it really does help. i think you are probably right, i could put js on hold and do what i can in terms of php. knowing how to build an ecommerce site is one of my main goals though but i think ill wait until edition 2 comes out. i will start java once the course starts.

    i have to say contributors on this forum and these forums of larrys are excellent.

×
×
  • Create New...