Jump to content

Recommended Posts

heres the line for my button

echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location = post_reply.php?cid=".$cid."&tid=".$tid."\" /><hr /> ";

for some reason when i click on it in the site it does not do anything, but when i type the link in maunaly that the button should link to the page works.

 

heres the code for the page that the button is on


<?php require("top.php");

?>
<div id='content'>

<div id='homepageright'>
<?php

require("scripts/connect.php");

if($username){

$cid = intval($_GET['cid']);
$tid = intval($_GET['tid']);



$sql = "SELECT * FROM topics WHERE category_id = $cid AND id = $tid";
$res = mysql_query($sql) or die(mysql_error());

/*$cid = $_GET['cid'];
$tid = $_GET['tid'];

$sql = "SELECT * FROM topics WHERE category_id='".$cid."' AND id='".$tid."'";
$res = mysql_query($sql) or die(mysql_error());*/

if(mysql_num_rows($res) == 1){


echo "<table width='100%'>";
if($username){

echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location = post_reply.php?cid=".$cid."&tid=".$tid."\" /><hr /> ";
}

While ($row = mysql_fetch_assoc($res)) {
$sql2 = "SELECT * FROM post WHERE category_id='".$cid."' AND topic_id= '".$tid."'";
$res2 = mysql_query($sql2) or die(mysql_error());
while ($row2 = mysql_fetch_assoc($res2)) {
echo "<tr><td valign='top' style='border: 1px solid #000000;'><div style='min-height: 125px;
'>".$row['topic_title']."<br /> by ".$row2['post_creator']." - ".$row2['post_date'].
"<hr /> ".$row2['post_content']."</div></td><td width='200' valign='top' 
align='center' style='border: 1px solid #000000;'>User Info Here</td></tr><tr><td 
colspan='2'><hr /></td></tr>";
}
echo "</table>";

}

}

else{
echo "This Topic Does Not Exist.";
echo "$sql";
}

}
else{
echo "You Must Be Logged In To Continue.";
}
?>
</div>
<div id='homepageleft'>
<?php


?>
</div>

</html>
</body>

Link to comment
https://forums.phpfreaks.com/topic/247143-button-not-working/
Share on other sites

I believe you need a full url for windows.location. It is changing the URL in the browser and it would have no reference for the domain to use (unlike a normal link). Also it would be a good idea to enclose the value of window.location in quotes

 

Try this (modifying the root url as needed)

echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location='http://www.mysite.com/post_reply.php?cid={$cid}&tid={$tid}\" /><hr />";

Link to comment
https://forums.phpfreaks.com/topic/247143-button-not-working/#findComment-1269330
Share on other sites

alright, well i did that and its still not working, it seems like on of my quotes is off cause it just dont look right but when i randomly add a quote everything looks good.

 

heres my line now.

 

echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location='http://www.trucksterusa.com/post_reply.php?cid={$cid}&tid={$tid}' /><hr />";

Link to comment
https://forums.phpfreaks.com/topic/247143-button-not-working/#findComment-1269348
Share on other sites

Now you removed the ending double quote for the onclick/action handler. You need to enclose the onclick/action value within double quotes. Then the value inside that in a javascript window.location with it's own value that should be in single quotes (not you can swap which ones use single vs double quotes.

 

echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location='[url=http://www.trucksterusa.com/post_reply.php?cid=]http://www.trucksterusa.com/post_reply.php?cid=[/url]{$cid}&tid={$tid}'\" /><hr />";

Link to comment
https://forums.phpfreaks.com/topic/247143-button-not-working/#findComment-1269384
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.