Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong in this code (php results from SQL)

Status
Not open for further replies.

joep

Programmer
Jun 4, 2000
15
0
0
NL
Hello, <br><br>I've got three checkboxes on which i want to search for results in my database. Code: <br>--------------------------- <br>if ($submit) { <br><br>if ($webmail ¦¦ $opstartcd ¦¦ $telnet) { <br>$sql = &quot;SELECT * FROM access WHERE &quot;; <br><br>if ($webmail) <br>{$sql .= &quot;webmail = '$webmail &quot;;} <br><br>if ($opstartcd) <br>{if ($webmail) $sql .= &quot;AND &quot;; <br>$sql .= &quot;opstartcd = '$opstartcd &quot;;} <br><br>if ($telnet) <br>{if ($webmail ¦¦ $opstartcd) $sql .= &quot;AND &quot;; <br>$sql .= &quot;telnet = '$telnet &quot;;} <br><br>$result = mysql_query($sql); <br>{ <br>echo &quot;&lt;table border=1&gt;<br>&quot;; <br>echo &quot;&lt;tr&gt;&lt;td&gt;Bedrijf&lt;/td&gt;&lt;td&gt;Pakket&lt;/td&gt;&lt;td&gt;Type&lt;/td&gt;&lt;td&gt;Regio&lt;/td&gt;&lt;/tr&gt;<br>&quot;; <br>while ($myrow = mysql_fetch_array($result)){ <br>printf(&quot;&lt;tr&gt;&lt;td&gt;%s&lt;/td&gt;&lt;td&gt;%s&lt;/td&gt;&lt;td&gt;%s&lt;/td&gt;&lt;td&gt;%s&lt;/td&gt;&lt;/tr&gt;<br>&quot;, <br>$myrow[bedrijf], $myrow[pakket], $myrow[type], $myrow[regio]); <br>}} <br><br>} else { <br>echo(&quot;Oeps! None of the boxes selected.&quot;); <br>} <br>} <br>------------------------------------ <br>When i select a box and post the form i get the following error: <br><br>Warning: Supplied argument is not a valid MySQL result resource in /opt/guide/<A HREF=" TARGET="_new"> on line 30 <br><br>Line 30 is the following piece of code: <br>while ($myrow = mysql_fetch_array($result)) <br><br>I don't see the problem. Do you? <br>Great thanks, <br><br>Joep
 
Normally you must to connect first:<br><FONT FACE=monospace><br>$mysqlcx = mysqlpconnect( $server, $user, $password )<br></font><br>Check the connection and <b>then</b> send a query:<br><FONT FACE=monospace><br>if ( $mysqlcx ) {<br>&nbsp;&nbsp;$mysqlrt = mysql_query( ... )<br></font><br>And, if it is a valid query, <b>then</b> try to get the result set:<br><FONT FACE=monospace><br>if ( $mysqlrt ) {<br>&nbsp;&nbsp;$myrow = mysql_fetch_array( ... )<br></font><br><br>I hope it works...
 
Hello,<br><br>Thanks for the reply.<br>But that wasn't the problem. I had forgotten single quotes (') after $opstartcd $webmail etc.<br>Ofcourse i had to connect first. But this piece of script only works when the 'submit' button is pressed. (first line)<br>Thanks anyway.<br><br>Joep
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top