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
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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.