|
Although I'm not a noob when it comes to programming, I have zero experience of web services so I'm seeking advice!
For one of our departments at work I have developed a simple CRUD application using Apache, MySQL and PHP on a local network server. This works fine
Due to expansion of the department, the database is to be migrated to the main DB server to which I will not be able to make direct calls from my PHP code due to security. They are happy however to create a webservice that I can use that will in turn access the database. I have total say in how the data will be returned to me for interpretation by my PHP pages and how I send data to the web service.
Which is the recommended way (I hear alot of 'talk' about JSON nowadays) and do you know of any good tutorials that you would recommend?
(I'm posting here as I'm not sure where is best, and from my side of things PHP will be doing all the communication with the service)
|
|
|
|
|
Hi,
It is better to use XML way, which is more understandable and easy.But JSON is much efficient and fast.
|
|
|
|
|
|
I did understand that you would develop the serverside application with PHP
But I didn't understand what would be the client application, Would it be web browser? or are you going to develop Application to extract the reply from HTTP server.
I know I am coward since the day I know that fortune favors the brave
|
|
|
|
|
The Client will be a web browser using PHP/Apache on a local server. The local PHP scripts will communicate with the remote web service.
Web Browser <-> Local Apache/PHP <-> Web Service <-> Remote Apache/MySQL/PHP
|
|
|
|
|
Both will be perfect,
or you just can create a user with permitting only one host ip with the limitation of tables connection. It wont do any herm
I know I am coward since the day I know that fortune favors the brave
|
|
|
|
|
Hi,
In ASP.NET, the best way to manage http errors e.g: Error 400.x, 500.x is to specify this in the web.config or globax.asax file.
How do I accomplish the same in php, because I was to get a nicely formatted error page displayed to my users instead of the anoying apache error page.
Please help!
|
|
|
|
|
|
Hi
I have two posts: /post1, /post2
how I can create a link that every 20 seconds redirect to one of them. I mean if this link go to /post1, after 20 seconds if that or another person click on it go to /post2, also this time sets with server time
please help me
thanks
|
|
|
|
|
How can i add simple texteditor to my application.Just like post a question in this site.
|
|
|
|
|
|
If you run this in a browser you can see the form. I want to clarify how could that be happen the form is inside the if statement. Is there any way you can hide html code in PHP. The html code will be executed if the "if" statement is true.
<?php
require "../utility/connection.php";
$submit = true;
if(isset($_POST['submit'])){
$query = mysqli_query($connect, 'SELECT * FROM email_accounts');
}else{
}
if($submit = true){?>
<form method="post" action=" .<?php echo $_SERVER['PHP_SELF']; ?> ">
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" value="<?php echo $subject; ?>" />
<br />
<br />
<label for="message_body">Say something:</label>
<textarea id="message_body" name="message_body"><?php echo $msg_body;?></textarea>
<br />
<input type="submit" id="submit" name="submit" value="Send Email" />
</form>;
<?php
}
?>
|
|
|
|
|
First, your 'if' statement is wrong - you have used a single '=', which means it assigns the value true to $submit and then tests it, finding it to be true and executing the block that follows. Here are some options that will work:
if($submit == true) {
if($submit === true) {
if($submit) {
The second reason your form will display is that you have set $submit to true on the second line of the script, and you don't appear to be setting it anything else elsewhere in the code.
|
|
|
|
|
Wow your great.
I change the initial value of submit to false. I also change the "if" statement to == but the form still showing.
Thanks for your help.
|
|
|
|
|
Just to clarify aswell:
= is an assignment operator.
== is the comparison operator as mentioned above.
=== is another comparison operator I call identity, which checks for equality AND type.
As PHP is not strongly typed, a variable can change types dynamically at runtime.
Example:
$a = 2;
$b = "2";
A comparison would be like this:
if($a == $b)
{
}
..would be TRUE, as they have the same value, but one is an integer and one is a string.
if($a === $b)
{
}
.. would be FALSE, because they have matching values but different types!
For me, understanding this in the beginning helped me to write reliable condition tests for websites and applications.
|
|
|
|
|
flashery wrote: If you run this in a browser you can see the form.
PHP doesn't run in a browser, it runs in the web server. If you open a PHP file directly in a browser (by File->Open...) instead of loading it from a server the PHP code won't get executed.
|
|
|
|
|
I run this stuff using my local web server xampp in localhost.
|
|
|
|
|
I think you might have a syntax error.
if you have to check something, then the if statement should be:
if($submit == true)
if($submit = true) -> is setting submit to true not checking.
Hope this helps.
|
|
|
|
|
This is an odd error and I hope someone has seen it before.
I have a script that is called from other scripts. It also runs from the commandline and is used to ftp files to various destinations. One is to a google upload site and it looks to work 2 out of 3 runs with one time reporting this error
Warning: ftp_put(): '': command not understood.
Using a google search, I have found reference to "ftp_put(): 'STOR':" errors but nothing on the empty string I have.
What else gets me is this does not fail always, just once in a while. I can use the same parameters too...sometimes it fails but usually it is good.
ideas?
Chris J
www.redash.org
|
|
|
|
|
Reading the comments in the PHP Manual ... http://php.net/manual/en/function.ftp-put.php[^] you are not the only one to suffer. In the comments various possible solutions are suggested.
Let us know which, if any, provides a better answer.
modified 1-Aug-19 21:02pm.
|
|
|
|
|
I will have to get back to you in a few, this got pushed back by two other projects....grrrr!
Thanks for the response tho.
Chris J
www.redash.org
|
|
|
|
|
Hi all;
I am create a page with data form with phot upload capability and I don't seem to be getting it right. Below is what I have done so far but not working.
index.php
<pre><?php
include_once 'includes/helpers.inc.php';
require_once 'classes/CommonData.php';
?>
<?php
if (isset ($_GET['upload'])){
if (isset($_GET['destination']) && isset ($_GET['allowedFiles'])) {
$allowedFiles = explode(',', $_GET['allowedFiles']);
if (sizeof($allowedFiles) == 0)
$allowedFiles = $_GET['allowedFiles'];
if (in_array($_FILES["file"]["type"], $allowedFiles)) {
if ($_FILES['file']['error'] > 0) {
$src = '';
$imgMsg = "Return code: " . $_FILES['file']['error'];
} else {
if ($_FILES['file']['size'] > $_GET['maximumFileSize']) {
$src = '';
$imgMsg = 'File size to large. Must be less or equals 10KB.';
} else {
if (file_exists($_GET['destination'] . $_FILES['file']['name'])) {
$src = '';
$imgMsg = $_FILES['file']['name'] . ' already exists.';
} else {
move_uploaded_file($_FILES['file']['tmp_name'] ,
$_GET['destination'] . $_FILES['file']['name']);
$src = $_GET['destination'] . $_FILES['file']['name'];
$imgMsg = '';
echo $src;
}
}
}
} else {
$src = '';
$imgMsg = 'Invalid file type.';
}
} else {
$src = '';
$imgMsg = 'File destination not specified.';
}
$surname = '';
$otherNames = '';
$contactAddress = '';
$email = '';
$phone = '';
$occupation = '';
$officeAddress = '';
include 'views/registration.php';
} elseif (isset ($_GET['registration'])) {
$src = '';
$imgMsg = '';
$surname = '';
$otherNames = '';
$contactAddress = '';
$email = '';
$phone = '';
$occupation = '';
$officeAddress = '';
include 'views/registration.php';
} else {
include 'views/home.php';
}
?>
registration.php
<pre><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php setPageTitle('Home'); ?></title>
<link href="styles/site.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="scripts/jquery-1.6.2.js"></script>
<script type="text/javascript" src="scripts/utility.js"></script>
<script type="text/javascript">
function getState(countryId) {
var strURL="shared/finder/_find-states-by-country-id.php?country="+countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
document.getElementById('statediv').innerHTML = req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
$(function() {
$("#upload").click(function() {
if ($("#file").val().length == 0) {
$("#imgMsg").html('File not specified for upload.');
return false;
}
$.ajax({
url: 'index.php?upload&destination=' + $("#destination").val() + '&allowedFiles=' + $("#allowedFiles").val(),
type: 'POST',
success: function(result){
$("#test").html(result);
}
});
return true;
});
});
</script>
</head>
<body>
<div id="container">
<?php include 'shared/_public-header.php'; ?>
<!--
<div id="main">
<div id="sidebar">
</div>
<div id="content">
<h1>Welcome</h1>
<form action="submit-registration" method="post">
<table>
<tr>
<td>
<table>
<tr>
<td>Surname:</td>
<td><input type="text" id="surname" name="surname" value="<?php htmlOut($surname); ?>" /></td>
</tr>
<tr>
<td>Other Names:</td>
<td><input type="text" id="otherNames" name="otherNames" value="<?php htmlOut($otherNames); ?>" /></td>
</tr>
<tr>
<td>Contact Address:</td>
<td><input type="text" id="contactAddress" name="contactAddress" value="<?php htmlOut($contactAddress); ?>" /></td>
</tr>
<tr>
<td>Country:</td>
<td>
<select id="country" name="country" onChange="getState(this.value)">
<option value="">[Select Country]</option>
<?php
$commondData = new CommonData();
$countries = $commondData->getCountries();
if (sizeOf($countries) > 0) {
foreach($countries as $country) {
?>
<option value="<?php echo $country['countryId']; ?>"><?php htmlOut($country['name']); ?></option>
<?php } } ?>
</select>
</td>
</tr>
<tr>
<td>State:</td>
<td>
<div id="statediv">
<select id="state" name="state">
<option value="">[Select country first]</option>
</select>
</div>
</td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="email" id="email" name="email" value="<?php htmlOut($email); ?>" /></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" id="phone" name="phone" value="<?php htmlOut($phone); ?>" /></td>
</tr>
<tr>
<td>Occupation:</td>
<td><input type="text" id="occupation" name="occupation" value="<?php htmlOut($occupation); ?>" /></td>
</tr>
<tr>
<td>Office Address:</td>
<td><input type="text" id="officeAddress" name="officeAddress" value="<?php htmlOut($officeAddress); ?>" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</td>
<td>
<span id="test"></span>
<img name="photo" border="1" src="<?php echo $src; ?>" id="photo" width="120px" height="120px" /><br />
<?php ?>
<!--
<input type="file" name="file" id="file" /><br />
<input type="button" id="upload" value="Upload" /><span id="imgMsg"><?php echo $imgMsg; ?></span>
<input type="hidden" id="destination" name="destination" value="uploads/member/photo/" />
<input type="hidden" id="allowedFiles" name="allowedFiles" value="image/jpeg" />
<input type="hidden" id="maximumFileSize" name="maximumFileSize" value="10000" />
<!--
</td>
</tr>
</table>
</form>
</div>
</div>
<!--
<?php include 'shared/_public-footer.php'; ?>
</div>
</body>
</html>
What am I getting wrong. Please help.
|
|
|
|
|
in your form tag one attribute is missing. Without that attribute browser wont upload file
enctype="multipart/form-data"
I know I am coward since the day I know that fortune favors the brave
|
|
|
|
|
johny10151981 wrote: in your form tag one attribute is missing. Without that attribute browser wont upload file
enctype="multipart/form-data"
Thanks for this.
I have got it working with uploadify [uploadify].
I am very grateful.
|
|
|
|
|
I think this belongs better in the forum as I believe the problem to be on the PHP side. What I'm doing is creating a table dynamically that has some JavaScript function calls in it (well I'm trying to). The page is displaying ok in Chrome and Firefox but IE is complaining about it and not displaying at all. However in Chrome and Firefox it's not "working" just displaying right. this is the code I'm trying to use...
$display_string .= "<td><a href='javascript:choice('".$row .$col ."')'><img src='images/o.jpg' border=0 height=100 width=100 name='" .$row .$col ."' alt='Open'></a></td>";
When you hover over one of the cells on the loaded page you see javascript:choice(. It should read something like javascript:choice(A3) If I do an inspect element with chrome I get
<img src="images/o.jpg" border="0" height="100" width="100" name="B2" alt="Open"> so it appears the issue is in the creation of the javascript call?
Thanks in advance!!
|
|
|
|