Jump to content

button not working.


dominic600

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.