Jump to content

[SOLVED] Passing php variable to a javascript location.replace


CincoPistolero

Recommended Posts

I have a php page that has two buttons at bottom of page. Each takes viewer to new page based on <input type="submit" name="a" ... yada yada.

 

this works fine. however I'm trying to attach an ID to the redirects. As I'll show below, I've created a plain jane page that only serves the purpose of proving this is possible and it works. I take the same code and place it in a more robust php page and it does not work, it sends me to the next page, but does not attach the ID value. Below is my code.

 

for trouble shooting I've even echo the ID value lower on the page to prove it is present.

 

any help is greatly appreciated.

 

Code from page that works

<?php
$awoID=5;
if (isset($_POST['tt'])) { // if form has been submitted 
?>
  <script language='javascript'>
location.replace('send.php?awoID="<?php echo $awoID; ?>"');
</script> 
<?php } else if(isset($_POST['tv'])) { ?>
<script language='javascript'>
location.replace('edit.php?awoID="<?php echo $awoID; ?>"');
</script>
<?php } else { ?>

<form action="<?php echo $_SERVER['PHP_SELF']?>" name="form" method="post">
<input type="submit" name="tt" value="edit">
<input type="submit" name="tv" value="send">
</form>
<?php } ?>

 

some of the code from page that does not work.

<?php
$queryusers = "SELECT userID, lastName, firstName FROM users WHERE userName='$salesTitan';";
$resultusers = mysql_query($queryusers) or die ("Error in query: $queryusers. " . mysql_error());
$usersrow= mysql_fetch_array($resultusers);
extract($usersrow);
$f_name=$usersrow['firstName'];
$l_name=$usersrow['lastName'];
$uID=$usersrow['userID'];
?>
<?php //New Submissions Query
$query = " SELECT * FROM artWO WHERE awoID='$awoID'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$row= mysql_fetch_array($result);
extract($row);

$preDot = substr($row['phoneNum'],0,3);
$postDot = substr($row['phoneNum'],3,4);
$awoID = $row['awoID'];
?>
<?php
if (isset($_POST['mo'])) { // if form has been submitted 
?>
  <script language='javascript'>
// location.replace('makeOrder.php?awoID="<?php echo $row['awoID']; ?>"');
                location.replace('send.php?awoID="<?php echo $awoID; ?>"');
</script> 
<?php } else if(isset($_POST['edit'])) { ?>
<script language='javascript'>
location.replace('editWO.php?awoID="<?php echo $row['awoID']; ?>"');
</script>
<?php } else { ?>
<div id="main">

I finally figured it out. I had send.php?awoID="<?php echo $awoID; ?>"

 

this of course sends "some #" as the ID.

 

and I need just some # without the quotes. I removed the quotes from around the php echo statement, and now I am golden.

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.