
![]() |
jammaster82
![]() $companyname = trim($_REQUEST['companyname']); $contactfirstname= trim($_REQUEST['contactfirstname']); $contactlastname=trim($_REQUEST['contactlastname']); $streetaddress=trim($_REQUEST['streetaddress']); $suitenumber=trim($_REQUEST['suitenumber']); $city=trim($_REQUEST['city']); ![]() so i can just be like print $suitenumber; print ' was the suitenumber posted to this form.'; Also: Am i allowed to do this: $sql = "insert into testtable (fieldone, fieldtwo) values( '$companyname', '$contactfirstname' )"; cause its easier to work with? DangerMouse
Yeah i believe you can put the SQL statement on multiple lines, thats what I do anyway - had exactly the same issue as you when I started doing it - hate that scruffy way it looks!
As for your first point, I guess you could create a little function that would take the contents of the associated array $_REQUEST and create variables of the results based on the array key, although it would be quite crude. I'd also suggest a tad more error checking and validation before inserting into a database. DM perkiset
Scruffy?
There are two forms of string that will dereference, and 2 ways to tell PHPwhat to do.Static strings, of course are surrounded by single quotes ie., 'Hello World' and as such as the quickest type of string because there's no processing executed against them and they are "static" in the way they are compiled into the PHPPCode.Dereferenced strings are surrounded by double quotes, and take just a smidgeon more time because a copy of the string os produced while dereferencing any variables inside of it. Consider: <? php$name = 'Perkiset'; $string = "The name of the person is '$name'"; ?> This also outlines quite clearly why you must have the $ in front of a var JM - how would PHPunderstand my intention in that expression without it?The last form, which I use for HTML dereferencing, SQL statements etc is the TEXTHERE operator like in PERL.<? php$theDate = date('Y-m-d H:i:s', time()); $names[0] = 'Perkiset'; $names[1] = 'Jammaster'; $names[2] = 'NutBalls'; $sql = <<<SOMETEXT select * from contacts where visitdate <= '$theDate' and ( lastname = {$names[0]} or lastname = {$names[1]} or lastname = {$names[2]} ) SOMETEXT; mysql_query($sql); ?> The way to reference complex variables or object properties or, *most significantly* object METHODS, is to wrap them in curly braces. Note that you can derefence OBJECT METHODS as if they were variables in strings... this is a huge tool if you give it a moment of thought. Scruffy? Pretty elegant to me actually... unless I'm misreading entirely. nutballs
on the subject of quotes. I use doubles for SQL statements because of single quotes in the queries. And single quotes for almost everyhing else. Just a covention to make things simpler to keep track of.
DangerMouse
quote author=perkiset link=topic=694.msg4823#msg4823 date=1200074211 Scruffy? Pretty elegant to me actually... unless I'm misreading entirely. Was just referring to long SQL statements on a single line, not instances where they're split - didnt really explain what I meant sorry. Like the use of the textarea thing there, can see me using that in future ![]() DM |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads