Help needed with web forms:
19-08-2005, 22:41
|
#1
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Help needed with web forms:
Hi Guys,
I need a little help with creating a web form.
I'm starting from scratch so please excuse me if I sound like a bit of a
Using DreamWeaver, how do I create a form? It needs to have 2 fields that the user can enter data into and two buttons, one button will be used to carry out an SQL search on a database and the other will be used to reset the form fields.
If anybody could give me a little help to get started I would really appreciate it.
|
|
|
19-08-2005, 23:13
|
#2
|
|
Inactive
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
|
Re: Help needed with web forms:
<form action="processing-file.php" method="get">
<input type="text" name="variable-field" />
<input type="hidden" name="stuff-you-want-to-carry-over" value="variable-value" />
<input type="submit" value="Go" />
</form>
It's not really that hard...to get you started:
http://www.w3schools.com/html/html_forms.asp
BTW - I hear you're creating something for CF - I can clean up everything and check the code...
|
|
|
19-08-2005, 23:18
|
#3
|
|
Inactive
Join Date: Jul 2003
Posts: 1,395
|
Re: Help needed with web forms:
The w3c schools are always good: http://www.w3schools.com/html/html_forms.asp
I'm not sure how you do it graphically in DW but if you go to code view the html should be something like:
Code:
<form name="my_form" action="form_submit.php" method="GET">
<input type="text" name="text_one"><br>
<input type="text" name="text_two"><br>
<input type="submit" value="Submit"><br>
<input type="reset" value="Clear">
</form>
Hope that gives you enough to be going on with, I'm off to bed
Edit: At least Rich and I are in agreement and not confusing you
|
|
|
20-08-2005, 00:20
|
#4
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Help needed with web forms:
Ok, I've got the form part working, it passes two variables to a .php page.
The .php page queries a database and returns some values, based upon what was input in the form.
I then need to take some of the values from the record and some of the values from the form and perform an UPDATE.
So, from the form:
$usrInputName
$usrInputSearch
The SELECT query (which works) is:
PHP Code:
$result = mysql_query("SELECT * FROM tblMyTable WHERE requiredfield = '$usrInputSearch'",$link);
I can then "echo" all of the fields from the one returned record so that they output in the browser.
What I now need to do is take the usrInputName value and append it to the end of what is currently in one of the fields returned by the SELECT statement.
So, I'm doing this:
PHP Code:
mysql_query("UPDATE tblMyTable SET TheFieldToAmend = $row[TheFieldToAmend] . '<BR>' . $usrInputName WHERE id = $row[id] LIMIT 1");
So:
If TheFieldToAmend = This
And $usrInputName = Raistlin
I want the value of TheFieldToAmend for the selected record (identified by $row[id] returned by the SELECT query) to be:
This<BR>Raistlin
|
|
|
20-08-2005, 00:30
|
#5
|
|
cf.mega poster
Join Date: Dec 2003
Age: 51
Posts: 7,101
|
Re: Help needed with web forms:
Why would you want to include that inside a sql statement? Why not retrieve the values and then manipulate or concatonate them within your php code afterwards?
|
|
|
20-08-2005, 00:33
|
#6
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Help needed with web forms:
Quote:
|
Originally Posted by Richard M
BTW - I hear you're creating something for CF - I can clean up everything and check the code... 
|
Sorry, forgot to say....Thanks
I'll certainly take you up on that, I'm trying to do as much of the fiddly stuff as possible - the theory being that once the hard work's done someone wonderful (like you  ) can help me just get it a little bit tidy 
__________________
Quote:
|
Originally Posted by Gareth
Why would you want to include that inside a sql statement? Why not retrieve the values and then manipulate or concatonate them within your php code afterwards?
|
The values have already been retrieved, I now want to concatenate them (love that word  ) and amend the table in the database - wasn't aware that I could do that without a SQL statement 
__________________
Quote:
|
Originally Posted by philip.j.fry
Edit: At least Rich and I are in agreement and not confusing you 
|
Nah, I think I'm confusing myself  Thanks
|
|
|
20-08-2005, 00:34
|
#7
|
|
cf.mega poster
Join Date: Dec 2003
Age: 51
Posts: 7,101
|
Re: Help needed with web forms:
Oh, so you want the field value to contain the html tags that you're using...? Am I understanding this correctly? I've had a few tonight
|
|
|
20-08-2005, 00:40
|
#8
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Help needed with web forms:
Yep:
Say (for example) that the field value was originally:
THIS
I want it to be:
THIS<BR> WORD
So that when it is displayed on a web page it looks like:
THIS
WORD
Does that make sense, I haven't slept much in the last 72 hours so I'm a bit muddled myself
|
|
|
20-08-2005, 03:49
|
#9
|
|
Inactive
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
|
Re: Help needed with web forms:
PHP Code:
$result = mysql_query("SELECT * FROM tblMyTable WHERE requiredfield = '$usrInputSearch'",$link);
Very insecure code there...
I could (if I wanted to) change that code to this:
PHP Code:
$result = mysql_query("SELECT * FROM tblMyTable WHERE requiredfield = '$usrInputSearch'; UPDATE usertable SET pwd='0wned', admin='I-am-admin', trusted=100",$link);
That might have given me full access to the database...
And all I would have had to do is thus:
www.yoursite.com/script.php?usrInputSearch=blahblah';%20UPDATE %20usertable%20SET%20pwd='0wned',%20admin='I-am-admin',%20trusted=1;
Scary no?
|
|
|
20-08-2005, 12:03
|
#10
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Help needed with web forms:
Quote:
|
Originally Posted by Richard M
PHP Code:
$result = mysql_query("SELECT * FROM tblMyTable WHERE requiredfield = '$usrInputSearch'",$link);
Very insecure code there...
I could (if I wanted to) change that code to this:
PHP Code:
$result = mysql_query("SELECT * FROM tblMyTable WHERE requiredfield = '$usrInputSearch'; UPDATE usertable SET pwd='0wned', admin='I-am-admin', trusted=100",$link);
That might have given me full access to the database...
And all I would have had to do is thus:
www.yoursite.com/script.php?usrInputSearch=blahblah';%20UPDATE %20usertable%20SET%20pwd='0wned',%20admin='I-am-admin',%20trusted=1;
Scary no?
|
Yep, very scary
So, how do I get round that?
This is my first attempt at doing anything with PHP
|
|
|
20-08-2005, 20:43
|
#11
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Help needed with web forms:
Anybody?
|
|
|
21-08-2005, 00:35
|
#12
|
|
Inactive
Join Date: Jul 2003
Posts: 1,395
|
Re: Help needed with web forms:
Quote:
|
Originally Posted by Raistlin
Anybody? 
|
Connect to the db with a user that only has SELECT privilidges and use that connection for your query. Alternatively you can parse the input to make sure there is no nasty stuff. Or do both
|
|
|
23-08-2005, 21:54
|
#13
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Help needed with web forms:
Ok, so I connect to the database with an account that only has SELECT privileges - how do I then do the update that I want to do on the table?
I'm assuming that I would then need to connect using an account that has UPDATE privileges but then I'm running the same risk surely?
Not sure how I'd go about "parsing the input" either, I'm really new to all this PHP stuff.
Richard would appreciate any more comments you have on this security issue, unless I can get this resolved I'm on to a real no starter here
|
|
|
23-08-2005, 22:00
|
#14
|
|
Inactive
Join Date: Jun 2003
Location: Essex innit
Age: 52
Services: Sky HD + 16Mb ADSL
BT Telephone
Posts: 15,735
|
Re: Help needed with web forms:
May need to PM him for advice, he was last active 30 mins ago, I'm sure he won't mind since he is interested in what you are trying to create
|
|
|
23-08-2005, 22:01
|
#15
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Help needed with web forms:
Quote:
|
Originally Posted by Paul
May need to PM him for advice, he was last active 30 mins ago, I'm sure he won't mind since he is interested in what you are trying to create 
|
May do if he doesn't see this, if he's not been active for a while he won't see the PM either
Thanks though
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 08:01.
|