Forum Moderators: coopster

Message Too Old, No Replies

passing 2 variables to I_Frame

Can you pass two variables at once to an I-frame

         

postman

11:39 pm on Aug 6, 2003 (gmt 0)

10+ Year Member



I'm brand new at PHP and am trying to pass two variables:
$id and $master_id to an I-frame which will display the result:
this is my code on the main page:

//get poetry
$get_poem = "select id, master_id, concat_ws(', ', title) as display_name from poem where master_id = $_POST[sel_id]";
$get_poem_res = mysql_query($get_poem);

if (mysql_num_rows($get_poem_res) > 0) {
$display_block .= "
<form method=\"post\" action=\"poemdisplay.php\">
<P><strong>Select a poem to view:</strong><br>
<select name=\"sel_id\" , \"sel_master_id\">
<option value=\"\" , \"\">-- Select One --</option>";

while ($recs = mysql_fetch_array($get_poem_res)){
$id = $recs['id'];
$master_id = $recs['master_id'];
$display_name = stripslashes($recs['display_name']);

$display_block .= "<option value=\"$id\" , \"$master_id\">
$display_name</option>";
}

$display_block .= "
</select>
<input type=\"hidden\" name=\"op\" value=\"view\">
<p><input type=\"submit\" name=\"submit\"
value=\"View Poem\"></p>
</FORM>";
}

This is my code to view poetry on the I-Frame:

if ($_POST[op] == "view") {

$get_poem = "select title, poem, poem_note from poem where id = $_POST[sel_id] && master_id = $_POST[sel_master_id]";
$get_poem_res = mysql_query($get_poem);

if (mysql_num_rows($get_poem_res) > 0) {
$display_block .= "<P><strong>Poem</strong><br>";

while ($add_info = mysql_fetch_array($get_poem_res)) {
$title = $add_info[title];
$poem = $add_info[poem];
$poem_note = $add_info[poem_note];

$display_block .= "<b>$title<br><br> $poem<br><br> $poem_note<br><br></b>";
}

}
}

Can anyone tell me what I am doing wrong or perhaps show me a better way to do this?

jatar_k

6:00 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld postman,

what exactly is happening? Do you get an error message?

my guess is that the html format is messed up
$display_block .= "<option value=\"$id\" , \"$master_id\">

should come out as if $id=1 and $master_id=2
<option value="1" , "2">

That isn't right, you may not have meant to escape all of those quotes, not sure.

postman

9:00 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



Hi Jatar_K,

I'm getting the following error from the poemdisplay.php I-frame.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/christia/public_html/poemdisplay.php on line 11

You can see what happens if you go to:

<snip>

And submit the poet and then title.

[edited by: engine at 7:44 am (utc) on Aug. 8, 2003]
[edit reason] No urls, thanks. See TOS [webmasterworld.com] [/edit]

jatar_k

9:06 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what is the php code from line 11 then?

postman

9:37 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



if (mysql_num_rows($get_poem_res) > 0) {

jatar_k

9:48 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and does $get_poem_res come from something like

$get_poem_res = mysql_query("some query here");

if so try
$get_poem_res = mysql_query("some query here") or die("<p>error:<br>".mysql_error());

that should show you the actual error from mysql and give us some more information.

postman

10:49 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



I get an error message that reads:

error:
You have an error in your SQL syntax near '' at line 1

Line 1 on my code is the <?php>

jatar_k

11:02 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



no that's ok, it isn't referring to your php. That is the actual error coming from mysql. It is telling you that there is something wrong here

$get_poem = "select id, master_id, concat_ws(', ', title) as display_name from poem where master_id = $_POST[sel_id]";

that query doesn't work, what I usually do is echo the full constructed query and then take a look at where the actual error is.

echo "<p>query:<br>",$get_poem;

put that after the line I mentioned above and then paste the query in here and we'll have a look.

jatar_k

11:30 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



also take a look at the source of the page
<select name="sel_id" , sel_master_id>
<option value="4" , 4><b>In Worship</b></option>

that will definitely break your sql statement

I would suggest passing the two vars seperately. Once they select a writer the sel_master_id is the same for each entry. Maybe

<input type="hidden" name="sel_master_id" value="4">

when they are on the second page and
<select name="sel_id">
<option value="4"><b>In Worship</b></option>
for the drop down

jatar_k

11:44 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe like so with the above changes

$get_poem = "select title, poem, poem_note from poem where id=" . $_POST[sel_id] && master_id=" . $_POST[sel_master_id]";

postman

11:44 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



The error is on this line on the second page.

$get_poem = "select title, poem, poem_note from poem where id = $_POST[sel_id] && master_id = $_POST[sel_master_id]";

I ran the query you gave me and got this reply:

query:
select title, poem, poem_note from poem where id = 1 && master_id =

error:
You have an error in your SQL syntax near '' at line 1

It seems as though I'm getting the id from the first page but not the master_id. So my problem must be in the form on the first page.

jatar_k

11:46 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



look at post #9 I have an idea how you can make the changes to the form by splitting the two fields. ;)

It is because the html is broken you are putting two vars into one element and you can't really do that.

postman

11:05 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



Hi Jatar_K
I just wanted to thank you for all of your help. You can tell I am new at this. I only needed to pass one variable to the new page not two. That's the way I had my database set up and I forgot about it as time went on.
Your tips were invaluable to me and I will use them often I'm sure as I put the page together.
Have a great Day!
JRHoffman

jatar_k

11:07 pm on Aug 8, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



glad to be of help :)