Passing from Javascript to PHP

I have a php generated webpage that reads in data from a MySQL database and displays it. One of the database fields being displayed can be moused over and it creates a link. (this is adapted code so I can’t say it ever worked).

In the beginning of the code is this:

[php]
[/php]

Later in the code, is this (this generates the link based on the mouse-over)

[php]print "


<a href=“javascript:smallpopUp(‘sendcmd.php?cmd=$prefix$row[code]’)”>
$row[code]

";[/php]

What is supposed to happen is that when any displayed entry is clicked, the script sendcmd.php is supposed to be called (this part works) and the value of $cmd passed to it. Of course $cmd is empty at the popup window (sendcmd.php).

What do I need to do in order to make this work?[/code]

No one, eh?

What does your HTML output look like? (Not the PHP print, the actual output)

HTML is fine - fields are displayed correctly. While this is a lot, here’s the page source

[php]

Arcom RC210 Web RCP

Home  
Macros  
Set Points  
Port & Global Programming  
Command Codes  
DVR  
CONTROL  
Word List  
Macro Functions  
IRLP  
RC210 5.50 Manual  


Command Codes

Click the function number on the left to send the command code.

<tr >
	<td colspan=4 height="50" valign="bottom"><TABLE BORDER="0" CELLPADDING=0 CELLSPACING=0 WIDTH="400" align="LEFT"><TR>
<td rowspan="2">&nbsp;</td>

	<TD BGCOLOR="D4C69A"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="D4C69A" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablinkselected" HREF="codes.php?tab=alarms">Alarms</A><BR>
	</TD>
	<TD BGCOLOR="D4C69A"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>

	<TD BGCOLOR="500000"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablink" HREF="codes.php?tab=linking">Linking</A><BR>
	</TD>
	<TD BGCOLOR="500000"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>

	<TD BGCOLOR="500000"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablink" HREF="codes.php?tab=auxaudio">Aux Audio</A><BR>
	</TD>
	<TD BGCOLOR="500000"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>

	<TD BGCOLOR="500000"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablink" HREF="codes.php?tab=ufoutputs">Digital outputs</A><BR>
	</TD>
	<TD BGCOLOR="500000"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>

	<TD BGCOLOR="500000"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablink" HREF="codes.php?tab=Port1">Port 1</A><BR>
	</TD>
	<TD BGCOLOR="500000"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>

	<TD BGCOLOR="500000"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablink" HREF="codes.php?tab=Port2">Port 2</A><BR>
	</TD>
	<TD BGCOLOR="500000"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>

	<TD BGCOLOR="500000"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablink" HREF="codes.php?tab=Port3">Port 3</A><BR>
	</TD>
	<TD BGCOLOR="500000"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>

	<TD BGCOLOR="500000"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablink" HREF="codes.php?tab=Remote Base">Remote Base</A><BR>
	</TD>
	<TD BGCOLOR="500000"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>

	<TD BGCOLOR="500000"  ALIGN=LEFT VALIGN=TOP>
		<IMG height="9" src="tab-left.gif" width="9"><BR> 
	</TD>
	<TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE">
		<A class="tablink" HREF="codes.php?tab=misc">Misc</A><BR>
	</TD>
	<TD BGCOLOR="500000"  ALIGN="RIGHT" VALIGN="TOP">
		<IMG height="9" src="tab-right.gif" width="9"><BR> 
	</TD>
	<td rowspan="2">
		&nbsp;
	</td>
</tr><tr>
	<TD BGCOLOR="D4C69A">&nbsp;</TD>
	<TD BGCOLOR="D4C69A">&nbsp;</TD>
	
	<TD BGCOLOR="500000">&nbsp;</TD>
	<TD BGCOLOR="500000">&nbsp;</TD>
	
	<TD BGCOLOR="500000">&nbsp;</TD>
	<TD BGCOLOR="500000">&nbsp;</TD>
	
	<TD BGCOLOR="500000">&nbsp;</TD>
	<TD BGCOLOR="500000">&nbsp;</TD>
	
	<TD BGCOLOR="500000">&nbsp;</TD>
	<TD BGCOLOR="500000">&nbsp;</TD>
	
	<TD BGCOLOR="500000">&nbsp;</TD>
	<TD BGCOLOR="500000">&nbsp;</TD>
	
	<TD BGCOLOR="500000">&nbsp;</TD>
	<TD BGCOLOR="500000">&nbsp;</TD>
	
	<TD BGCOLOR="500000">&nbsp;</TD>
	<TD BGCOLOR="500000">&nbsp;</TD>
	
	<TD BGCOLOR="500000">&nbsp;</TD>
	<TD BGCOLOR="500000">&nbsp;</TD>
	</tr></table>

	</td>
</tr><tr>
		<td class="lightrow">
			<table align="center" border=0 cellspacing=0 cellpadding=4 width="100%"> 	
			<TR class="darkrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 1 OFF </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#1910')">				
					1910</a>
			   
			   </td>	
		</tr>	
			<TR class="lightrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 1 ON </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#1911')">				
					1911</a>
			   
			   </td>	
		</tr>	
			<TR class="darkrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 1 Interogate </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#1913')">				
					1913</a>
			   
			   </td>	
		</tr>	
			<TR class="lightrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 2 OFF </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#2910')">				
					2910</a>
			   
			   </td>	
		</tr>	
			<TR class="darkrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 2 ON </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#2911')">				
					2911</a>
			   
			   </td>	
		</tr>	
			<TR class="lightrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 2 Interogate </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#2913')">				
					2913</a>
			   
			   </td>	
		</tr>	
			<TR class="darkrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 3 OFF </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#3910')">				
					3910</a>
			   
			   </td>	
		</tr>	
			<TR class="lightrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 3 ON </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#3911')">				
					3911</a>
			   
			   </td>	
		</tr>	
			<TR class="darkrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 3 Interogate </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#3913')">				
					3913</a>
			   
			   </td>	
		</tr>	
			<TR class="lightrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 4 OFF </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#4910')">				
					4910</a>
			   
			   </td>	
		</tr>	
			<TR class="darkrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 4 ON </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#4911')">				
					4911</a>
			   
			   </td>	
		</tr>	
			<TR class="lightrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 4 Interogate </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#4913')">				
					4913</a>
			   
			   </td>	
		</tr>	
			<TR class="darkrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 5 OFF </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#5910')">				
					5910</a>
			   
			   </td>	
		</tr>	
			<TR class="lightrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 5 ON </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#5911')">				
					5911</a>
			   
			   </td>	
		</tr>	
			<TR class="darkrow">
				<td> &nbsp;
				</td>
				
				<td>Alarm 5 Interogate </td>
			   <td>
					<a href="javascript:smallpopUp('sendcmd.php?cmd=#5913')">				
					5913</a>
			   
			   </td>	
		</tr></table></td></tr></table><tr><td height="1%">
Copyright© 2005 - 2013 by Arcom Communications. All Rights Reserved.

[/php]

Simple testing…

var_dump($_GET);

Using “cmd=1”

array (size=1)
  'cmd' => string '1' (length=1)

Using “cmd=#1”

array (size=1)
  'cmd' => string '' (length=0)

So… remove the # it is for anchors not the query string.

Sorry, I’m kinda new to this.

Do you want me to create a new php file with your code and run it?

No, I’m saying you need to remove the # symbol from your query string.

[php][/php]

Man, I wish there was an edit feature here! ;D

Anyway… the $prefix variable was adding the # so I removed it. Now it shows in source (for example)

[php]

Alarm 3 Interogate


3913
[/php]

Still doesn’t pass to sendcmd.php though…

What is the code in sendcmd.php?

Ok… it appears to now be working! Thanks for your help

Sponsor our Newsletter | Privacy Policy | Terms of Service