PHP variable in MySQL query WHILE string breaks -
Why can not I use the PHP string variable in a MySQL query in a LIKE selector?
$ weekday = '% w%'; Resonant "day of the week"; $ Sql = "Choose from ID of Message ID, where day day" looks like; $ Result = $ pedo-> Query ($ sql); I receive the error message: "SQLSTATE [42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; manual that is to your MySQL server version The correct syntax for using '% w%' on '2%'
I have tried it with double quotes around the variable yet still gets an error.
If I replace it with '% w%' instead of the variable, then it works fine.
I have used the PHP variable in other queries without any problem. I can not understand this.
Edit: Sorry, I think that I was more tired than it was. You are right I posted the wrong query. I was trying to do everything to work with the placeholder and I do not know what I was doing.
But I have a problem Which I can not get.
{Date_def Try ault_timezone_set ( "Pacific / Honolulu"); $ Daynum = array ( "s", "m", "t", "w", "h", "f", "a"); $ weekday = Striptime ("% w"); $ Weekdays = $ daynum [$ weekday]; // $ day = "w"; $ Weekdays = '%' $ weekday '%'; // $ day = "% w%"; Resonant "day of the week"; $ Sql = "Selection ID from message id where day: day of week"; $ S = $ pdo- & gt; Ready ($ sql); $ S- & gt; Bind Value (': Day of the week', '$ weekday'); $ S- & gt; Executed (); $ Result = $ s- & gt; Fetch (); Foreign Currency ($ result as line $) {$ messageids = Array ('id' = & gt; $ line ['id']); // This is an error line) print_r ($ messageids); Exit () And with single quotes I'm working in different ways - sorry. I was actually receiving a different problem completely, which still can not be.
I am using a statement prepared for security and BIND and then recovering the data in a very standardized way. In this example, I can not find it to work.
I come back I:
Warning: C: \ xampp \ htdocs \ ... \ gonogo.php line invalid string 28 Offset 'ID' warning: illegal string offset 'ID' C: \ xampp \ htdocs \ ... \ gonogo.php Arre ([ID on line 28] = & gt; 1) I have to fetch In the other places without problem / problem, the front arrange array combo can not see why this is going wrong. The array should be 1, 4 and 5.
If your field type is not an integer (or number-based, for that matter), you quotes Need to absorb your input with.
$ sql = "Selection ID from message ID where day '$ day of the week'";
But please save and use yourself.
Comments
Post a Comment