PHP - Php Runs With Ajax In Network Tab No Errors...
Hello all, <?php // Connect to Phpmyadmin database localhost. $hostname = "localhost";//"";127.0.0.1 $username = "root"; $password = "password";//"password"; $dbname = "test"; $conn = new mysqli($hostname, $username, $password, $dbname); if($conn -> connect_error) { die("Connection failed: " . $conn -> connect_error); } // USED to CHANGE the db. - (mysqli_select_db($con, "test") or die()); /* Check to make all fields entered -make sure submitted- #2*/ if(isset($_POST["register"])) { if(!$_POST["email"] | !$_POST["password"] | !$_POST["password2"]) { die("You did not fill in all the fields"); } /* do escape strings for SQL injection */ $emailsafe = mysqli_real_escape_string($conn, $_POST["email"]); $passsafe = mysqli_real_escape_string($conn, $_POST["password"]); $pass2safe = mysqli_real_escape_string($conn, $_POST["password2"]); /* Check and see if email EXISTS in db. */ /* Insert email in db if does not exist */ $sql = "SELECT email FROM users WHERE email = '$emailsafe'";//limit 1 $result = $conn->query($sql) or die("invalid email check " . mysqli_error($conn)); $numrows = mysqli_num_rows($result); if($numrows != 0) { die("Sorry the email " . $_POST["email"] . "is already in use"); } // check if passwords both match if($_POST["password"] != $_POST["password2"]) { die("Passwords did NOT match"); } // if passwords match encrypt $hashedpass = password_hash($passsafe, PASSWORD_DEFAULT); // With everything escaped and hashed INSERT into db. $sqlINSERT = "INSERT INTO users(email, password) " . "VALUES('" . $emailsafe ."','". $hashedpass ."')"; if($query = $conn->query($sqlINSERT)=== TRUE) { echo '<script type="text/javascript">alert("Successfully INSERTed");</script>'; } else { die("Unsuccessful"); } $conn->close(); ?>
I ran my php with ajax and it creates the file successfully so i know it runs. I wanted to setup PHP debugging with atom or visual studio but i have not been able to successfully do that... I tried with xdebug so i just use the network tab inchrome to find if errors exist. Similar Tutorials//my php code sample <?php include_once('con.php'); if(isset($_POST['username'])){ $message = []; if(empty($_POST['username'])){ $message['username'] = 'username required'; } #some validation continue... $data = $_POST['username']; if (count($errors) === 0){ #ccode... $message['username'] = 'success your name saved'; } } ?> //my jquery ajax $('.username').click(function() { $.ajax({ url: 'user.php', method: 'POST', data: $('.user').serialize(), success: function(data) { swal('Wow!','success message from php','success'); }, error: function(data) { swal('Oops!','error message from php','error'); } }); return false; });
$news='news'; $sql_news = "INSERT INTO `rise`.`news` ( `user` , `message` ) VALUES ( :id, :news );"; $q_news = $conn->prepare($sql_news); $q_news -> execute(array(':id'=>$id, ':news'=>$news)); print_r($q_news); echo $q_news->rowCount();Why does it echo 1 instead of 2 when everything else on the page is turned off for processing, and it's the last thing on the page? Why do 2 inserts happen? How would I go about settings up a verification system with scripts that I write, so that I could sell scripts but if they were to get leaked or something I could kill the script, is there a way to set up a IP verification system when a script is run through CLI so it only runs if someones IP matches the one in the script? Write a function Counter() that keeps track of the number of times it is called. This function should not take any parameters and return the number of times that it has been called. Hi, I have a script that reads data from a website and insert this into a DB and every time a record is written into DB the script gives an output on the screen When I run this script local on my computer it runs ok and the screen update is every 20 or 30 seconds (not realtime) i though this maybe because of my computer is to slow etc. When I upload this to the server, it's even worse, no updates at all but it does insert the records into the DB. I believe it must be a setting in the Apache or PHP server. Anyone please, advice Thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356031.0 I have this function and for some reason it is running over 100 queries on page load. I'm not sure what I am doing wrong. Can I please get some guidance on this? Code: [Select] <?php function fetch_users($page = 1, $per_page = 20, $type = null, $country = null, $state = null) { $start = (int)(($page - 1) * $per_page); $per_page = (int)$per_page; $type = (int)$type; $country = (int)$country; $state = (int)$state; $sql = "SELECT `users`.`id`, `users`.`firstname`, `users`.`lastname`, `users`.`username`, `users`.`email`, `users`.`gender`, `users`.`accounttype`, `users`.`personalweb`, `users`.`guestviews`, `users`.`iviews`, `users`.`eviews`, `users`.`credentials`, `users`.`specialties`, `users`.`country`, `users`.`city`, `users`.`state`, `users`.`phonenumber`, `users`.`dateofbirth` AS `dob`, `users`.`mail_status`, `users`.`status`, `investor_info`.`investor_type`, DATE_FORMAT(`users`.`dateofbirth`,'%D') AS `dayofbirth`, DATE_FORMAT(`users`.`dateofbirth`,'%c') AS `monthofbirth`, DATE_FORMAT(`users`.`dateofbirth`,'%Y') AS `yearofbirth`, DATE_FORMAT(`users`.`dateofbirth`,'%D \of %M %Y') AS `dateofbirth`, DATE_FORMAT(`users`.`signupdate`,'%h:%i %p %M %e, %Y') AS `signupdate`, SUM(`investor_info`.`capital_available`) AS `totalavailable`, `companytype`, `capital` FROM `users` LEFT JOIN `investor_info` ON `users`.`id` = `investor_info`.`uid` LEFT OUTER JOIN employees ON users.id = employees.userid LEFT OUTER JOIN ( SELECT companies.companyid, companies.companytype AS `companytype`, SUM(companies.capital) AS `capital` FROM `companies` GROUP BY companies.companytype) SumCompanies ON employees.companyid = SumCompanies.companyid WHERE `users`.`status` > 2 "; if($type != null) { $acctype = $type - 1; $sql.= "AND`users`.`accounttype` = {$acctype} "; } if($country != null) { $sql.= "AND`users`.`country` = {$country} "; } if($state != null) { $sql.= "AND`users`.`state` = {$state} "; } $sql.= "GROUP BY `users`.`id` ORDER BY `users`.`id` DESC LIMIT {$start}, {$per_page}"; $result = mysql_query($sql) or die(mysql_error()); $users = array(); $i = 0; while($row = mysql_fetch_assoc($result)) { $users[$i] = array( 'id' => $row['id'], 'firstname' => $row['firstname'], 'lastname' => $row['lastname'], 'username' => $row['username'], 'email' => $row['email'], 'gender' => $row['gender'], 'accounttype' => $row['accounttype'], 'guestviews' => $row['guestviews'], 'iviews' => $row['iviews'], 'eviews' => $row['eviews'], 'credentials' => $row['credentials'], 'specialties' => $row['specialties'], 'country' => $row['country'], 'state' => $row['state'], 'city' => $row['city'], 'phonenumber' => $row['phonenumber'], 'dob' => $row['dob'], 'mail_status' => $row['mail_status'], 'status' => $row['status'], 'investor_type' => $row['investor_type'], 'dayofbirth' => $row['dayofbirth'], 'monthofbirth' => $row['monthofbirth'], 'yearofbirth' => $row['yearofbirth'], 'dateofbirth' => $row['dateofbirth'], 'signupdate' => $row['signupdate'], 'totalavailable' => $row['totalavailable'], 'companytype' => $row['companytype'], 'capital' => $row['capital'], ); $i++; } return $users; } ?> I have a script that is mostly written in PHP with a little JS Ajax for updating. It won't stop. There are some cookies and a couple of simple sessions. I've created a 'destroy' page which destroys the session and deletes the cookies but the program still won't stop. I've deleted the files from the server - the script doesn't exist - and yet if I upload the script after several minutes it updates where it left off. I simply can't figure out how to stop of otherwise 'destroy' this script. What I've tried: A redirect page that includes the following: unset($_SESSION['FOR-EACH-SESSION']); setcookie("FOR-EACH-COOKIE", "", time() - 42000); session_unset(); session_destroy(); die; exit; Deleting the script from the server does not stop the script. Yes, if I go to the script after the files have been deleted I receive a 404 error naturally. Yet, when I upload the files again the script still starts off where it left off, it has sessions from the server that still exist. I don't get. Is there anything else I can do? Hello, I had updated from PHP 5.x to PHP 7.2. The issue is that my cron files are not running now. The sites based on php 5 code runs without any issues. The cron files when run from cmd are producing errors like to change to mysqli. Any solutions? Thanks. Hi all, I have two issue with script. 1. It works in PhpEd and with apache but doesn't work at remote server with apache. Error is well known - "Warning: Cannot modify header information - headers already sent " 2. when I added more than 20 records like $var = $_POST['var']; it stops work local. Error is same. adminka_wrapp.php Code: [Select] <?php $addFormatName = $_POST['addFormatName']; $addFormatDes = $_POST['addFormatDes']; $page = $_GET['page']; if (isset($addFormatName) && isset($addFormatDes)) { $page = 'add_formats'; } else if ($page == NULL) { $page = "user_access_log"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="../style/adminkaview.css"> </head> <body> <div class="col-wrap1"> <div class="col-wrap2"> <div class="col1"> <div class="content" id="c1"> <p><a href="?page=view_add_format">Format and extensions</a></p> </div> </div> <div class="col2"> <div class="content" id="c2"> <?php require("$page.php");?> </div> </div> <div class="clear"></div> </div> </div> </body> </html> view_add_format.php Code: [Select] <?php require_once "../function.php"; $q = connect("SELECT `formats`.* FROM `xxx`.`formats` "); echo "<form method='post' action='adminka_wrapp.php'> <table> <tr> <td>id</td> <td>Formats Name</td> <td>Description</td> </tr>"; while($rowResult = $q->fetch_assoc()) { echo "<tr>"; $id = $rowResult["id"]; $formatName = $rowResult["f_name"]; $description = $rowResult["description"]; echo "<td>".$id."</td>" ."<td>".$formatName."</td>" ."<td>".$description."</td>"; echo "</tr>"; } echo " <tr> <td> <input type='submit' value='AddFormat' name='submitAddFormat'> </td> <td> <input type='text' name='addFormatName' maxlength='20' size='5'> </td> <td> <input type='text' name='addFormatDes' maxlength='20' size='5'> </td> "; echo "</table> </form>"; ?> add_formats.php Code: [Select] <?php require "../function.php"; if (isset($addFormatName) && isset($addFormatDes) ) { $q = connect("INSERT INTO `xxx`.`formats` (`id` ,`f_name` ,`description` ) VALUE (NULL ,'$addFormatName' ,'$addFormatDes' ) "); header("Location: adminka_wrapp.php?page=view_add_format"); exit(); } ?> function.php Code: [Select] <?php function connect($query) { $db = new mysqli('127.0.0.1', 'xxx', 'xxx', 'xxx'); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $result = $db->query($query); $db->close(); return $result; } ?> Hello there
After a few years of spending less and less time coding, I've got a lot of catching up to do. Back when I left I usually would run without classes. Now this is a big deal for me today.
I do understand the concept of classes and already did some working models, mostly from my learning process.
Now here is what is bothering me:
<?PHP class database { // Variables public $test; // Constructor public function __construct() { $test = "4"; } // Functions // public function test() { var_dump($this->test); } } $test = new database; $test->test(); ?>Wether I run this script on itself, nor through another file, this does work. What i get is: NULL The constructor does run, I did an echo inside it. Also it does not matter if the variable is public, private or protected - it will be always NULL. Error_reporting is on E_ALL, does not show any errors. What have I overlooked? I have the following php code that errors as indicated: $query = $con->query('SELECT FILENAME, country, area, city FROM download WHERE FILENAME is not null'); Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'country' in 'field list' in /home/larry/web/test/public_html/report1.php:47 Stack trace: #0 /home/larry/web/test/public_html/report1.php(47): PDO->query('SELECT FILENAME...') #1 {main} thrown in /home/larry/web/test/public_html/report1.php on line 47 The Select statement doesn't error when run in mysql shell or phpmyadmin. Here's the result of show create table download: localhost/test/download/ http://localhost/phpmyadmin/tbl_sql.php?db=test&table=download&token=5739c407033be3e118287bc7a9041c2c Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. Your SQL query has been executed successfully. show create table download download CREATE TABLE `download` ( `ID` int(5) NOT NULL AUTO_INCREMENT, `LOG_TIME` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `IP_ADDRESS` int(64) unsigned NOT NULL, `FILENAME` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `country` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `area` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `city` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=1266 DEFAULT CHARSET=utf8 COLLATE=utf8_general_mysql500_ci Does anyone have an idea why this is happening? dear folks
this question is regarding the plugin update, file uploader and SFTP - on a wordpress that runs on secured- server
I think I know the answer to the following question as "not possible" but I figured I would check. my sites are on servers where we disable FTP access and only use SFTP access, and also on a different port (not port 22). what if i want to use a automated maintaining service like the following https://mainwp.com http://wwww.infinitewp.com automated Installing and updating plugins to the sites does not seem to work and I assume this is the reason why. I'm also assuming the File uploader extension will not work either. Can anyone confirm this for sure though? Any ideas as far as workaround? one might think of the following way: Can you try adding your SFTP settings into the wp-config of one of my sites to see if that allows the functions to work? we can see an example in http://codex.wordpre...g_wp-config.php under WordPress Upgrade Constants or possibly try this plugin SSH SFTP Updater Support do you have any idear!? cf: https://mainwp.com/f...&highlight=sftp Hi, I'm a bit of a newbie when it comes to PHP. I'm a thirs year music/music tech student and for my disseration I took a very ambitious task. I want to create a sort of social networking site for musicians. But I wanted to create it dynamically using PHP and MySQL. I want to basically allow users to register and sign up with their details basically. But the first problem I came across was actually making a custom registration page, I wanted things such as post codes (zip codes) so that I would then have a Google Maps overlay showing where users were. So that you could 'see' you local music 'scene'. So far I've been playing around with Joomla, Drupal and WordPress. I tried writing the PHP from scratch but after following various tutorials, but I had no luck what-so-ever with that approach. So I started using content management systems, which got me a lot closer, but I found I couldn't really edit custom registration pages etc. And the I would have no idea how to get the Google maps idea working. If anyone could nudge me in the right direction and give me a few tips and ideas as to how I'm most likely to achieve this then please reply, I would be highly grateful for you responses. Thanks, Ewan Valentine. I have a PHP app that I wrote that requires a new IP address each time that it is run. Currently I use Tor on my desktop and the Vidalia app to change the Tor identity each time I run the script but I want to automate this. Can anyone help with switching Tor identities with PHP? Essentially after my script runs I need to call a function that switches to a new Tor identity. I have the following code but it doesn't seem to work, and I am not sure why. I am running this from XAMPP on OSX, Tor is running locally (client not server)... in my Tor settings I have 127.0.0.1 and port 9051, set to "no password"... Code: [Select] <?php function tor_new_identity($tor_ip='127.0.0.1', $control_port='9051', $auth_code='') { $fp = fsockopen($tor_ip, $control_port, $errno, $errstr, 30); if (!$fp) { return false; //can't connect to the control port } fputs($fp, "AUTHENTICATE $auth_code\r\n"); $response = fread($fp, 1024); list($code, $text) = explode(' ', $response, 2); if ($code != '250') { return false; //authentication failed } //send the request to for new identity fputs($fp, "signal NEWNYM\r\n"); $response = fread($fp, 1024); list($code, $text) = explode(' ', $response, 2); if ($code != '250') { return false; //signal failed } fclose($fp); return true; } tor_new_identity(); ?> Hi all, I am trying to create a socket that can read from and write to a client. This is my first attempt at it and the code in question is based more or less on a python script a friend sent me as well as some php tutorials google supplied. The problem is (and this seems to be a reoccurring one) when I run it from the command line Code: [Select] php -q server.php nothing visibly happens. Can anyone see what the problem might be? Code: [Select] <?php $host = "localhost"; $port = 50007; set_time_limit(0); // no timeout $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); // create $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); // bind $result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); // listen echo "Waiting for connections...\n"; $contact = socket_accept($socket) or die("Could not accept incoming connection\n"); // accept $input = socket_read($contact, 1024) or die("Could not read input\n"); // read $input = trim($input); // clean $output = "Greetings, you have connected to a socket.\n"; socket_write($contact, $output, strlen ($output)) or die("Could not write output\n"); // return socket_close($contact); // close socket socket_close($socket); // close socket ?> This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=327407.0 Hi,
I'm not sure if this is possible, however I'm sure somebody will be able to point me in the right direction. Relativley new to php here.
I would like to write a small app that will change my IP/Subnet Mask/Gateway depending on a selection made from a dropdown list. I will have a tota; of 50 different IP settings & drop downs (each drop down will represent a different location)
I have yet to start writing the app, just on paper so far - can this be done?
I have seen examples of batch scripts like the one below that work, would I need to incorporate something like this into my php?
netsh int ipv4 set address name="Local Area Connection" source=static address=10.127.86.25 mask=255.255.255.240 gateway=10.127.86.30This is just a personal project, I'm trying to further my knowledge! Thanks J Right now I redirect to index page after I delete a record. However I am looking to make it so that I can delete a record without redirecting the page. I know this can be accomplised using Ajax. I have spent countless hours before trying to make it work, but it did not work.
So here is a basic setup I created. Can you please update it with ajax code so that I can see how it's done properly?
<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>Home Page</title> </head> <body> <div class="record" > <a href="record.php?id=<?php echo $record_id ?>"><?php echo $record_name; ?></a> <div class="delete-record"> <a href="delete.php">Delete Record</a> </div> </div> </body> </html> Edited by man5, 18 August 2014 - 08:55 PM. |