TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-07-2008, 10:21 PM   #1 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 87
Thanks: 49
StevenF is on a distinguished road
Default Query With a C# Variable?‏

Hiya


I was wondering if someone could help me out here, please? Big Smile

I'm creating a forum, my threads page has the following query:

SELECT * FROM [threads] WHERE ([forum_name] = ?) ORDER BY [time_created] DESC

The "?" (control value) is the sub-forum which the thread is linked to. Example:

List of Forums:

- Introduce Yourself
- The Lounge
- Another Thread
- Blah Blah Blah

User clicks on The Lounge, loads thread.aspx where Query: SELECT * FROM [threads] WHERE ([forum_name] = ?) ORDER BY [time_created] DESC runs

------------------------------------------------------------------------------------------------------------------------------------------------

Now the page with "The Lounge" threads loads, and I store the querystring into a variable

string forum_name = Page.Request.QueryString["forum_name"];
Page.Response.Write("Now browsing the threads about " + forum_name);

Now the user clicks "New Thread" button, and is presented with a form to fill out. Instead of typing the name of the forum that their thread is to be featured in (i.e. "The Lounge") I would like it to automatically have this filled in, based upon where they came from.

My Insert query then looks like this:

Insert Into threads ([thread_name], [thread_author], [forum_name], [time_created]) Values(?,?,?,?)"

But I'm getting an error saying "No value given for one or more required parameters." So I think the variable isn't passing into the query. Do you know why this might be?

Basically, how do I incorporate the value stored in that variable, into the query?


Thanks a lot!

Kind Regards,
Steven
__________________
My Personal and Photo Blog
StevenF is offline  
Reply With Quote
Old 12-07-2008, 11:45 PM   #2 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

i think your in the wrong section.
__________________
Serenity Project - 5% (Layout) - Ongoing....
Project Serenity Free Life!....
zxt3st is offline  
Reply With Quote
Old 12-07-2008, 11:48 PM   #3 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 87
Thanks: 49
StevenF is on a distinguished road
Default

There is no C# version, so I figured this would be the next best place.

If a mod wants to move it to a more relevant section, feel free.
__________________
My Personal and Photo Blog
StevenF is offline  
Reply With Quote
Old 12-08-2008, 01:11 AM   #4 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 87
Thanks: 49
StevenF is on a distinguished road
Default

To simplify, I want to do something like the following:


PHP Code:

 
<% string forum_name Page.Request.QueryString["forum_name"];
   
Page.Response.Write("Now browsing the threads about " forum_name); %>

Insert Into threads ([thread_name], [forum_name], [thread_author], [time_created]) Values(?,<% forum_name %>,?,?) 
But that isn't valid, but that shows the idea of what I want to be able to do.
__________________
My Personal and Photo Blog
StevenF is offline  
Reply With Quote
Old 12-08-2008, 03:57 AM   #5 (permalink)
The Contributor
 
Join Date: Mar 2008
Posts: 31
Thanks: 1
masfenix is on a distinguished road
Default

You have the easy option and an advanced option. Your easy option is that you already have a variable "forum_name" that has your forum name, so why not pass this on to your new thread page.

People click view lounge and it goes to the page view.aspx?name=viewlounge and you query that paramter am I correct?

Then from that page you call /newthread.aspx?name=viewlounge and just on your page_load event, just fill the textbox in with that parameter.
masfenix is offline  
Reply With Quote
Old 12-08-2008, 05:32 AM   #6 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

In the page load event set a hidden field to the value of that variable then set that hidden fields contents to be the query param. Or a bit more secure way is to set that variable as a session variable in the page load then set that parameter as a session param and get it that way.
CoryMathews is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ugh, Query in a while statement Aaron Absolute Beginners 2 08-11-2008 06:36 PM
query question Evulness Absolute Beginners 4 04-21-2008 07:46 PM
Query caching xenon Advanced PHP Programming 4 01-29-2008 08:20 PM
Need help with a query webosb MySQL & Databases 5 01-11-2008 10:12 PM
Insert data into two tables with one query CMellor MySQL & Databases 5 12-10-2007 10:46 AM


All times are GMT. The time now is 07:37 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design