Jump to content

Search the Community

Showing results for tags 'mysql php'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 13 results

  1. I've made a PHP web crawler and then made a MySQL table called "dex" as in index, then I connected to the database through PDO and tweaked the code to "INSERT" websites that aren't already crawled into the table, "UPDATE" for websites that are crawled, and used URL hashes as an indicator or "id" for links. The terminal shows all the links and links related to them, the if statement works perfectly and there are no major errors, so why does it not insert the data into the "dex" table? every-time I check the table after the process I only find the row that I inserted manually to test the if statement for "UPDATE" or "INSERT". what can I do to fix this issue and insert the date the crawler retrieves? Test.html: <a href="https://google.com"></a> <a href="https://www.yahoo.com/"></a> <a href="https://www.bing.com/"></a> <a href="https://duckduckgo.com/"></a> Crawler: <?php error_reporting(E_ALL); ini_set('display_errors', 1); $start = "http://localhost/deepsearch/test.html"; $pdo = new PDO('mysql:host=127.0.0.1;dbname=deepsearch', 'root', ''); $already_crawled = array(); $crawling = array(); function get_details($url) { $options = array('http'=>array('method'=>"GET", 'headers'=>"User-Agent: howBot/0.1\n")); $context = stream_context_create($options); // Suppress warnings for HTML parsing errors libxml_use_internal_errors(true); $doc = new DOMDocument(); @$html = @file_get_contents($url, false, $context); // Load HTML content and check for parsing errors if ($doc->loadHTML($html)) { if (!empty($titleElements)) { $title = $titleElements->item(0); $title = $title->nodeValue; } else { $title = ""; } $description = ""; $keywords = ""; $metas = $doc->getElementsByTagName("meta"); for ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); if ($meta->getAttribute("name") == strtolower("description")) { $description = $meta->getAttribute("content"); } if ($meta->getAttribute("name") == strtolower("keywords")) { $keywords = $meta->getAttribute("content"); } } return '{"Title": "'.str_replace("\n", "", $title).'", "Description": "'.str_replace("\n", "", $description).'", "Keywords": "'.str_replace("\n", "", $keywords).'", "URL": "'.$url.'"}'; } else { // Handle the parsing error echo "HTML parsing error: " . libxml_get_last_error()->message . "\n"; return ''; // Return an empty string or handle the error as needed } } function follow_links($url) { global $pdo; global $already_crawled; global $crawling; $options = array('http' => array('method' => "GET", 'headers' => "User-Agent: howBot/0.1\n")); $context = stream_context_create($options); $doc = new DOMDocument(); @$doc->loadHTML(@file_get_contents($url, false, $context)); $linklist = $doc->getElementsByTagName("a"); foreach ($linklist as $link) { $l = $link->getAttribute("href"); if (substr($l, 0, 1) == "/" && substr($l, 0, 2) != "//") { $l = parse_url($url)["scheme"] . "://" . parse_url($url)["host"] . $l; } else if (substr($l, 0, 2) == "//") { $l = parse_url($url)["scheme"] . ":" . $l; } else if (substr($l, 0, 2) == "./") { $l = parse_url($url)["scheme"] . "://" . parse_url($url)["host"] . dirname(parse_url($url)["path"]) . substr($l, 1); } else if (substr($l, 0, 1) == "#") { $l = parse_url($url)["scheme"] . "://" . parse_url($url)["host"] . parse_url($url)["path"] . $l; } else if (substr($l, 0, 3) == "../") { $l = parse_url($url)["scheme"] . "://" . parse_url($url)["host"] . "/" . $l; } else if (substr($l, 0, 11) == "javascript:") { continue; } else if (substr($l, 0, 5) != "https" && substr($l, 0, 4) != "http") { $l = parse_url($url)["scheme"] . "://" . parse_url($url)["host"] . "/" . $l; } if (!in_array($l, $already_crawled)) { $already_crawled[] = $l; $crawling[] = $l; $details = json_decode(get_details($l)); echo $details->URL . " "; $rows = $pdo->query("SELECT * FROM dex WHERE url_hash='" . md5($details->URL) . "'"); $rows = $rows->fetchColumn(); $params = array(':title' => $details->Title, ':description' => $details->Description, ':keywords' => $details->Keywords, ':url' => $details->URL, ':url_hash' => md5($details->URL)); if ($rows > 0) { echo "UPDATE" . "\n"; } else { if (!is_null($params[':title']) && !is_null($params[':description']) && $params[':title'] != '') { $result = $pdo->prepare("INSERT INTO dex (title, description, keywords, url, url_hash) VALUES (:title, :description, :keywords, :url, :url_hash)"); $result= $result->execute($params); //if ($result) { // echo "Inserted successfully.\n"; //} else { // echo "Insertion failed.\n"; // print_r($stmt->errorInfo()); //} } } //print_r($details)."\n"; //echo get_details($l)."\n"; //echo $l."\n"; } } array_shift($crawling); foreach ($crawling as $site) { follow_links($site); } } follow_links($start); //print_r($already_crawled); ?> at first I tried different links that got me an empty value which resulted in errors and warnings then I changed the links and started writing the "UPDATE", "INSERT" if statement and started specifically writing the insert PDO first to test it out. when I executed the the file using command php I got the intended results in term of how it was supposed to look like in the terminal but then I checked on the table and found out that nothing was inserted. I want to insert these to use them in my search engine and make them searchable by query.
  2. I'm creating a report page and can't figure out how to retrieve multiple rows from a table and display them in html. There are 5 data elements in each row and I'm thinking that using a form in the html might be the best way as I'm totally ignorant about tables in html. I'm a newbie to php and can't figure out how to accomplish this. Here's the code that I have so far: <?php $filename = NULL; session_start(); // start of script every time. // setup a path for all of your canned php scripts $php_scripts = '../php/'; // a folder above the web accessible tree // load the pdo connection module require $php_scripts . 'PDO_Connection_Select.php'; //******************************* // Begin the script here // Connect to the database if (!$con = PDOConnect("foxclone")): { echo "Failed to connect to database" ; exit; } else: { $sql = 'SELECT COUNT(IP_ADDRESS) FROM download WHERE FILENAME IS NOT NULL'; $sql1 = 'Update download t2, ip_lookup t1 set t2.country = t1.country, t2.area = t1.area, t2.city = t1.city where ((t2.IP_ADDRESS) = (t1.start_ip) OR (t2.IP_ADDRESS) > (t1.start_ip)) AND ((t2.IP_ADDRESS) = (t1.end_ip) OR (t2.IP_ADDRESS) < (t1.end_ip)) AND (t2.FILENAME is not null and t2.country is null)'; $sql2 = 'SELECT (IP_ADDRESS, FILENAME, country, area, city) from download where FILENAME is not null'; // Update the table $stmt = $con->prepare($sql1); $stmt->execute(); // Get count of rows to be displayed in table $stmt = $con->prepare($sql); $stmt->execute() ; $cnt = $stmt->fetch(PDO::FETCH_NUM); // retrieve one row at a time $i = 1; while($i <= $cnt){ $stmt = $con->prepare($sql2); $row->execute(array('')); // Do I need an array here? // from here on, I'm lost $i++; I'd appreciate any guidance you can provide or understandable tutorials you can point me to. Larry
  3. I have a table containing 6 records i want to display first four records today and today date should be saved against those 4 records.On the next day remaining two records should be displayed and first two records as well and date should be saved and flag should b incremented as well. i hope you guys are getting my point
  4. Ok i have a code that is supposed to put the checkbox number into a data base the table is set up as playernick card1 card 2 card 3 random(to be used later so null in this application) and the date but when i fill out the form i get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CURRENT_DATE()')' at line 1 here is the php code from below where it connects to database $checkBox = implode(',', $_POST['whatcard']); if(isset($_POST['submit'])) { $query="INSERT INTO earlyreg VALUES (playernick,'" . $checkBox . "',.,CURRENT_DATE()')"; mysql_query($query) or die (mysql_error() ); echo "Complete"; } ?>
  5. I have no code yet that why I am posting this. I need a login script something like this: if user = xxx then $db_host = "localhost";$db_user = "1234";$db_pass = "*******";$db_name = "1234";$db_table = "xxx"; else if user = yyy then $db_host = "localhost";$db_user = "1234";$db_pass = "********";$db_name = "1234";$db_table = "yyy"; else if user = zzz then $db_host = "localhost";$db_user = "1234";$db_pass = "********";$db_name = "1234";$db_table = "zzz"; else user = '' then $db_host = "localhost";$db_user = "1234";$db_pass = "********";$db_name = "1234";$db_table = "casual"; Trouble is I need to connect to the database to get the user then disconnect and reconnect to it with the correct table. Also have not attempted to write the login script for the website as I think it might be all part of the same thing.
  6. Hello all, im new to this forum, im a noobie, just started coding about 3 weeks ago, don't be too hard on me. My question is I wan't to check for challenges a user's team posted that have not been excepted after 1 day, then auto refund the user's team back there credits, and then also delete all the challenges. So far here is my code. //Delete all matches not accepted after 1 day $arrayin = array(); $autorefund = mysql_query("SELECT * FROM `challenges` WHERE `a` = " . $team['id'] . " " . "AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < " . ((int) time()) . ")"); if (mysql_num_rows($autorefund) > 0) { while ($autorefund = mysql_fetch_assoc($autorefund)) { $arrayin[] = $autorefund['id']; mysql_query("UPDATE `teams` SET `balance` = `balance` + " . $autorefund['credits'] . " " . "WHERE `id` IN (" . mysql_real_escape_string(implode(',', $arrayin)) . ")"); mysql_query("DELETE FROM `challenges` WHERE `a` IN " . "(" . mysql_real_escape_string(implode(',', $arrayin)) . ") " . "AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 " . "AND (`expires` < " . ((int) time()) . ")"); } } FYI here is the code i had, it works fine, however it will only delete 1 challenge per team, not all of there challenges. $autorefund = mysql_query("SELECT * FROM `challenges` WHERE `a` = " . $team['id'] . " AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < ".((int)time()).")"); if (mysql_num_rows($autorefund) > 0) { while ($autorefund = mysql_fetch_assoc($autorefund)) { if ($autorefund['accepted'] == 0 and $autorefund['expires'] < time()) { mysql_query("UPDATE `teams` SET `balance` = `balance` + " . $autorefund['credits'] . " WHERE `id` = " . $team['id'] . ""); mysql_query("DELETE FROM `challenges` WHERE `a` = " . $team['id'] . " AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < ".((int)time()).")); } } } I inherited this script, its using deprecated statements, i know im not skilled to rewrite the entire site to use prepared statements.
  7. Hello. i am writing an API for lua... that sends POST requests to a php script. this php script is malfunctioning. below is the code and error. Code: <?php $host = $_POST['host']; $port = $_POST['port']; $user = $_POST['user']; $password = $_POST['password']; $db = $_POST['db']; $query = $_POST['query']; $query = urldecode($query); $connection = mysql_connect($host,$user,$password) or die("err1"); mysql_select_db($db) or die("err2"); $resource = mysql_query($query); $rows = array(); while($r = mysql_fetch_object($resource)){ $rows[] = $r; } echo json_encode($rows); //echo $rows; mysql_close(); ?> Error: html passed to JSON:decode(): <br /><b>Warning</b>: mysql_fetch_object(): supplied argument is not valid MySQL result resource in [server url] on line 17 Note: it does actually connect to the Database as per previous experiments with the code. JSON:decode() is working and therefore not the problem, since it was the PHP that gave this error to the JSON handler API. The server is working correctly as i use it all the time to make MySQL requests. though, never with this php code. i use a framework to do it for me. but it seems to be working correctly which verifies this php script ás what is malfunctioning.
  8. I am not a programmer but I am trying to learn mysql, php and some html. I am just trying to pull some data from an exsiting mysql table: mysql> show create table servers ; +---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | servers | CREATE TABLE `servers` ( `server_name` varchar(25) NOT NULL, `source` varchar(50) DEFAULT NULL, `rto` varchar(10) DEFAULT NULL, `hardware_platform` varchar(15) DEFAULT NULL, `status` varchar(25) DEFAULT NULL, `category` varchar(25) DEFAULT NULL, `function_type` varchar(25) DEFAULT NULL, `machine_role` varchar(100) DEFAULT NULL, `notes` varchar(255) DEFAULT NULL, `domain` varchar(35) DEFAULT NULL, `os` varchar(50) DEFAULT NULL, `service_pack` varchar(15) DEFAULT NULL, `manufacturer` varchar(15) DEFAULT NULL, `machine_model_name` varchar(25) DEFAULT NULL, `machine_type` varchar(20) DEFAULT NULL, `machine_model` varchar(20) DEFAULT NULL, `proposed_decommission_date` datetime DEFAULT NULL, `decommission_company` varchar(25) DEFAULT NULL, `decommission_id` varchar(25) DEFAULT NULL, `decommission_pu_date` datetime DEFAULT NULL, `build_method` varchar(15) DEFAULT NULL, PRIMARY KEY (`server_name`), KEY `decommission_id` (`decommission_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 | +---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0. here is my first php that I put together from some examples and it's not pulling any data from the table. I can login with the same credentials and pull the information with the select but the .php gives me no data. I was wondering if someone could help me with what I am doing wrong: version | 5.1.69 <?php $db_host = 'localhost'; $db_user = 'root'; $db_pwd = 'passw0rd'; $database = 'testdata'; $connector = mysql_pconnect($db_host, $db_user, $db_pwd) or trigger_error(mysql_error(),E_USER_ERROR); $table = 'servers'; mysql_select_db($database, $connector);//This connects and selects proper database $query = "SELECT * FROM servers";//This is the query that is sent to MySQL $result = mysql_query($query, $connector) or die(mysql_error()); //Sends the query to the database $row_Details = mysql_fetch_assoc($result); //Grabs the first record of the returned data $fields_num = mysql_num_fields($result); //Returns a count of the returned records - Not really going to use this unless you want to use this for loops or to display a record count ?> <html><head><title>MySQL Table Viewer</title></head><body> <table border='1' width="900"> <tr> <td align="center">Server Name</td> <td align="center">Platform</td> <td align="center">RTO</td> <td align="center">Domain</td> <td align="center">Operating System</td> <td align="center">Service Pack</td> <td align="center">Status</td> <td align="center">Category</td> </tr> <?php do { ?> <tr> <td align="center"><? echo $row_Details['server_name'];?></td> <td align="center"><? echo $row_Details['platform'];?></td> <td align="center"><? echo $row_Details['rto'];?></td> <td align="center"><? echo $row_Details['domain'];?></td> <td align="center"><? echo $row_Details['os'];?></td> <td align="center"><? echo $row_Details['service_pack'];?></td> <td align="center"><? echo $row_Details['status'];?></td> <td align="center"><? echo $row_Details['category'];?></td> </tr> <?php } while ($row_Details = mysql_fetch_assoc($result)); ?> <tr> <td colspan="8" align="right">Total Records Returned: <? echo $fields_num;?> </table> <? mysql_free_result($result); ?> </body> </html> Thank you in advance if anyone could help me with this.
  9. Hello, i have a simple mysql database and i use some forms to write data to the databases. This is done by some novice users, wich i am myself too. However i dont want them to login to phpadmin when they made a typo or want to delete a record. Is there a simple tool wich i can install on the webserver that gives a simple overview of a table with a delete and edit button? I tried looking for some but i cannot find it... Thanks!
  10. Hi I have this piece of code part of a larger code block: $page = '../../register.php'; $msg = $error['register']; $msg .= mysql_error($link); header("Location: templates/frontend/error.php?msg=$msg&page=$page"); everything works if I remove the "$msg .= mysql_error($link);" line. the line bellow comes from a language, file and if the Mysql_error is not on the line, it shows up. with the mysql_error, just get ablank line Any help please?
  11. I am running a query that works until I add the variable $selections. This is from a multi-select dropdown box. I am sure my syntax is off on this. I am using MySQL 5.0 Error message is "Cannot Parse Query" SELECT tblLocations.CityID, tblDetails.DetailName, tblRestaurants.RestName, CONCAT(tblLocations.StreetNumber,' ',tblLocations.Street) Address, tblLocations.Phone, tblLocations.Price, tblLocations.Rating, tblRestaurants.RestPage FROM (tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID) INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID GROUP BY tblLocations.CityID, tblLocations.AreaID, tblLocations.CuisineID, tblDetails.DetailName, tblRestaurants.RestName, tblLocations.Street, tblLocations.Phone, tblLocations.Price, tblLocations.Rating HAVING tblLocations.CityID='16' AND tblLocations.AreaID='131' AND tblLocations.CuisineID='3' AND tblDetails.DetailName='( ' . implode(' AND ', $selections) . ' )' ORDER BY tblRestaurants.RestName ASC
  12. Hey folks, I'm trying to create my first Login script using php to check for username and password in a MYSQL database. The script seems succesful at connecting to the database, however when I retrieve results from a table that I have confrimed exsist, the mysql_num_rows($result); returns zero, Can anyone suggest a solution or a diagnosis path? Here is what I have: LAMP server PHP 5.4.4-7 MYSQL Ver 14.14 Distrib 5.5.24 <?php ob_start(); $host="localhost"; // Host name $username="pi"; // Mysql username $password="raspberry"; // Mysql password $db_name="n2it2_database"; // Database name $tbl_name="email_list"; // Table name // Connect to server and select databse. $dbc = mysqli_connect("$host", "$username", "$password", "$db_name")or die("cannot connect"); $sql="SELECT * FROM email_list"; $result=mysqli_query($dbc, $sql) or die('Error quering database.'); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" echo "Success!"; } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> login_script 2.php
  13. Hi I am trying to pull data from a MySQL table but it keeps returning some of the PHP code instead of the results. <? $db_server = '127.0.0.1'; $db_usr = 'user123'; $db_pass = '123456'; $db_database = 'test'; $con = mysql_connect($db_server, $db_usr, $db_pass, $db_database); if (!$con) { die('Could not connect: ' . mysql_error()); } $query = "SELECT * FROM bookings WHERE `booking_start` <= NOW( ) ORDER BY booking_start"; $result = mysql_query($query); echo mysql_error(); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bookingnum = $row['booking_num']; $servernum = $row['server_num']; $usrnum = $row['usr_num']; $start = $row['booking_start']; $end = $row['booking_end']; $creation = $row['booking_made']; echo " <div> bookingnum: $bookingnum<br /> servernum: $servernum<br /> usrnum: $usrnum<br /> start: $start<br /> end: $end<br /> creation: $creation<br /> </div> "; } mysql_close($con); ?> So please tell me if I am missing something, but this is what my query returns. and this is what the MySQL table looks like.
×
×
  • 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.