PHP - Need To Send Json From Php Processing To Public Page
I am modifying someones existing coldfusion web app. I am adding php processing pages to do various tasks. Up to this point I have just been calling the php pages, and interacting with the web app by passing variables via the url.
Current usage: Code: [Select] public.cfm calls processing.php?id=69 Then processing will do what it has too, then ultimately: Code: [Select] header("Location: $publichome?id=$id&importantstuff=$stuff"); exit(); And the webapp will pick up where it has too. But now one of my scripts has to send a JSON object back instead of simple variables. I don't know how to get this done. I tried doing a post with cURL but that wasn't working because I need the public facing coldfusion page to take over and curl returns to the php script (I know I can echo the body of the curl result but this keeps me on the php script domain which I dont want). Is there a way to do the above header location and send an object because thats what I need - the php script to stop and the coldfusion page to be served up with the object to work with. Do I have to create some sort of JSON service in php, that the coldfusion page will call an retrieve the result? If so how? Similar TutorialsI am retrieving Google Books info in JSON format and displaying it inside a div. I would like to send the contents of this div (name, title, description) to my database using Ajax.
Currently only the ISBN field sends because I have it declared as a variable. However my question is, how do I send the other fields (name, title, author). How do I declare these also, I'm not sure what format they need to be in etc.
My JS
$(document).ready(function() { $('#submit').click(function(ev) { ev.preventDefault(); var isbn = $('#isbn_search').val(); //get isbn direct from input var url='https://www.googleapis.com/books/v1/volumes?q='+isbn; $.getJSON(url,function(data){ $.each(data.items, function(entryIndex, entry){ var html = '<div class="results well">'; html += '<h3>' + entry.volumeInfo.title + '</h3>'; html += '<div class="author">' + entry.volumeInfo.authors + '</div>'; html += '<div class="description">' + entry.volumeInfo.description + '</div>'; }); }); }); });My Ajax; $.ajax({ type: 'POST', url: 'addIsbnScript.php', data: { 'isbn' : isbn, 'title' : title 'subtitle' : subtitle, 'authors' : authors, 'description' : description }, success: function () { $.growl({ message: " Record added" }); } });Note, if i manually set the vars like below they all do successfully send to my database, so I know my query is working ok var title = "some text", var author = "some text", Var description = "some text"Thanks in advance for any help, newbie here (incase it wasn't obvious!). J This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=322125.0 Hi, I am making a dating site where I have made the user profile edit page visible to the user when they log in, and I think I can get away with not showing the user their "public" profile view. But I definitely need to show other users on the site the "public" non editing profile page view. But I don't know how to do this. I have yet to create the search, search results, thumbnails with optional descriptions of the possible dating results. But I first want to just get 2 versions of the user profile page view. One that the user sees that I have already done. (The editable one). And the other I need to make which is the page the other users will see, (The public profile) Please if anyone has any idea how to do this I would greatly appreciate it, especially if you have any pseudocode ideas. thank you. I seem to be having a problem with the below script, on the 1st run it doesnt print the $variables, but on refresh these a being written to file once? Code: [Select] if(isset($_GET['sprop']) && ($_GET['sprop'] == "update")) { //my connection stuff // // $playername = "userid"; $nether = $_POST["nether"]; $lname = $_POST["lname"]; $query = $_POST["query"]; $flight = $_POST["flight"]; $portdd = $_POST["port"]; $rcon = $_POST["rcon"]; $seed = $_POST["seed"]; $sip = $_POST["sip"]; $wlist = $_POST["wlist"]; $san = $_POST["san"]; $omode = $_POST["omode"]; $pvp = $_POST["pvp"]; $dif = $_POST["dif"]; $sname = $_POST["sname"]; $gmode = $_POST["mode"]; $pmax = $_POST["max"]; $sm = $_POST["sm"]; $view = $_POST["view"]; $motd = $_POST["motd"]; sleep(3); $sftp = new Net_SFTP($ftp_s); if (!$sftp->login($ftp_u, $ftp_p)) { exit('Login Failed'); } echo $sftp->pwd() . "\r\n"; $sftp->put ("/root/mc/server.properties", "allow-nether=$nether level-name=$lname enable-query=$query allow-flight=$flight server-port=$portdd enable-rcon=$rcon level-seed=$seed server-ip=$sip white-list=$wlist spawn-animals=$san online-mode=$omode pvp=$pvp difficulty=$dif server-name=$sname gamemode=$gmode max-players=$pmax spawn-monsters=$sm view-distance=$view motd=$motd"); } As you can see, I have try adding a sleep to give it time to catch up but something tells me the variables are not being set 1st time for some reason, can anyone shine any light on this? Okay after correcting the issues with the jQuery side of things I'm having a small error with the php processing side. I'm getting a response back in firebug that there is an undefined index "name" and undefined index "value". Now I'm not sure on a fix but I know I'll have to do some sort of foreach I think because on the jquery dataString is a each so there's going to be more than name and value coming in at one time. Code: [Select] <?php error_reporting(E_ALL); // Include the database page include ('../inc/dbconfig.php'); $styleID = $_GET['id']; $query = "SELECT fields.ID, fields.fullName, fields.enabled FROM fields INNER JOIN styles ON styles.ID = fields.styleID WHERE styles.ID = '" . $styleID . "'"; $result = mysqli_query ( $dbc, $query ); // Run The Query ?> <script> $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); $("input.submit").click(function() { $('div.message-error').hide(); var dataString = '&submitBioFields=True'; $('#bioConfigForm .field').each(function() { dataString += '&'+$(this).find('input:first').attr('name')+'='; dataString += ($(this).find('input[value|=0]').is(':checked')) ? '0' : '1'; }); alert(dataString); $.ajax({ type: "POST", url: "processes/bioconfig.php", data: dataString, success: function() { $('div.message-error').hide(); $("div.message-success").html("<h6>Operation successful</h6><p>Bio fields saved successfully.</p>"); $("div.message-success").show().delay(10000).hide("slow", function() { $('#content').load('mods/bioconfiguration.php'); }); } }); return false; }); }); </script> <!-- Title --> <div id="title" class="b2"> <h2>Bio Configuration</h2> <!-- TitleActions --> <div id="titleActions"> <!-- ListSearch --> <div class="listSearch actionBlock"> <div class="search"> <label for="search">Recherche</label> <input type="text" name="search" id="search" class="text" /> </div> <div class="submit"> <button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button> </div> </div> <!-- /ListSearch --> </div> <!-- /TitleActions --> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <!-- Form --> <form action="#" id="bioConfigForm" > <fieldset> <legend>Bio Config</legend> <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { ?> <div class="field"> <label for="<?php '' . $row['ID'] . '' ?>"><?php echo '' . $row['fullName'] . ''?></label> <input type="radio" value="0" name="<?php echo $row['ID']; ?>" class="status" <?php if($row['enabled'] == 0) echo ' checked="checked"'; ?> />Enabled <input type="radio" value="1" name="<?php echo $row['ID']; ?>" class="status" <?php if($row['enabled'] == 1) echo ' checked="checked"'; ?> />Disabled </div> <?php } ?> <input type="submit" class="submit" name="submitBioFields" id="SubmitBioFields" title="Submit Bio Fields" value="Submit Bio Fields"/> </fieldset> </form> <!-- /Form --> <!-- Messages --> <div class="message message-error"> <h6>Required field missing</h6> <p>Please fill in all required fields. </p> </div> <div class="message message-success"> <h6>Operation succesful</h6> <p>Bio configuraton was eddited to the database.</p> </div> <!-- /Messages --> <?php error_reporting(E_ALL); // Include the database page require ('../inc/dbconfig.php'); if (isset($_POST['submitBioFields'])) { $fieldID = (int)$_POST['name']; $value = (int)$_POST['value']; $query = "UPDATE `fields` SET `enabled` = '".$value."' WHERE `ID` = '".$fieldID."'"; mysqli_query($dbc,$query); $result = "good"; } //Output the result echo $result; ?> My validation Code: [Select] <?php if(!isset($_POST['submit'])) { if(!isset($_GET["id"])) { me_redirect_to("staff.php"); } } ?> is redirecting me even if my $_POST['submit'] is set here's the full code Code: [Select] <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php require("includes/header.php"); ?> <?php require("includes/navbar.php"); ?> <?php require("staff_sidebar.php"); ?> <?php if(!isset($_POST['submit'])) { if(!isset($_GET["id"])) { me_redirect_to("staff.php"); } } ?> <?php if(!isset($_POST['submit'])) { if(!is_numeric($_GET["id"])) { me_redirect_to("staff.php"); } } ?> <?php if(isset($_GET['id'])); { $i = 0; $edit_proj_id = $_GET['id']; $edit_query = "Select proj_name, content from rec_projects where proj_id = {$edit_proj_id}"; $edit_result = mysql_query($edit_query, $connection); $num = mysql_num_rows($edit_result); if($num != 1) { me_redirect_to("staff.php"); } $edit_proj_name = mysql_result($edit_result,$i,"proj_name"); $edit_content = mysql_result($edit_result,$i,"content"); } ?> <div id="content"> <h1>Edit Subject</h1><br> <?php if(isset($_POST['submit'])) { $proj_name = me_mysql_prep(trim($_POST['proj_name'])); $proj_content = me_mysql_prep($_POST['proj_content']); if(empty($_POST['proj_name'])) { $empty_name = array('Project Name Cannot Be Empty'); } if(empty($_POST['proj_content'])) { $empty_content = array('Content Cannot Be Empty'); } if(isset($empty_name) && isset($empty_content)) { $error_merge = array_merge($empty_name, $empty_content); } else if(isset($empty_name)) { $error_merge = array_merge($empty_name); } else if(isset($empty_content)) { $error_merge = array_merge($empty_content); } else { $error_merge = array(); } if(!empty($error_merge)) { foreach($error_merge as $error) { echo "<span class=\"error_validation\">*". $error . "<br></span>"; } } else { $query = "UPDATE rec_projects SET proj_name='{$proj_name}', content='{$proj_content}' where proj_id = {$edit_proj_id}"; if($result = mysql_query($query,$connection)) { me_redirect_to("edited_project.php?edited=1"); } else { echo "Can\'t edit the project: ". mysql_error() . ""; } } echo "<br><br>"; } ?> <table> <tr><td> </td></tr> </table> <table> <form action="edit_project.php" method="post" name="add_subject"> <tr> <td>Project Name:</td> <td><input type="text" size="50" name="proj_name" value="<?php echo $edit_proj_name; ?>"></td> </tr> <tr> <td>Content:</td> <td><textarea cols="70" rows="20" name="proj_content"><?php echo $edit_content; ?></textarea></td> </tr> <tr> <td></td> <td><input type="submit" value="Edit Project" name="submit" id="submit" size="30"></td> </tr> </form> </table> </div> <?php require("includes/footer.php"); ?> It's suppose to be executing the mysql edit query but it's bypassing my validation. I wonder what the problem is.. I have 2 scripts that take a while to process... The first takes a few minutes, the second takes over an hour... The first script completed successfully, but the second script seems like it just stops most of the way through the script... I have this set on both files: set_time_limit(0); ini_set('memory_limit', -1); I NEED to disable ALL time limits and all of that, does ANYONE have any clue as to why my second script is failing? It is NOT the programming, I know that for sure... But the script just stops executing, and I think it is because it times out... But after setting those 2 options, I don't see why it times out.. Also for reference, I am NOT using any database... I am simply downloading files from an FTP server to my server... Any help would be appreciated, I have been searching for the last few days on an answer. Rob Hi I have put together a options page for the script that I have been working on. I have 1 options page where there options are divided into 4 jQuery tabs with there own save button. The options in each tab are posted using Ajax to their own separate file like process.php, process1.php etc. My question is there a way to place all the processing code in one file and if so would this affect the load on the server? Would each form be better off having their own page for processing? For example: Code: [Select] <form id="options_1" action="process1.php" method="post" > <!-- this is form 1 that is processed with process1.php --> </form> <form id="options_2" action="process2.php" method="post" > <!-- this is form 2 Can this form be processed using process1.php instead of process2.php --> </form> <form id="options_3" action="process3.php" method="post" > <!-- this is form 3 Can this form be processed using process1.php instead of process3.php --> </form> How can I call a public function inside of another public function? The get_primary_edge() says it's undefined, but it's just another public function in the class so shouldn't this work? Code: [Select] public function get_dynamic_edge($uid) { $uid = (int)$uid; $sql = "( SELECT `users`.`id` FROM partners INNER JOIN `users` ON `partners`.`user_id` = `users`.`id` WHERE partners.friend_id = '${uid}' AND `approved` = 1 ) UNION ALL ( SELECT `users`.`id` FROM `partners` INNER JOIN `users` ON `partners`.`friend_id` = `users`.`id` WHERE `partners`.`user_id` = '${uid}' AND `approved` = 1 )"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; while (($row = mysql_fetch_assoc($result)) !== false) { $dynamic[$i] = array( 'uid' => $row['id'], 'score' => get_primary_edge($row['id']), ); $i++; } print_array($dynamic); } I want to add a note field and a checkbox to my list/grid page and save this information to a json file using uomptrucknumber as the key. The note information will be information for the whole truck not by order. The check box will let them know that the truck is ready to have paper work printed. I have not add the note field or checkbox because I did not want to start off wrong. echo "<table>"; echo "<tr style='background:#82fbfd'>"; echo "<th>ShipDate</th>"; echo "<th>ShipMeth</th>"; echo "<th>Name</th>"; echo "<th>LoadID</th>"; echo "<th>Drop</th>"; echo "<th>OrderID</th>"; echo "<th>Status</th>"; echo "<th>FGI</th>"; echo "<th>FGM</th>"; echo "<th>TotalBox</th>"; echo "<th>Cubes</th>"; echo "<th>Total</th>"; echo "<th>Notes \n</th>"; //echo "<table>"; echo "<tr style='background:#82fbfd'>"; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } function ShowDetail($row){ if($row['ompclosed']==-1){ $theColor="#AAF0D2"; }else{ $theColor="#FFFFFF"; } if($row['ompclosed']==0 && $row['date'] < date("m/d/Y")) { $theColor="#FF0000"; } echo "<tr style='background-color :$theColor'><td>" .$row['date'] ."</td>"; echo "<td>" .$row['ompshippingmethodid'] ."</td>"; echo "<td style='text-align:left'>" .$row['cmoname'] ."</td>"; echo "<td>" .$row['uomptrucknumber'] ."</td>"; echo "<td>" .$row['uompdropsequence'] ."</td>"; echo "<td>" .$row['ompsalesorderid'] ."</td>"; echo "<td>" .$row['ompclosed'] ."</td>"; echo "<td>" .round($row['FGIqty'],0) ."</td>"; echo "<td>" .round($row['FGMqty'],0) ."</td>"; echo "<td>" .round($row['uomptotalboxcount'],0) ."</td>"; echo "<td>" . number_format($row['uompvolumetotal'],2) ."</td>"; echo "<td>" . number_format($row['ompordertotalbase'],2) ."</td>"; echo "<td style='text-align:left'>" .$row['ompordercommentstext'] ."</td></tr>" ; } //**************************************************************** while ($row = odbc_fetch_array($result)) { if($row['ompclosed']==-1){ $theColor="#AAF0D2"; }else{ $theColor="#FFFFFF"; } if($row['ompclosed']==0 && $row['date'] < $today) { $theColor="#FF0000"; } if($row['uomptrucknumber'] != $loadid) { if ($loadid !== 0) { echo "<tr style='background:#eee'> <td colspan='7'>TOTAL</td> <td>$TotalFGI</td> <td>$TotalFGM</td> <td> </td> <td> </td> <td>$loadTotal</td> </tr>"; } $TotalFGI=0; $TotalFGM=0; $loadTotal=0; } ShowDetail($row); $loadid = $row['uomptrucknumber']; $TotalFGI+=round($row['FGIqty'],0); $TotalFGM+=round($row['FGMqty'],0); $loadTotal +=$row['ompordertotalbase']; } echo "<tr style='background:#eee'> <td colspan='7'>TOTAL</td> <td>$TotalFGI</td> <td>$TotalFGM</td> <td> </td> <td> </td> <td>$loadTotal</td> </tr> </table>"; odbc_close($connect); ?>
I have a small family only website and I use this code on my login page to see if members are having trouble re logging in.
// routine writes to file when this page is accessed
<?php $logfile = '/home/xxxxxxx/public_html/temp/trouble.txt'; $date = date('j M Y H:i:s'); if (isset($_COOKIE["family_user"])) { $user = $_COOKIE["family_user"]; } if ($file = @fopen($logfile, 'a')) { fwrite($file, "\r\n$date $user "); fclose($file); } ?> How can I use the information gathered (fwrite($file, "\r\n$date $user ") that writes to my trouble.txt file be sent to me via email. And ideally only once per session. I found this code will send me an email every time the page is accessed but can not figure out how to get fwrite($file, "\r\n$date $user " into either the subject (preferred) or into the body. <?php mail('yourEmailAddress@yourDomain.com','Subject of the e-mail','This is the body of the e-mail!'); ?> Anyone able to help with the code Thank you for your time Hi friends. I have a problem with https about $_SESSION in php last time my website is working correctly with http but after change to https I can send value of session to another page
login.php session_start(); $_SESSION['user_ID'] = 8;
Action.php session_start(); echo "User ID = " . $_SESSION['user_ID'] ; //// It's not show any thing
Thank you very much for your help I have a problem, i have page to send via mail function, cant snd html page, when recive mail, there is no layout, but text is there, also there are no images, and i put full address to image file. Using content type html/text, and still nothing :-( Can someone help me? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=318598.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=320495.0 Hi, I am sending data from a form to a URL using $_GET but I would also like the user to be redirected to a thankyou page which is a different URL. Does anyone know if this is possible? Thanks, database.php I have phpmailer on a website and after clicking send, it goes to the forms action page and don't seem to redirect to the enquiry confirmation page, the forms action page is a blank white page which am guessing is correct as it's PHP coding but thought it should redirect. I don't get any errors showing what the issue is. I have the phpmailer uploaded onto the FTP server and has the class.phpmailer.php file inside the phpmailer folder. The client has their email going through office365. Below is the code I have + <?php ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); //index.php $error = ''; $name = ''; $email = ''; $subject = ''; $message = ''; function clean_text($string) { $string = trim($string); $string = stripslashes($string); $string = htmlspecialchars($string); return $string; } if(isset($_POST["submit"])) { if(empty($_POST["name"])) { $error .= '<p><label class="text-danger">Please Enter your Name</label></p>'; } else { $name = clean_text($_POST["name"]); if(!preg_match("/^[a-zA-Z ]*$/",$name)) { $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>'; } } if(empty($_POST["email"])) { $error .= '<p><label class="text-danger">Please Enter your Email</label></p>'; } else { $email = clean_text($_POST["email"]); if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error .= '<p><label class="text-danger">Invalid email format</label></p>'; } } if(empty($_POST["subject"])) { $error .= '<p><label class="text-danger">Subject is required</label></p>'; } else { $subject = clean_text($_POST["subject"]); } if(empty($_POST["message"])) { $error .= '<p><label class="text-danger">Message is required</label></p>'; } else { $message = clean_text($_POST["message"]); } if($error == '') { require 'phpmailer/class.phpmailer.php'; $mail = new PHPMailer; $mail->SMTPDebug = 2; $mail->IsSMTP(); //Sets Mailer to send message using SMTP $mail->Host = 'smtp.office365.com'; //Sets the SMTP hosts $mail->Port = '587'; //Sets the default SMTP server port $mail->SMTPSecure = 'tls'; //Sets connection prefix. Options are "", "ssl" or "tls" $mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables $mail->Username = 'email@domain.co.uk'; //Sets SMTP username $mail->Password = 'password'; //Sets SMTP password $mail->From = $_POST["email"]; //Sets the From email address for the message $mail->FromName = $_POST["name"]; //Sets the From name of the message $mail->AddAddress('email@domain.co.uk', 'Name');//Adds a "To" address $mail->AddCC($_POST["email"], $_POST["name"]); //Adds a "Cc" address $mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters $mail->IsHTML(true); //Sets message type to HTML $mail->Subject = "New Website Enquiry"; //Sets the Subject of the message $mail->Body = "Name: " . $_POST["name"] . "<br><br>" . "Email: " . $_POST["email"] . "<br><br>" . "Subject: " . $_POST["subject"] . "<br><br>" . "Message: " . "<br>" . $_POST["message"]; //An HTML or plain text message body if (!$mail->Send()) //Send an Email. Return true on success or false on error { header('Location: https://www.domain.co.uk/enquiry-confirmation.php'); } else { $error = '<label class="text-danger">There is an Error</label>'; } $name = ''; $email = ''; $subject = ''; $message = ''; } } ?>
Hello every one i need your help please about this i would like to add this tabs to my facebook fan page i got App allowing me to put php coding or html but i need when some one add his info and click on submit i receive it at my email so can any 1 here help me or tell me what shall i do ? i newbie and hope to get your help guys please Hi I have tried and tried and tried again to get this to work
in simple terms I have very little knowledge with PHP and even less with mysql
I have a paid subscription and domain in order to learn more and I feel I have made ok progress so far
then I realised how unsafe my current work is;
here is my experience this far
I created a site for a group of voluntary online game hosts where they can posts points from their tournaments in a forum
and some info pages to go with this,
however what I did was create a base template and style sheet and then an admin dashboard linked to individual forms to allow the group admin to edit the info pages they go to my form and enter the desired info and submit this then sends through and action file which posts the text and <BR> to a .txt file,
then the connecting page reads the .txt file using the PHP code of " <? php include ( 'index.txt'); ?>
yes you are seeing this correctly I have allowed a direct edit of text in a .txt file rather silly of me but I didn't realise how unsafe this was until now I guess its a good job I trust that the admin has no knowledge or skills in coding
ok since all this I have created a DB in MySQL on my server,
My server uses PHPMyAdmin I have create a DB named " mnvbcou1_content1 " and a table named " home " with rows " ID " and " home "
what I am trying to do:
I want my page to display the content of the table row home and a form once submitted to send to the table row home
or if needed I can re make this DB if the names are not suitable
I have tried to create the needed coding to make this work but for some reason this just will not work I have already added 2 rows to my table to try and make the page to display the content but it just is not working I got an error every time
so I hope that someone out there is rather patient and is willing to help me learn how to do this correctly and safely,
also this is a closed group website the address to this site is only known by a handful of none programmers I am mainly trying to make this work for my own personal knowledge and server safety please help me
|