Jump to content

[SOLVED] mysql_query and then How do I use the results?


bumba000

Recommended Posts

Hi All,

        I have a connection to my db finally.  I use

$dbResults = mysql_query("SELECT website_url2 FROM url", $connection);
if(!$dbResults) {
die("Database Table Selection Failed: " . mysql_error());
}

while ($row = mysql_fetch_array($dbResults)) {
echo $row[0].', ';
}

 

To see all of my results in my browser just like the tutorials say. It works! Great! Now I need to use those results as a list of urls with the following code kinda like a foreach.

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Uncomment this for Windows.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_URL, $websites);

$result = curl_exec($ch);

echo '<pre>';
//print_r(curl_getinfo($ch));
echo '</pre>';

echo 'Errors: ' . curl_errno($ch) . ' ' . curl_error($ch) . '<br><br>';
if (curl_errno($ch) == 0)
{echo 'Good SSL';} 
else {
echo 'bad ssl:'.$websites;}
//$_POST['$websites'];
//$badSiteMessage = "This website currently has a broken or no SSL:\r\n" . $websites;
//mail($myaddress, 'Automated Bad SSL Scan Report', $badSiteMessage);}

//echo $ch;
curl_close ($ch);

echo '<br>'.'EOF';

 

So instead of the while loop that I have there I need to know how to get my results into a variable named $websites in a usable fashion. I have been beating my head against this wall for almost 24 hours. Please help me. I'm just not sure how much longer I can keep this up.

 

$myName = "John";

 

Thanks in Advance,

                    echo $myName;

Link to comment
Share on other sites

<?php

if ($dbResults = mysql_query("SELECT website_url2 FROM url", $connection)) {
  if (mysql_num_rows($dbResults)) {
    while ($row = mysql_fetch_assoc($dbResults)) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_TIMEOUT, 30);
      curl_setopt($ch, CURLOPT_HEADER, 1);
      curl_setopt($ch, CURLOPT_VERBOSE, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_URL, $row['website_url2']);
      if ($result = curl_exec($ch)) {
        if (curl_errno($ch) == 0) {
          echo 'Good SSL';
        } else {
          echo 'bad ssl:' . $row['website_url2'];
        }
      } else {
        echo 'Errors: ' . curl_errno($ch) . ' ' . curl_error($ch) . '<br><br>';
      }
      curl_close ($ch);
      echo '<br>'.'EOF';
    }
  } else {
    die("Database Table Selection Failed: " . mysql_error());
  }
} else {
  echo "query failed";
}

?>

Link to comment
Share on other sites

Thank you soooo much for your quick reply. Yeah it will prolly be a few months more before I can just come up with something like that. I did alter it slightly but I still get no "bad ssl" for a known bad ssl url that I have in my db.

I have 3 urls in the db. 2 are good 1 is bad. The results that I get in the broswer are

 

Good SSL

EOF

Good SSL

EOF

 

 

if ($dbResults = mysql_query("SELECT website_url2 FROM url", $connection)) {
  if (mysql_num_rows($dbResults)) {
    while ($row = mysql_fetch_assoc($dbResults)) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_TIMEOUT, 30);
      curl_setopt($ch, CURLOPT_HEADER, 1);
      curl_setopt($ch, CURLOPT_VERBOSE, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_URL, $row['website_url2']);
      if ($result = curl_exec($ch)) {
        if (curl_errno($ch) == 0) {
          echo 'Good SSL';
        } else {
          echo 'bad ssl:' . $row['website_url2'];
        }
      
      curl_close ($ch);
      echo '<br>'.'EOF'.'<br>';
    }
}
}
}

?>

 

 

Please advise.

 

Thanks again,

                  John

Link to comment
Share on other sites

That does not appear to be the answer. WOW. This is worse than spanish!

 

I need to see two things here in my browser. Good SSL and Bad SSL.

For those that are good show Good SSL and for those that aren't good show Bad SSL.

 

Why is this so complicated? If I wanted to go to the nearest city and take a php course which class would I ask for?

 

Thanks,

        John

Link to comment
Share on other sites

You might try....

 

<?php

if ($dbResults = mysql_query("SELECT website_url2 FROM url", $connection)) {
  if (mysql_num_rows($dbResults)) {
    while ($row = mysql_fetch_assoc($dbResults)) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_TIMEOUT, 30);
      curl_setopt($ch, CURLOPT_HEADER, 1);
      curl_setopt($ch, CURLOPT_VERBOSE, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_URL, $row['website_url2']);
      if (curl_errno($ch) == 0) {
        echo 'Good SSL';
      } else {
        echo 'Bad SSL:';
      }
      curl_close ($ch);
      echo '<br />';
    }
  } else {
    die("query found no results";
  }
} else {
  echo "query failed"  . mysql_error());
}

?>

Link to comment
Share on other sites

This give me Parse error: syntax error, unexpected ';' in /home/hackerse/public_html/sslTest4.php on line 33

 

which is :      die("query found no results";

No way that I alter this makes the browser happy.

 

Also. How will this make the good and the bad ssl urls show up in the browser.

 

Basically in the end what I would like to do is if it's good (curl_errno ==0) I see Good SSL if (curl_errno > 1) I see Bad SSL.

 

 

Link to comment
Share on other sites

Thank you all for your help on this. In the end it was a little from each and my goofy way of hijacking php.

 

$myQuery = mysql_query("SELECT website_url2 FROM url", $connection);
if(!$myQuery) {
    die("Database table Selection Failed: " . mysql_error());
}


  while ($row = mysql_fetch_assoc($myQuery)) {

//Filename: curl_test.php

$ch = curl_init();

curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Uncomment this for Windows.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_URL, $row['website_url2']);

$result = curl_exec($ch);

if (curl_errno($ch) == 0){
echo 'Good SSL '.$row['website_url2'];
} 
else {
echo 'bad ssl: '.$row['website_url2'];
}


curl_close ($ch);

echo '<br>'.'EOF'.'<br>';
}
?>

 

This gives me the result

 

 

Once again, Thank you so much for your time and consideration with this super newb.

 

Best Regards,

                  John

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.