Jump to content

[SOLVED] Noob insert into db, help needed


mikebyrne

Recommended Posts

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;

Link to comment
https://forums.phpfreaks.com/topic/148850-solved-noob-insert-into-db-help-needed/
Share on other sites

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?

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();
?>  

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.