lee_swire Posted September 1, 2006 Share Posted September 1, 2006 Hello,I am new here so please forgive me if this has been posted before, I did use search but couldn't find the answer. I have processed a form using php and written some of the information to a file on my server. This is because the users that use this system do not accept cookies, and I have disable session variables.I can read the file no problem, but when defining the variables and trying to use them in my SQL statement I get the following error:Warning: Wrong parameter count for mysql_result() in /www/survey/reports/xml/6.php on line 35Warning: Wrong parameter count for mysql_result() in /www/survey/reports/xml/6.php on line 40The PHP code looks like this:Now read from file recently written too*/$lifecycle = file('../xml_lifecycle.txt');$from = file('../xml_date_from.txt');$to = file('../xml_date_to.txt');echo "$lifecycle[0] | $from[0] | $to[0] ";$from_date = $from[0];$to_date = $to[0] ;$life = $lifecycle[0]; // QUESTION 6 START // First get results from DB $sql = 'SELECT count(*) FROM `survey` WHERE `6` = CONVERT( _utf8 \'yes\' USING latin1 ) COLLATE latin1_swedish_ci AND stage = \'$life\' AND date_submitted BETWEEN \'$from_date\' AND \'$to_date\''; $query1 = mysql_query($sql); $yes = mysql_result($query1); $sql2 = 'SELECT count(*) FROM `survey` WHERE `6` = CONVERT( _utf8 \'no\' USING latin1 ) COLLATE latin1_swedish_ci AND stage = \'$life\' AND date_submitted BETWEEN \'$from_date\' AND \'$to_date\''; $query2 = mysql_query($sql2); $no = mysql_result($query2);Does anyone have any suggestions on what is going wrong? I have spent all day trying different things and am really stuck!!Thanks,Lee Quote Link to comment https://forums.phpfreaks.com/topic/19381-using-variable-in-a-sql-statement/ Share on other sites More sharing options...
obsidian Posted September 1, 2006 Share Posted September 1, 2006 the problem is that you're using mysql_result() with the wrong number of arguments. that's what the error means by [i]Wrong parameter count[/i]. mysql_result() is used to pull a specific item from a specific record in the results of a query. if you're trying to get the entire row, you need to use mysql_fetch_array() or similar. if you're trying to pull an individual piece of data, mysql_result() takes either one or two additional parameters (one for the row number to pull from [i]starting with 0[/i] and one for the column name you're wanting to pull).hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/19381-using-variable-in-a-sql-statement/#findComment-84102 Share on other sites More sharing options...
wildteen88 Posted September 1, 2006 Share Posted September 1, 2006 You are using variables in single quotes. Variables will not be parsed if they are using in single quotes. So use double quotes:[code=php:0]$sql = "SELECT COUNT(*) FROM `survey` WHERE `6` = CONVERT( _utf8 'yes' USING latin1 ) COLLATE latin1_swedish_ci AND stage = '$life' AND date_submitted BETWEEN '$from_date' AND '$to_date'";$query1 = mysql_query($sql);$yes = mysql_result($query1, ROW_NUMBER_HERE);[/code]Also the mysql_result function requires two parameters, one for the query result ($query1)and the other the row number Quote Link to comment https://forums.phpfreaks.com/topic/19381-using-variable-in-a-sql-statement/#findComment-84104 Share on other sites More sharing options...
lee_swire Posted September 4, 2006 Author Share Posted September 4, 2006 thanks for your help guys!!!! ::) I knew it would be something simple!! It works a treat now!! Quote Link to comment https://forums.phpfreaks.com/topic/19381-using-variable-in-a-sql-statement/#findComment-85631 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.