473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Linking with form php and mysql

Hi Im have aproblem with a site im trying to design. What Im trying to do is when you click on an image it links to another page and displays data that is relevent to its self.
The images are stored in the mysql data base under a colum called thumb and what im trying to make happen is when you click on the image it submittes its thumb name with a form feature and I can use the post meathod to recive it on another page and display the rest of the data stored in its row.
The below code sort of works, the only problem is that is selects the last item in the data base with the name gibson and the data in its row. I cant get it to select anything else.
I could be going about this complitly the wrong way...
Any help would be great
this is the code to send;

<form action='proinfo.php' target ='mainFrame' method='post' >

<?php
$result = mysql_query("SELECT * FROM stocklist WHERE make LIKE 'gibson' ");
while($row = mysql_fetch_array($result))
{
//$proid = $row['thumb'];
$thumbpic = $row['thumb'];

echo "<input type='image' src = '$thumbpic'/>";
echo "<input type='hidden' name ='proid' value ='$thumbpic'/>";

}

?>

This is the code to display what has been sent;

$searchd = $_POST["proid"];
$sql = "SELECT * FROM stocklist WHERE thumb = '$searchd'";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
echo $row['title']." ".$row['image']." ".$row['images'];
echo "<br />";
}
Dec 5 '06 #1
14 2867
ronverdonk
4,258 Expert 4TB
Maybe I don't understand your question in full, but you select the 'gibson' yourself! So you cannot complain that only 'gibson' is selected. See this statement
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT * FROM stocklist WHERE make LIKE 'gibson' ");
  2.  
Ronald :cool:
Dec 5 '06 #2
There are 8 items in the row named gibson and another 10 named somthing else. But the code at the moment only returns the last item with the name gibson. I cant get it to return any of the other 7:(
Dec 5 '06 #3
ronverdonk
4,258 Expert 4TB
All your form input fields have the name 'proid'. Since there can only be one occurrence in the array ($_POST[ 'proid']) there is only one entry passed, i.e. the last one filled.

Ronald :cool:
Dec 5 '06 #4
Yep I have just been messing round with it and found that. How can I get round that? I want to click on the image and for it to sends its 'id' information with it? I just cant figure out how to do it:(
Dec 5 '06 #5
ronverdonk
4,258 Expert 4TB
Well, I am not much of a JavaScript and html image submit buff, but I found, by trying, a solution that (at least) works.

Firstly, the problem for unique names can be solved by using an index variable $i and concatenating that to the proid constant.
Secondly, the name passed by the image submit button is not the name you give it, but is an internal name (someting like 'proid0_x23').

So I just thought, why don't I use JS to capture the name before it gets clobbered and pass that name in the hidden input with id 'submitted', so the name of the clicked image statement is passed via the 'id=submitted' input statement.

Anyway, here is the code and it works for me. Any HTML or JS guru's: go ahead and make it better or lighter.
[html]<html<head><title>Test It</title>
<script type="text/javascript">
function getIt(sel) {
document.getElementById("submitted").value=sel.nam e;
}
</script>
</head><body>
<?php
if (isset($_POST['submitted'])) {
// connect to server and db
$ind = $_POST['submitted'];
$searchd = $_POST[$ind];
$sql = "SELECT * FROM stocklist WHERE thumb='$searchd'";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo $row['title']." ".$row['image']." ".$row['images']."<br />";
}
}
else {
echo "<form action='a.php' method='post'>";
// connect to server and db
$i=0;
$result = mysql_query("SELECT * FROM stocklist WHERE make LIKE 'gibson' ");
while ($row = mysql_fetch_array($result)) {
$thumbpic = $row['thumb'];
echo "<input type='image' id='myimage' name='proid$i' onclick='getIt(this)' src='$thumbpic' width='60' height='60' />&nbsp;&nbsp;&nbsp;";
echo "<input type='hidden' name='proid$i' value='$thumbpic' />";
$i++;
}
echo "<input type='hidden' id='submitted' name='submitted' value='1' />";
echo "</form>";
}
?>
[/html]
Ronald :cool:
Dec 5 '06 #6
Oh wow thats brillaint, thank you. I do have a couple of questions tho, Im a networking student a know very little about programming so Im sorry il any of the questions seem simple.
Do I just have to change 'a.php' to a blank php and the results will get sent there? Or do I need a echo command?
Dec 5 '06 #7
ronverdonk
4,258 Expert 4TB
I forgot to change the action of the form. Since you are submitting the form to itself you can replace the form statement by
[php]echo '<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">';[/php]
Ronald :cool:
Dec 5 '06 #8
I think some of the " need replacing with ' because the code turns all black when you added the section you wrote. I thought this would be right ,[php]echo "<form action = '<?php echo "$_SERVER['PHP_SELF']"; ?>' method='post'>";[/php]
but it gives "Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\Risingsun Gibson.php on line 42" error code.
Dec 5 '06 #9
ronverdonk
4,258 Expert 4TB
I think some of the " need replacing with ' because the code turns all black when you added the section you wrote. I thought this would be right ,[php]echo "<form action = '<?php echo "$_SERVER['PHP_SELF']"; ?>' method='post'>";[/php]
but it gives "Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\Risingsun Gibson.php on line 42" error code.
I am too hasty nowadays, this will do it[php]echo "<form action='".<?php echo "$_SERVER['PHP_SELF']"; ?>. "' method='post'>";[/php]
Ronald :cool:
Dec 5 '06 #10
It still doesnt like it. all of the code after the last dot turns black. I have tried moving the dotes and have added another set of " before and after each dot that makes the code go the right color.
[php] echo "<form action='"."<?php echo "$_SERVER['PHP_SELF']"; ?>"." ' method='post'>";[/php]
But I get the same error as before
"Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\Risingsun Gibson.php on line 42"
Dec 5 '06 #11
ronverdonk
4,258 Expert 4TB
It's just not one of my days! Not quite my day at all!
Expand|Select|Wrap|Line Numbers
  1. echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>"; 
Ronald :cool:
Dec 5 '06 #12
Thanks sooooooooooooooo much it works :D I cant tell you how gratefull I am.
Dec 5 '06 #13
Ronald, it should be valid HTML which would be this:

[php]echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';[/php]

Double-quotes should be used for HTML attributes. Using single-quotes makes the HTML code invalid in the HTML 4.0, and XHTML 1.0 specs.

Plus, Double-quotes are parseable, but using single-quotes is better because they are not parsed for vairables. This speeds up your PHP apps because PHP doesn't have to parse that stuff.

Sean
Dec 6 '06 #14
ronverdonk
4,258 Expert 4TB
Whoever told you that?

Ronald :cool:
Dec 6 '06 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: nectar | last post by:
Hello, In an Offers DB, I have a form with two fields BeginDate and EndDate. When clicking on a button, it opens a continous form with a DoCmd.OpenForm and a criteria based on the 2 dates...
2
by: Gt394 | last post by:
I have a form called frm_quote and a report called rpt_quote. I want to be able to view the form on a particular quote number (field: QuoteNo - autonumber) and then go to the report where the the...
2
by: dimension | last post by:
Hi, i have one question and one opinion i seek. please assist if you can. I am using VS2005 beta. 1) I have two tables with the following columns Security: security_id, name, symbol, exchange_id...
4
by: Jayhawk | last post by:
Hello, I am trying to use a MS Access front end application to link to data tables stored in MySQL Server. I am running MySQL 5.0 Community Server, MySQL Connector/ODBC 3.51, and MS Access...
1
by: TMacD | last post by:
This is my first project linking an MS Access (2003) front end to a MySQL back end. I've created and populated several tables in the MySQL database. I can read/write all of them except one from my...
1
by: thabit | last post by:
Good times for all Is there any way to link form-subform with more than 3 fields, since the wizard (subform field linker) does not support more than 3 fields linking
2
by: johnplayboy07 | last post by:
hi, please i need support. i design a Registration form in frontpage 2003 and then design a table in SQL server 2000 database, now i want the data entries that will be filled on the form to be stored...
7
by: PotatoChip | last post by:
Ok, I have a form and a subform. The form shows a document with it's pertinent information. The subform has some of the same fields as the form and shows where the document was sent. The main form...
2
by: tj 6 | last post by:
Hi all i was wondering if any one could help me i'm tring to build a view by month calander to show client appointments i have a text box which starts with the current year which i'm planning to be...
0
by: imark34 | last post by:
First of all I am a complete newbie so please go easy on me. I am trying to create a form in PHP that will create a user account in MYSQL. In the form I want a drop down menu for the user to choose...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.