I keep getting the following error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in.... On line 7 in the code below:
Employees account created successfully...
Bạn đang xem: Php
";echo "Click here to Login.";}else?>
Employees account created successfully...";echo "Click here lớn Login.";else?>
I"m not sure if it is just the way I bởi it, but I thought the PHP variable/array should be outside of the quotes like below:
$result= mysql_query("select * from service where serviecid="" . $_POST Sorry, I was completely wrong before. I"ve just noticed what is actually wrong with the code.... You appear lớn have a slight typo on your column name, you have wrote serviecid, rather than serviceid
I"m not sure if it is just the way I vày it, but I thought the PHP variable/array should be outside of the quotes lượt thích below:
$result= mysql_query("select * from service where serviecid="" . $_POST
Nope. It is perfectly valid lớn put variables inside strings that are defined with double quotes. However, you have to lớn be careful. Based upon whether the variable is next to other text or not it can be mis-parsed. Plus, arrays cannot use quotes around the key when used in double quoted strings without specific delimiters (more below). But, your example above is actually incorrect. Because the array variable is defined outside a quoted string, you should have quotes around the array key. That will work, but it is the wrong way to bởi it because the PHP parser will first try khổng lồ find a constant with the name serviceid. If not found it will then use that value as the key name. I typically define my variables inside double quoted strings but I always enclose them in curly braces, , lớn ensure they are parsed correctly. You should read this page which has all the information you need to lớn understand how to lớn define strings and how they are interpreted: http://php.net/manual/en/language.types.string.php
Maclovin: First off, use < code > tags when posing code. Your problem is that your query is failing so the return value of $result is the Boolean false. You shoudl first demo your queries in PHPMyAdmin or whatever database management tool you use. Then, you should also địa chỉ cửa hàng error handling to lớn your code. The way you have it provides no information if there is an error or not or how to lớn fix it. Plus, the code you are using has a lot of flaws:
1) The mysql_ functions are deprecated
2) You are using input đầu vào from the user directly in the query without escaping it - opening yourself up lớn SQL Injection
3) The two select queries at the top have no purpose - the results aren"t used anywhere
Anyway, you can change those queries to show whatever error is displayed. This is just a quick example script khổng lồ point you in the right direction. I would have more code for a real application.
Xem thêm: Đọc Truyện Tổng Tài Bá Đạo Yêu Em Đến Thiên Trường Địa Cửu Kiều Nhã Linh
//Escape the user submitted value$serviceid = mysql_real_escape_string(trim($_POST<"serviceid">));//Create the query as a string$query = "select * from service where serviceid="$serviceid"";//Execute the query$result= mysql_query($query);//Check if query failed or had no resultsif(!$result) echo "Query Failed!Query: Error: " . Mysql_error();elseif(!mysql_num_rows($result)) echo "The query returned 0 results.$query";else $row1 = mysql_fetch_array($result);
Link lớn commentShare on other sitesQuery: Error: " . Mysql_error();elseif(!mysql_num_rows($result)) echo "The query returned 0 results.$query";else $row1 = mysql_fetch_array($result);" data-webShareUrl="https://khansar.net/topic/281178-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-in/?do=findComment&comment=1445076">More sharing options...