Posts

Showing posts with the label php

search for custom post on AJAX response in WORDPRESS

search for custom post on AJAX response in WORDPRESS I search for a post with certain $value in posts of custom post type with custom field in AJAX response. Custom field is provided by ACF plugin. When button is clicked then AJAX request is send and posts are searched through. If custom_field of a post equals $value then I get id of that post if $value doesn't exist in any of custom posts then post is created and I get id of newly created post. Every post of custom_post contains custom_field . When I refresh page it works and post is not created for second time after second click. Otherwise the another click doesn't find a post so it is created again. I don't know why refresh helps. $value custom_field $value id $value id custom_post custom_field In content-page.php I call a function from my functions.php that generates links with: content-page.php functions.php jQuery(document).ready(function($) { jQuery( "body" ).click(function( event ) { v...

Retrieve data from Mysql database, display on a form, and allow user to update using PHP

Retrieve data from Mysql database, display on a form, and allow user to update using PHP I am VERY NEW to PHP. I have a page where I want a user to be able to enter a citation and that information is then passed to a php script that queries against the database, returns the information in a form, and then allows the user to update any of the fields returned in that form. I have three problems: 1) When data returns, is only returns the first word in the field. Many of the fields contains multiple words. 2) When the users changes data in the field, the database isn't updated. 3) I don't seem to know how to get the form fields to display like I do for data entry. Here is the code that queries and returns the data for the user to review and update if necessary: <?php mysql_connect("***************", "*********", "****") or die(mysql_error()); mysql_select_db("***********") or die(mysql_error()); $searchterm= $_POST['searchterm...

Sorting MySQL data into limit sized pages, and onscreen option to change pages? How is it done? [on hold]

Image
Sorting MySQL data into limit sized pages, and onscreen option to change pages? How is it done? [on hold] I am new to HTML and CSS, however I have some basic knowledge of programming games in C# and Java (using frameworks like LibGDX, Unity etc). I've built a database in MySQL and the corresponding php code that displays a html article for each entry in the table. Everything is working great but the whole database loads onto one big webpage. I have been reading around a lot but cannot seem to find where to start on building it into pages. The only idea I can imagine right now is that I will need a field somewhere on my site to hold the current page number the user selected, and then in my SQL SELECT statement use that figure to somehow pull only say 20 pages starting from 'currentPage * 20' for example. I've found small parts of the info I need like I see there may be a LIMIT clause I can use. But how can the SELECT * FROM table ORDER BY id DESC LIMIT (currentPage*20); ...

convert json string to variables

convert json string to variables maybe my question is a bit unreasonable, but what's wrong i ask. I have a simple script like below <?php $r['code'] = 200; $r['result'] = "hello world"; $r['down'][0] = "first"; $r['down'][1] = "second"; echo json_encode($r, JSON_PRETTY_PRINT); ?> and the results from the script are { "code": 200, "result": "hello world", "down": [ "first", "second" ] } as seen above, that variables can be converted to json by using json_encode, and to my question, can we change json back into variables? for example Before { "code": 200, "result": "hello world", "down": [ "first", "second" ] } After <?php $r['code'] = 200; $r['result'] = "hello world"; $r['down'][0] = "first"; $r['down'][1] = ...

Form not submitting values

Image
Form not submitting values Ok so, I am a self taught coder, so no need to be overly rude if I am missing something lol. This is the first ever form I have created, and I have the css, html, and php set up. My issue is whenever I hit the submit button, all it does is reload the page and sends no data. I have honestly checked out the other forums here for answers but the things I have found in other forums, I have tried, but it hasn't worked. I will leave my code below, if anyone could tell me why its not submitting the values that would be a huge help. <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content="Contact Us"> <meta name="keywords" content="Contact Us"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> <meta http-equiv="X-UA-Compatible" content=...

SQL Query not updating the database

SQL Query not updating the database I was getting an error from my processing form down below. I'm not sure why it isn't updating to the database when I hit submit. It says it has been successful but yet the databse has not been updated?! I think it maybe because of the "mysqli_stmt_execute" but I'm not sure. Any thoughts :/ Thanks. <?php if(isset($_POST['submit'])){ include_once 'connection.php'; $first = mysqli_real_escape_string($conn, $_POST['first']); $last = mysqli_real_escape_string($conn, $_POST['last']); $uid = mysqli_real_escape_string($conn, $_POST['uid']); $pwd = mysqli_real_escape_string($conn, $_POST['pwd']); $hashedPwd = md5($pwd); //Error Handling //Checking for empty fields if(empty($first) || empty($last) || empty($uid) || empty($pwd)){ header("Location: ../signup.php?signup=empty"); exit(); }else{ //Checking if the input...

mysqli_real_escape_string doesn't seem to be working

mysqli_real_escape_string doesn't seem to be working I am a novice in PHP. I am trying to insert a variable's value into a MariaDB table and was trying to use mysqli_real_escape_string to escape '$value'. I got the idea from here. It inserted an empty string to the table(I did add a connection link to the database). So, I copied and pasted the following code from PHP Manual, it still didn't work. The output I got was an error code alone: Error: 42000. What am I missing? I am using a Virtualbox, OS: CentOS7 <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %sn", mysqli_connect_error()); exit(); } mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City"); $city = "'s Hertogenbosch"; /* this query will fail, cause we didn't escape $city */ if (!mysqli_query($link, "I...

Credit Cards with PayPal REST API

Credit Cards with PayPal REST API My client uses the PayPal NVP API for processing both PayPal and credit cards payments. That appears to be deprecated or PayPal is encouraging upgrading to REST. I convinced my client to do the upgrade and while implementing it I noticed the following: Important: The use of the PayPal REST /payments APIs to accept credit card payments is restricted. Instead, you can accept credit card payments with Braintree Direct. That puts a serious wrench in my work. A little more searching around and I find this option for accepting credit card payments with the REST API: Guest payments with a credit card that is stored in the PayPal vault This would imply to me that the Vault must be used on conjunction with guest payments. Can anyone confirm if that is the case? It looks like to enable guest checkout payments "PayPal Account Optional" must be turned on which I have confirmed is on in my sandbox account. The presumption I am now going on is credi...

Modify Php function to crop image border by X pixels

Modify Php function to crop image border by X pixels I have this PHP function that I use on Behat automation which takes a screenshot of an element of the page, cropping the image: protected function takeElementScreenshot($filename, $folder, $selector) { $element = $this->findElement($selector); $driver = $this->getSession()->getDriver(); $this->iScrollToTheElement('top', $selector); $previousWindowHeight = $driver->evaluateScript("window.outerHeight"); $previousViewportHeight = $driver->evaluateScript("window.innerHeight"); $domElement = "document.evaluate("$selector", document, null," . "XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue"; $elementRect = $driver->evaluateScript("$domElement.getBoundingClientRect()"); if ($previousViewportHeight < $elementRect["height"]) { $windowWidth = $driver->evaluateScript("windo...

How can I remove spaces in view?

How can I remove spaces in view? I use laravel 5.3 My case is like this : My code in view : " @if(isset($country)) {{ $country }} @endif @if(isset($city)) @if(isset($country)) - @endif {{ $city }} @endif " The result like this : " England - London " I want the result like this : "England - London" How can I do it? What's the difference between result and expectation ? Just spaces ? – Sagar Gautam Jun 7 '17 at 8:36 @Sagar, Yes, it just spaces – Success Man Jun 7 '17 at 8:36 Answer is here stackoverflow.com/questions/26146045/… – kRicha ...

Split array using list and array_chunk for dynamic requirements

Split array using list and array_chunk for dynamic requirements I am using list and array_chunk to split arrays. In my first example I split the array into four pieces using list. I would like to change the number from 4 to say 8 and have it dynamically do this. Instead of manually creating it in the code. Is this possible ? I assume I could use variable naming as listed in my non working second example below. How it works now : list($inv0, $inv1, $inv2, $inv3) = array_chunk($val['inventory'], ceil(count($val['inventory']) / 4)); What I would like is to set something $i = 8 and have it automatically split into 8 chunks dynamically . Something like : $i = 8 list(${inv.0}, ${inv.1}, ${inv.2}, ${inv.3},${inv.4},${inv.5},${inv.6},${inv.7}) = array_chunk($val['inventory'], ceil(count($val['inventory']) / $i)); So based on my needs I can split the array into X pieces instead of hard coding it to 4 or 8 etc... Any time you find your...

Change something in db when session unsets

Change something in db when session unsets I build a basic logout script which unsets all sessions, and changes the 1 under the column "loggedin" to 0 in the database. I need to do that so I can check of a user is loggedin, and post this on the users page. When you close of the browser, all sessions etc. are deleted, but the sql query to update the loggedin column will not be executed. How can I fix this? if there are any questions, please let me know! Can you help me? Code: Logout script: require "includes/db.php"; ini_set('session.cookie_domain', '.ictsupport.ga' ); session_start(); $username = $_SESSION['auth']; //SQL to set loggedin to 1 $sqlStat = "UPDATE account_users SET loggedin = 0 WHERE username='$username';"; /*It changes the 1 in the database to a 0 to let the users page know that the user is offline*/ mysqli_query($con, $sqlStat); session_unset(); session_destroy(); Add a column ...

Values on browser are different as compared to the ones stored in database php

Values on browser are different as compared to the ones stored in database php i generated a random number to use as a tracker but the random number generated is not the same as the one stored in the database. Php Code: <div class="form-group"> <label for="name-card" class="text-success"><strong><?php echo $NUMEROENVIO; ?></strong></label> <?php $qryEmpresa = mysql_query("SELECT * FROM company"); while($row = mysql_fetch_array($qryEmpresa)) { $pre = $row["prefijo"]; $cons = $row["cons_no"]; } mysql_free_result($qryEmpresa); $pa=mysql_query("SELECT MAX(cons_no)as maximo FROM c_tracking"); if($row=mysql_fetch_array($pa)){ if($row['maximo']==NULL){ $cons_no=''.$cons.''; }else{ ...

mysql query showing error: #1241 - Operand should contain 1 column(s)

mysql query showing error: #1241 - Operand should contain 1 column(s) Mysql query, SELECT qcat.name, COUNT( CASE WHEN qas.state = "todo" THEN 1 END ) AS gtotal, COUNT( CASE WHEN qas.state = "gradedright" THEN 1 END ) AS rightanswer, COUNT( CASE WHEN qas.state = "gradedwrong" THEN 1 END ) AS wronganswer, SUM(qas.fraction) AS grade, quiza.id FROM mdl_quiz_attempts quiza JOIN mdl_question_attempts qa ON qa.questionusageid = quiza.uniqueid JOIN mdl_question_attempt_steps qas ON qas.questionattemptid = qa.id JOIN mdl_question qstn ON ( qa.`questionid` = qstn.id ) JOIN mdl_question_categories qcat ON ( qstn.`category` = qcat.id ) WHERE quiza.id=1173 and FIND_IN_SET(qstn.id, (1,2,3,4,5,6)) GROUP BY quiza.id,qcat.name showing error: #1241 - Operand should contain 1 column(s) Try replace FIND_IN_SET(qstn.id, (1,2,3,4,5,6)) with FIND_IN_SET(qstn.id, 1,2,3,4,5,6) (remove parenthesis) – Felippe Duarte J...