mikebyrne Posted March 10, 2009 Share Posted March 10, 2009 I'm trying to create a simple php page to enter data to my database but im unsure where to start Im using xampp with mysql The SQL for the table im creating is CREATE TABLE `athy` ( `ID` decimal(10,0) NOT NULL, `Station` varchar(50) NOT NULL, `Sname` varchar(15) NOT NULL, `Fname` varchar(15) NOT NULL, `Address1` varchar(15) NOT NULL, `Address2` varchar(15) NOT NULL, `Address3` varchar(15) NOT NULL, `Address4` varchar(15) NOT NULL, `Vote` varchar(7) DEFAULT NULL, `Division` varchar(15) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 10, 2009 Author Share Posted March 10, 2009 I've written 2 php files to connect and run from the db I run my test.php file <? include("connect.php"); // now you are connected and can query the database $request = mysql_query("select * from athy"); // loop through the results with mysql_fetch_array() while($row = mysql_fetch_array($result)){ echo $row[0]." / ".$row[1]."<br>\n"; } // don't forget to close the mysql connection mysql_close(); ?> But im getting the error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\test.php on line 7 line 7 is while($row = mysql_fetch_array($result)){ Any idea what's wrong? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 10, 2009 Author Share Posted March 10, 2009 I changed it to the following and got it to work <? include("connect.php"); // now you are connected and can query the database $result = mysql_query("SELECT * FROM athy"); while($row = mysql_fetch_array($result)) { echo $row['Fname'] . " " . $row['Sname']; echo "<br />"; } // don't forget to close the mysql connection mysql_close(); ?> 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.