0
    session_start(); //continue session

$courseArray = array();  //create array to store current course info
$courseArray = $_SESSION['course']; //fill array

$currentTitle = (string)$courseArray[0][0];     
$currentDescription = (string)$courseArray[0][1];       
$currentRecPrep = (string)$courseArray[0][14];  

$newTitle = (string)$_POST["title"];
$newDescription = (string)$_POST["description"];
$newRecPrep = (string)$_POST["recPrep"];

if($currentTitle == $newTitle)
{
echo "succuse";
}

The above code is taking data from a form submitted on a previous page and checking if the data the user submitted is different from the data that was already there, which is stored in a session variable. The title, description, and recPrep are being sent from another page, and are submitting the correct values.

Now here's the part that's had me pulling out hair for the past hour: the strings being compared are identical, but the condition never completes. When I echo out the two titles just before the condition they print exactly the same thing, but the condition will not complete. What is wrong?

Someone please help. Thanks.

0

1 Answer 1

1

Try using the strcmp function with the === operator:

if (strcmp($currentTitle, $newTitle) === 0) {
    echo "succuse";
} else {
    echo '$currentTitle is not equal to $newTitle in a case sensitive string comparison';
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that didn't work, but when I echoed the result 1 came up. turns out there was a single space that was sneaking in.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.