0

I am trying to create button thats redirect me to another page. I am trying to put variable in the link but the button isnt working.

this is my script:

$idSelect[i]="SELECT * FROM times WHERE id=" . $mid[i] . "";
$idResult[i]=mysqli_query($con,$idSelect[i]); 

while($row = mysqli_fetch_array($idResult[i])) {
$uid[i]=$row['userid'];
}

$inc = "in.php?id=". $uid[i] ."";

echo "<input type='submit' value='back' class='button' onclick='window.location.href=". $inc ."'>";

notes:

  • ID prints Int from databse.
  • echo $inc is working, I checked it.

I tried few tutorials, and I read answers from for the same question but they didnt help

EDIT: I think my mistake is something with the onclick place, but I dont know what is the problem..

5
  • You can try anchor link instead of button. Commented Mar 8, 2014 at 8:03
  • @BindiyaPatoliya what do you mean? Commented Mar 8, 2014 at 8:09
  • you can use type='button' instead of type='submit' Commented Mar 8, 2014 at 8:12
  • @TunZarniKyaw still isnt working Commented Mar 8, 2014 at 8:13
  • if you think the error is Javascript error, then check in your browser console ... you will see what the error is Commented Mar 8, 2014 at 8:21

3 Answers 3

1

You didn't enclose the link.

So your html output would look like this

<input type="submit" value="back" class="button" onclick="window.location.href=in.php?id=1"> 

so javascript will look for a variable called in

This should work

echo "<input type='submit' value='back' class='button' onclick='window.location.href=\"". $inc ."\"'>";
Sign up to request clarification or add additional context in comments.

Comments

0

You can do something like this.

$inc = "http://in.yahoo.com/?p=us";
echo "<input type='submit' value='back' class='button' onclick='redirect()'>";

echo ("<script>
function redirect(){
    window.location.href = '$inc';
}
</script>");

Comments

0

Hey use onclick='window.location.replace' as below-

echo "<input type='button' value='back' class='button' onclick='window.location.replace="'. $inc .'"'>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.