|
-
Mar 29th, 2006, 06:33 PM
#1
Thread Starter
New Member
mysql_numrows():
Hi not very experienced at using PHP but i am trying to a bring up a query result which the user has typed in the query themselves into a textarea.
this is my code
<?php
include("dbandy.php");
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'db_andrewb';
mysql_select_db($dbname)or die('error finding DB');
$QSTRING = $_SERVER['QUERY_STRING'];
$QSTRING = str_replace('queries=', '',$QSTRING);
echo urldecode($QSTRING);
$query = $QSTRING;
$result = mysql_query($query) or die(mysql_error());
$number = mysql_numrows($result);
if ($number == 0) {
print "Sorry, there were no records matching those criteria";
} else {
for($i=0; $i<$number; $i++){
$degreeid = mysql_result($result,$i,"degreeid");
$degree_name = mysql_result($result,$i,"degree_name");
$modid = mysql_result($result,$i,"modid");
$mod_name = mysql_result($result,$i,"mod_name");
$studentid = mysql_result($result,$i,"studentid");
$stud_fname = mysql_result($result,$i,"stud_fname");
$stud_sname = mysql_result($result,$i, "stud_sname");
$tutorid = mysql_result($result,$i,"tutorid");
$tutor_fname = mysql_result($result,$i,"tutor_fname");
$tutor_sname = mysql_result($result,$i,"tutor_sname");
print "$degreeid, $degree_name, $modid, $mod_name, $studentid, $stud_fname, $stud_sname, $tutorid, $tutor_fname, $tutor_sname<br>";
}
}
mysql_close();
?>
and when trying to put in a query into the text area like SELECT * FROM student this error message comes up:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource
Can anyone help me?
-
Mar 29th, 2006, 06:47 PM
#2
<?="Moderator"?>
Re: mysql_numrows():
use mysql_error() to show the last error that occured from mysql. Could be a problem with your query.
Also use the [php][/php] tags to make your code easier to read.
-
Mar 30th, 2006, 03:40 AM
#3
New Member
Re: mysql_numrows():
Use mysql_num_rows() instead of mysql_numrows()
rgds,
shan
-
Mar 30th, 2006, 04:06 AM
#4
Thread Starter
New Member
Re: mysql_numrows():
right i have tried the mysql_num_rows() and still get the same error, but when i put(mysql_error()) next to the mysql_numrows it get up with a bit extra to the error.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
You have an error in your SQL syntax near '+*+FROM+student++&submit3=submit' at line 1
Last edited by AJByrne; Mar 30th, 2006 at 06:03 AM.
-
Mar 30th, 2006, 06:01 AM
#5
Re: mysql_numrows():
You should use $_GET['queries'] instead of the whole query string as this is urlencoded. Also, I do not recommend that you allow users to enter queries freehand into your script.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|