need Posted March 12, 2011 Share Posted March 12, 2011 I have Mysql 5.1.54, and whenever i execute the following it says that mysql_query expected a string but received a rescource. I've been looking around and can't find a way to fix this. $query="CREATE TABLE POSTS(num_rows int NOT NULL AUTO_INCREMENT, PRIMARY KEY(num_rows),Name varchar(30),Text varchar(200))"; $result=mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/ Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2011 Share Posted March 12, 2011 Is that the actual code? Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/#findComment-1186629 Share on other sites More sharing options...
need Posted March 13, 2011 Author Share Posted March 13, 2011 Yes...... Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/#findComment-1186856 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2011 Share Posted March 13, 2011 That might be part of your code, but it is not the code where the error is occurring at. It would help if you posted the complete error message and the complete file where the error is occurring. Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/#findComment-1186858 Share on other sites More sharing options...
need Posted March 13, 2011 Author Share Posted March 13, 2011 okay, i checked the line number and that is the spot where the error is, but here is the full thing <?php //have it check if database already exists b4 creating it. $data=mysql_connect("localhost","root",""); if (!$data) { die('Could not connect: ' . mysql_error()); } if (mysql_query("CREATE DATABASE site_data",$data)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } //mysql_query($data); mysql_select_db("site_data", $data); $query="CREATE TABLE POSTS(num_rows int NOT NULL AUTO_INCREMENT, PRIMARY KEY(num_rows),Name varchar(30),Text varchar(200))"; $result=mysql_query("CREATE TABLE POSTS(num_rows int NOT NULL AUTO_INCREMENT, PRIMARY KEY(num_rows),Name varchar(30),Text varchar(200))"); if($result){ echo "Table Created"; }else{ echo "Error Making table"; } mysql_query($data); mysql_close($data); ?> here is the error message: Warning: mysql_query() expects parameter 1 to be string, resource given in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\test site\create database.php on line 40 Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/#findComment-1186862 Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 You're attempting to use the connection resource as a query string in this line: mysql_query($data); It serves no purpose, so remove it and see if that doesn't clear up the error. Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/#findComment-1186865 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2011 Share Posted March 13, 2011 I think you probably need to use a programming editor that shows line numbers so that you can accurately determine where in your code an error is being reported at. Simply amazing. Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/#findComment-1186869 Share on other sites More sharing options...
need Posted March 13, 2011 Author Share Posted March 13, 2011 Thanks pikachu! that cleared it up, and i do have a program that allows line number counting, the error was telling me that it was at the first usage of mysql_query Sorry if this was a retarded problem, the tutorials i have found have been... lacking..... Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/#findComment-1186874 Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 Unfortunately a lot of tutorials are not very well written, and the people who need them the most are typically not even going to know until it's too late. Link to comment https://forums.phpfreaks.com/topic/230426-mysql_query-thinks-string-is-a-rescource/#findComment-1186876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.