Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HOw do i click on image to submit form that pass value to next page using php

Posted on 2007-11-18
7
Medium Priority
?
203 Views
Last Modified: 2013-12-13
Not sure if anyone is out there this Sunday, but just  in case.  I have set up a search form that returns the number of matches from a db.  From that results page, I want to click an edit button(that is an image) that carries the value to the next page.  I can't seem to get this to work.  Any help would be appreciated..  Code  attached and example located here:
http://mywebgenius.net/one.htm
<html>
<?php
//searches using ID/username from db
   $dbname="northwind";
   $host="localhost";
   $port="1433";
   $user="root";
   $password="";
 
$_POST['txt_searchName'];
$viewDetail = $_POST['txt_viewDetail'];
echo "<br><br>view detail has:  ".$viewDetail."<br><br>";
 
/*if (!$txt_searchName)
{
echo "<p align=center><font color=#800000 size=5 face=Arial Black>You did not enter a search criteria.<br><br>Please Try Again.</font></p>";
exit;	
}*/
//echo $_POST['txt_searchName'];
$searchName  = addslashes(trim($_POST['txt_searchName']));
echo "<br><br>search name is:  ".$searchName."<br><br>";
 
$connection=mysql_connect($host,$user,$password) or Die("Unable to connect to " . $host);
  
   mysql_select_db($dbname);
    $qry = "select CustomerID, CompanyName, City from tblcustomers where CustomerID LIKE  '%".$searchName."%'";
    echo $qry;
    $result = mysql_query($qry);
	$num_results = mysql_num_rows($result);
	echo "<br><br><font face=Arial size=4 color=#000080><b>Total # of Users Found: " .$num_results."</b></font><br><br>";
 
echo "<table border=1 id=table1 width=50% style='border-collapse: collapse'>";
echo "<tr>";
echo "<td bgcolor=#BEBEBE><font color=#000080><p align=center><b>Customer ID</td>
	  <td bgcolor=#BEBEBE><font color=#000080><p align=center><b>Customer Name</td>
	  <td bgcolor=#BEBEBE><font color=#000080><p align=center><b>City</td>
	  <td bgcolor=#BEBEBE><font color=#000080><p align=center><b>Edit</td>";
	  
echo "</tr>";	
	
while ($row = mysql_fetch_array($result))
{
	echo "<tr><td>".$row['CustomerID']."</td><td>".$row['CompanyName']."</td><td>".$row['City']."</td><td>"."<input type=image src=Edit.jpg onClick=document.frmUserResults.txt_viewDetail.value=".$row["CustomerID"];document.frmUserResults.submit();">"." </td></tr>";
}
echo "</table>";
	
echo "<FORM method='post' action='userDetail_proc.php' NAME='frmUserResults'>";
	echo "<input type=hidden name=txt_viewDetail size=20>";
echo "</form>";
 
?>
</body>
</html>

Open in new window

0
Comment
Question by:justmelat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 7

Expert Comment

by:dansoto
ID: 20308118

<input type="image" src="images/submit.jpg" value="Submit" alt="Submit">

Open in new window

0
 
LVL 1

Author Comment

by:justmelat
ID: 20308136
HI Dan
If you will notice on line 43 of my code I am using this:
echo "<tr><td>".$row['CustomerID']."</td><td>".$row['CompanyName']."</td><td>".$row['City']."</td><td>"."<input type=image src=Edit.jpg onClick=document.frmUserResults.txt_viewDetail.value=".$row["CustomerID"];document.frmUserResults.submit();">"." </td></tr>";
}
which I think is what you have.  It is just not submitting the form.  I get this error: Fatal error: Call to undefined function: submit() in
0
 
LVL 2

Expert Comment

by:LinuxCluster
ID: 20308151
You could pass the values in the href link part of the link and place the img into the href part and not use forms and javascript for it.

How about a link like this

<a href="userDetail_proc.php?txt_viewDetail=$row[CustomerID]"><img src="Edit.jpg" border=0></a>

Regards,
linuxcluster
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 1

Author Comment

by:justmelat
ID: 20308196
Linux

this works, but i know my boss is not going to like that the url w/the info is viewable.
0
 
LVL 2

Expert Comment

by:LinuxCluster
ID: 20308328
Ok, you could hide the info by encrypting it etc.-  if it is not too sensible data a simple ROT13 should do and is easily implementable.

Or you create a single form for every "edit" link you place. That way you can pass the edit value in a hidden form field along with the submit button the way dansoto had written.

Regards,
linuxcluster

0
 
LVL 2

Expert Comment

by:LinuxCluster
ID: 20308516
Or you use the JS code below in your page and set via JS the value of the clicked image into the hidden form field.

(the code is not brushed to be echoed by php...)

Regards,
linuxcluster
<script language="javascript">
function imgSubmit(v)
{
document.FormName.txt_viewDetail=v
document.FormName.submit()
}
</script>
 
<form name="FormName">
<input type="hidden" name="txt_viewDetail" value="">
...
<img src="Edit.jpg" onclick="imgSubmit('$row[CustomerID]')" value="Submit" alt="Submit">
...
</form>

Open in new window

0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20308605
This should work. i think your image needs to be in between the <form> tags, you don't even need the onclick event to submit the form, it will do it by itself.

hope this helps.
<html>
<?php
//searches using ID/username from db
   $dbname="northwind";
   $host="localhost";
   $port="1433";
   $user="root";
   $password="";
 
$_POST['txt_searchName'];
$viewDetail = $_POST['txt_viewDetail'];
echo "<br><br>view detail has:  ".$viewDetail."<br><br>";
 
/*if (!$txt_searchName)
{
echo "<p align=center><font color=#800000 size=5 face=Arial Black>You did not enter a search criteria.<br><br>Please Try Again.</font></p>";
exit;   
}*/
//echo $_POST['txt_searchName'];
$searchName  = addslashes(trim($_POST['txt_searchName']));
echo "<br><br>search name is:  ".$searchName."<br><br>";
 
$connection=mysql_connect($host,$user,$password) or Die("Unable to connect to " . $host);
  
   mysql_select_db($dbname);
    $qry = "select CustomerID, CompanyName, City from tblcustomers where CustomerID LIKE  '%".$searchName."%'";
    echo $qry;
    $result = mysql_query($qry);
        $num_results = mysql_num_rows($result);
        echo "<br><br><font face=Arial size=4 color=#000080><b>Total # of Users Found: " .$num_results."</b></font><br><br>";
 
echo "<table border=1 id=table1 width=50% style='border-collapse: collapse'>";
echo "<tr>";
echo "<td bgcolor=#BEBEBE><font color=#000080><p align=center><b>Customer ID</td>
          <td bgcolor=#BEBEBE><font color=#000080><p align=center><b>Customer Name</td>
          <td bgcolor=#BEBEBE><font color=#000080><p align=center><b>City</td>
          <td bgcolor=#BEBEBE><font color=#000080><p align=center><b>Edit</td>";
          
echo "</tr>";   
echo "<FORM method='post' action='userDetail_proc.php' name='frmUserResults'>";
while ($row = mysql_fetch_array($result))
{
        echo "<tr><td>".$row['CustomerID']."</td><td>".$row['CompanyName']."</td><td>".$row['City']."</td><td>"."<input type='image' src='Edit.jpg' onClick=document.frmUserResults.txt_viewDetail.value=".$row["CustomerID"];">"." </td></tr>";
}
echo "</table>";
        
 
        echo "<input type=hidden name=txt_viewDetail size=20>";
echo "</form>";
 
?>
</body>
</html>

Open in new window

0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question