Jump to content

How to read data from a web page and enter into mysql


Recommended Posts

Hi,

 

I am trying to find a way with PHP to read some data from a website (the url is always static and the return is always 'similar' to ABC1.2.3=987&).

 

I basically need to read the portion between the = and the &, divide this number by 10 and enter this into the next available row in a specific mysql db table with a date and time stamp.

 

Would really appreciate some guidance.

 

Thanks

 

Paul

is this an external website? is this string part of the actual contents of the webpage?

 

It is an external website but the return is simply an unformatted page exactly as detailed. (no html presence at all)

 

I can already send a $out = readfile to the page and display a similar result.  What I can't do is manipulate and stuff it into a DB.

 

Paul

so are you having issues with the regex or the inserting it into the db? or both?

 

As far as the regex is concerned, is the data always going to be in between =...&? is there more than one possible match to consider?

 

As far as the inserting into the db, do you know how to connect to your db and display info? That is, are you looking for help with an actual query string, or do you know nothing about the whole db thing at all?  Do you even have a db setup?

 

In other words, you need to be very specific about your situation.

OK,

 

Yes I need help with the connection string.  I do not currently have the DB set up but I know how to create the DB and the required table.  Apologies for the ignorance but I don't know how to connect my MYSQL table to my PHP page for input or output.  I do currently have many other MYSQL dbs setup and running from this server.

 

The table I will create will have 2 fields.  A time/date stamp plus a numeric field to store this output.

 

The data will ALWAYS be between the =...& but may vary in length.  It will only ever have one match on one single line returned.

 

Please let me know what other information I can supply to assist.

 

Thanks for your help

 

Paul

 

so are you having issues with the regex or the inserting it into the db? or both?

 

As far as the regex is concerned, is the data always going to be in between =...&? is there more than one possible match to consider?

 

As far as the inserting into the db, do you know how to connect to your db and display info? That is, are you looking for help with an actual query string, or do you know nothing about the whole db thing at all?  Do you even have a db setup?

 

In other words, you need to be very specific about your situation.

<?php
   // connect to database
   $conn = mysql_connect('localhost','dbusername','dbpassword') or die(mysql_error());
   $db = mysql_select_db('dbname',$conn) or die(mysql_error());

   // example string
   $blah = "blah=something&blahblah";
   preg_match("/=(.*)&/", $blah, $info);

   // insert into database
   $sql = "insert into table (column) values ('{$info[1]}')";   
   $result = mysql_query($sql, $conn) or die(mysql_error());
?>

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.