Reputation: 1937
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:
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..
Upvotes: 0
Views: 3153
Reputation: 69
Hey use onclick='window.location.replace' as below-
echo "<input type='button' value='back' class='button' onclick='window.location.replace="'. $inc .'"'>";
Upvotes: 0
Reputation: 2344
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 ."\"'>";
Upvotes: 1
Reputation: 6349
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>");
Upvotes: 0