Jump to content

php/Mysql Insert refused


nisroc
Go to solution Solved by boompa,

Recommended Posts

I get this error when I try to scrap data and enter it  directly into a Mysql database. The error i get is:

 

Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in D:\xampp\htdocs\scripts\index.php on line 7
Could not connect: No connection could be made because the target machine actively refused it.

 

It works just cannot get it to insert data, I am quite a rookie at php/mysql and my only guess is something to do with my query and table.

 

Can anyone help out here?

<?php

$dbhost = 'localhost:3036';
$dbuser = 'Name';
$dbpass = 'pass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

// Scrap
include('simple_html_dom.php');

$html = file_get_html('http://www.lottolore.com/lotto649.html');

$one = $html->find('table[width=480]', 0)->find('td', 0)->plaintext;
$two = $html->find('table[width=480]', 0)->find('td', 1)->plaintext;
$three = $html->find('table[width=480]', 0)->find('td', 2)->plaintext;
$four = $html->find('table[width=480]', 0)->find('td', 3)->plaintext;
$five = $html->find('table[width=480]', 0)->find('td', 4)->plaintext;
$six = $html->find('table[width=480]', 0)->find('td', 5)->plaintext;
$seven = $html->find('table[width=480]', 0)->find('td', 6)->plaintext;


$bonus = str_replace('Bonus ', '', $seven);
$today = date("Y-m-d");

//Scrap end

$sql = 'INSERT INTO draws '.
       '(Date, Number1, Number2, Number3, Number4, Number5, Number6, Bonus) '.
       'VALUES ( $today, $one, $two, $three, $four, $five, $six, $bonus )';


mysql_select_db('lotto');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
?>
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.