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); Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2011 Share Posted March 12, 2011 Is that the actual code? Quote Link to comment Share on other sites More sharing options...
need Posted March 13, 2011 Author Share Posted March 13, 2011 Yes...... Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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..... Quote Link to comment 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. Quote Link to comment 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.