Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
Redirect to URL if input exists in database

I'm trying to redirect a user to an existing URL (stored in a MySQL database) if the value they input already exists in the database. I've got most of it working, but I've run into some issues.

I'm using AJAX to check the database. It sends the input value to another PHP file & checks the database to see if it already exists.

if($row) {
    echo ".$row["itemNum"].";
} else {

}

It's within the AJAX code that I'm having issues, in particular this:

success: function (response) {
    if (response == <?php ".$row["itemNum"]." ?>) {
        window.location.href = "http://www.example.com/" <?php echo "+"; if (".$row["itemNum"].") { echo ".$row["itemNum"]." } else {""}
    } else {
        // do other stuff
    }
}

$row["itemNum"] doesn't always exist, so it's in a conditional statement to prevent a syntax error.

The above doesn't work regardless of how I do it.

I have a feeling the main issue is with the if (response == <?php ".$row["itemNum"]." ?>) line?

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Based on this code:-

if($row) {
    echo $row["itemNum"]; // check the change here
} else {

}

You have to do like this:-

success: function (response) {
    if (response !== '') { // if response have some value
        window.location.href = "http://www.example.com/"+response;
    } else {
        // do other stuff
    }
}
about 4 years ago · Santiago Trujillo Relatório

0

As you suspected you have problem with following line.

if (response == <?php ".$row["itemNum"]." ?>) {

The Problem is your use of (") and (.) characters

Following syntax will give you what you want.

if (response == <?=$row["itemNum"]?>) {
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda