Forum Moderators: coopster

Message Too Old, No Replies

string instead.

         

Flolondon

9:26 pm on Mar 22, 2006 (gmt 0)

10+ Year Member




php do not parse '-quoted strings. use "-string instead - I saw this comment on the internet somewhere... in terms of INSERT INTO.. can someone give me an exampe of what a -string instead is..?

jatar_k

9:30 pm on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it is referring to the quotes

rewritten

php does not parse single quoted strings. use double quoted string instead

I don't use double quoted strings actually. When building a var I concatenate them together.

$myvalue = 'apples';
$myvar = "I really love $myvalue";
echo $myvar;
$myvar = 'I really love' . $myvalue;
echo $myvar;

both are the same, I prefer the second.

this wouldn't give the expected results
$myvalue = 'apples';
$myvar = 'I really love $myvalue';
echo $myvar;

jatar_k

9:38 pm on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when taking variables from a form and using them in an insert query you would need to put them together

you shouldn't use variables from your $_POST array directly in your insert as this opens the door for injection and other nasty things so I always suggest pulling them into vars first

pretend we have firstname and lastname coming from our form

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];

how you test to make sure these vars are what they are supposed to be depends on what you are expecting there are threads in the library [webmasterworld.com] about that and I won't cover it here.

so now we could build our query to be sent to our db

$q = "insert into tablename (firstname,lastname) values('" . $firstname . "','" . $lastname . "')";

I used double quotes around the outside because I needed to use single quotes in my string, I am just too lazy to escape if I don't have to and it makes it easier to read

also
[dev.mysql.com...]

Flolondon

9:47 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



ok thanks