homepage Welcome to WebmasterWorld Guest from 23.23.8.131
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
have variable - need formating help
passing a numeric variable in a <form> call
Clair

5+ Year Member



 
Msg#: 3321552 posted 6:55 pm on Apr 25, 2007 (gmt 0)

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

 

cameraman

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3321552 posted 7:59 pm on Apr 25, 2007 (gmt 0)

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 . '">';

Clair

5+ Year Member



 
Msg#: 3321552 posted 11:16 pm on Apr 25, 2007 (gmt 0)

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]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved