Jump to content


Copying Data From HTML table Into MySQL

  • Please log in to reply
1 reply to this topic

#1 j3rmain3

  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 October 2006 - 11:21 AM

I have a table which has been setup in HTML, but now i need to store a rating system for the documents. I really do not want to copy all the data and enter it into mysql manually because there are about 50 documents. Is there a way i could place the data from the html table into mysql by using variables or something like that?

Here is some sample coding incase someone will need coding to work with

Table Coding

echo "<tr>";
echo "<td>Players Name</td>";
echo "<td>Position</td>";
echo "<td>Goals</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Jeremy Beadle</td>";
echo "<td>Striker</td>";
echo "<td>15</td>";
echo "</tr>";


mysql_connect(****,****,****) or die ("ERROR:".mysql_error());
mysql_select_db(****) or die ("ERROR."mysql_error());

$query = "INSERT INTO ( This is where i have no idea what to write to import the data from the exisiting data in the html table into mySQL db )";

The table has already been setup in mysql. All i need to do is copy the info across.

If more coding is need, just send a reply


#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 17 October 2006 - 11:28 AM

It can be done by using fopen() on the html files and then using preg_match() or preg_match_all() or something similar to extract the data.

You'd need to read up on the preg_* functions first.

If someone else has a better idea, I'm sure they'll post it soon.  Maybe something XML related.

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users