1

Rusty, just simply trying to pass stuff through parameters. What am I doing wrong?

//Insert into DB
function insert(x,y,z)
mysql_query("INSERT INTO x (y)
VALUES ('z')");


insert("test","name","Tyler");
4

2 Answers 2

4
function insert($x,$y,$z){
    mysql_query("INSERT INTO ".$x." (".$y.") VALUES ('".$z."')");
}
insert("test","name","Tyler");
Sign up to request clarification or add additional context in comments.

5 Comments

Much more confusing than I remember, thanks! Why the dots around the variables?
. concatenates the variables with your string. Since you are using double-quotes, concatenation is not necessary and the variables can be placed directly into the string and will be evaluated correctly.
The dot is PHP's string concatenation operator. You could also do like "INSERT INTO $x ($y) VALUES ('$z')" if you wanted, but some people don't like that for some reason. Though i'd argue if they don't like it, they shouldn't be sticking all their strings in double quotes...cause then interpolation will only happen when you don't want it to. :P
yeah, i have that habit and like it being colored in editors.
What would be the new way to retrieve data from sqldatabase and turn it into text and echo? Use to be hell.
1

Be sure you are referencing the variable correctly via $:

//Insert into DB
function insert($x, $y, $z)
{
    mysql_query("INSERT INTO $x ($y) VALUES ('$z')");
}


insert("test","name","Tyler");

4 Comments

Yea, I think I was doing it kind of javascripty . Thanks
You're welcome. It's helpful that you always debug your code to ensure that the desired result is occurring properly.
The purpose of debugging is not always to identify bugs. Debugging in itself means to remove errors and to see into the execution of a program by examining it. It is the second part that I was referring to.
What would be the new way to retrieve data from sqldatabase and turn it into text and echo? Use to be hell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.