Welcome to WebmasterWorld Guest from 54.158.51.150

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

have variable - need formating help

passing a numeric variable in a <form> call

     
6:55 pm on Apr 25, 2007 (gmt 0)

5+ Year Member



First -- I've been working on this blog system for weeks now, as a way of learning PHP and MySQL -- with books and many hours of fiddling, I've almost got exactly what I want. And, this is the first time I'm asking for help.

I have this successful call to the db which retrieves a blog entry that has been requested by another module that calls this one. I've no problem there -- it comes into this module fine and the following call to the db pulls out the correct entry.

$row = mysql_fetch_array ($r); // Retrieve the information.
$id = $row['blog_id'];
$title = trim ($row['title']);
$entry = trim ($row['entry']);
$day = trim ($row['date_entered']);

Later down in the code, but still within the php unit, I need to call another module from a submit button on a form.

print '<form action="x_add_comm.php?id=6" method="post">
<p>Name: <input type="text" name="name" size="20" maxsize="20" /></p>
<p>Comment: <textarea name="comment" rows="3" columns="70"/> </textarea></p>
<input type="submit" name="submit" value="Add Comment" /></form>';

It is the first line -- I have hard-coded in the 6 just to test the rest of my code (add a comment to the db, get out a comment, etc.) and everything works. And, this is the last hurdle of the entire program! Grrr.

Right now, the variable I need is in the same section of code as the form that needs to use it. It is in the form of

$id = $row['blog_id'];

What kind of punctuation and how should the variable be handled to get it attached the action call for the form:

print '<form action="x_add_comm.php?id=

In other words, what should the rest of that line look like?

I will be such a happy camper if someone can fill in that miserable blank for me!

Thanks,
Clair

7:59 pm on Apr 25, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



You can either:
print '<form action="x_add_comm.php?id=' . $id . '" method="post">';

or, what I usually do with ids is to make them hidden form fields:
print '<input type="hidden" name="id" value="' . $id . '">';

11:16 pm on Apr 25, 2007 (gmt 0)

5+ Year Member



ARghhh--

Well I used your answer to my question, and it passed the right number, but there was an = sign in front of it and therefore not a good number so in error checking it quit.

The variable dumped in the error report was =6 not 6.

I mucked about with it for another hour and was just starting to write you a thank-you post to tell you what happened and that I was going to try the "hidden value" approach in the morning, when I typed the =6 and a very dim bulb went off --sure enough, I had php?id==' . $id . '

That's what 8+ hours on the same line of code will get you. Finally get the truth and too wiped to enter it properly.

Thanks so much, Cameraman, for helping. It really is particularly awful when absolutely everything works, except this very last thing, and it never seems like it will ever get resolved.

But it is now, thanks to you. I'm off to bed and will be raring to go at 3 am when I can start the fun stuff of tweaking the niceties of the CSS and cleaning up the code. WAHHHHHHHHHHOOOOOOOOOOOOOOOO

g'night
Clair

[edited by: Clair at 11:27 pm (utc) on April 25, 2007]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month