Endpoint issue for posting to SQL - php

I have a simple 1 page webapp which uses AJAX to GET/POST mostly, however, when I try to run the SQL on one of my endpoints, it throws an internal server error and I can't think why, I tested my SQL command in PHPMyAdmin and it worked, I tested to be sure my values are being captured, and they are, so I cannot see the issue, any help would be great, here is my form:
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="UTF-8">
<title>Add a new album</title>
</head>
<body>
<p class="yeah">Add a new album</p>
<form action="http://localhost:8000/musicOnline/assets/scripts/php/create/new/" method="post" enctype="multipart/form-data">
<input type="text" placeholder="Artist Name" name="artist" required>
<input type="text" placeholder="Album Name" name="album" required>
<input type="text" placeholder="Genre" name="genre" required>
<input type="date" placeholder="Release Date" name="release" required>
<input type="text" placeholder="Record Label" name="recordLabel" required>
<input type="text" placeholder="enter a star rating (1 - 5)" name="rating">
<input type="submit" value="submit">
</form>
</body>
</html>
My AJAX handler:
//forms that post, put, delete or get
$(document).on("submit", "form", function (e) {
e.preventDefault();
$this = $(this),
$data = $this.serializeArray(),
$method = $this.attr("method"),
$endpointURL = $this.attr("action");
$.ajax({
type: $method,
data: $data,
url: $endpointURL,
success: function (data) {
$("#content-lockup").html(data);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("error: " + textStatus + ", error thrown: " + errorThrown);
}
});
return false;
});
And the endpoints code (/assets/scripts/php/create/new/):
<?php
require "http://localhost:8000/musicOnline/assets/scripts/php/dbConn/index.php";
$artist = $_POST['artist'];
$album = $_POST['album'];
$genre = $_POST['genre'];
$release = $_POST['release'];
$rating = $_POST['rating'];
$recordLabel = $_POST['recordLabel'];
try {
//prepare our statement
$preparedQuery = $conn->prepare("insert into albums (artistName, albumName, genre, releaseDate, recordLabel, rating) values ('" . $artist . "', '" . $album . "', '" . $genre . "', '" . $release . "', '" . $recordLabel . "', '" . $rating . "')");
//execute the statement
if($preparedQuery->execute()) {
echo "success";
$conn = null;
} else {
echo "nope";
$conn = null;
}
} catch(PDOException $e) {
echo 'Error: ' . $e->getMessage();
}
?>
And my db connection:
<?php
session_start();
//setup variables
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "dgc_music_online";
//instantiate our PDO connection to the DB
$conn = new PDO("mysql:host=$servername;dbname=$dbname;", $username, $password);
?>
And a screenshot of the console.log that is output:

Try to change your endpoint code to follow this manual: http://php.net/manual/en/pdo.prepared-statements.php
//prepare our statement
$preparedQuery = $conn->prepare("insert into albums (artistName, albumName, genre, releaseDate, recordLabel, rating) values (?, ?, ?, ?, ?, ?)");
//execute the statement
if($preparedQuery->execute(array($artist, $album, $genre, $release, $recordLabel, $rating))) {

In case of errors like that you should always the error details in you nginx/apache error logs. Most of the time there is something helpful recorded.

Related

Save login form data using php

html webpage screenshotphp code shown on button clickmySql database tableI need to store user login data. i am using phpMyAdmin. When I click on submit button, data is not stored. Instead the php code is shown. Both code files are given below. What I am doing wrong. Help me. I
am unable to store user data using phpmyadmin in xampp.
my html code
<html>
<head>
<title>Yahoo Signin And Signup Form</title>
</head>
<body>
<h2 style="color: midnightblue">yahoo!</h2>
<hr color="magenta">
<form method="post" action="connect.php" >
<fieldset style="background:#6495ED;">
<legend style="padding:20px 0; font-size:20px;">Signup:</legend>
<label for ="firstName">Enter First Name</label><br>
<input type="text" placeholder="First name" id="firstName" name ="firstName">
<br>
<label for ="lastName">Enter Last Name</label><br>
<input type="text" placeholder="Last name" id="lastName" name ="lastName">
<br>
<label for ="email">Enter Email</label><br>
<input type="text" placeholder="Email" id="email" name ="email"><br>
<label for ="password">Enter Password</label><br>
<input type="password" placeholder="Password" id="password" name ="password">
<br>
<label for ="number">Enter Mobile Number</label><br>
<input placeholder="03---" id="number" name ="number"><br>
<label for ="date">Enter Date of Birth</label><br>
<input type="text" placeholder="DD/MM/YY" id="date" name ="date"><br>
<label for ="gender">Enter Gender</label><br>
<input type="text" placeholder="Male/Female/Other" id="gender" name
="gender"><br>
<br><button style="background-color:orangered;border-
color:dodgerblue;color:lightyellow">Signup</button>
</fielsdet>
</form>
</body>
</html>
my connect.php
<?php
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$password = $_POST['password'];
$number = $_POST['number'];
$date = $_POST['date'];
$gender = $_POST['gender'];
// Making Connection with database
$con = new mysqli('localhost','root','','phpdata');
if ($con -> connect_error) {
die('Connection failed :'.$conn -> connect_error);
}
else{
$stmt = $con->query("INSERT INTO signup(firstName, lastName, email, password,
number, date, gender)
values(?,?,?,?,?,?,?)");
$stmt->bind_param("ssssiss",$firstName, $lastName, $email, $password,
$number, $date, $gender);
$stmt->execute();
echo "Sign up successful";
$stmt->close();
$con->close();
}?>
Use prepare instead of query. All everything is ok.:
$stmt = $con->prepare("INSERT INTO signup(firstName, lastName, email, password, number, date, gender)
values(?,?,?,?,?,?,?)");
And make button type as submit:
<br><button type="submit" style="background-color:orangered;border-color:dodgerblue;color:lightyellow">Signup</button>
here is the code, it works fine with me
<?php
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$password = $_POST['password'];
$number = $_POST['number'];
$date = $_POST['date'];
$gender = $_POST['gender'];
// Making Connection with database
$con = new mysqli('localhost','root','','phpdata');
if ($con -> connect_error) {
die('Connection failed :'.$conn -> connect_error);
}
else{
$stmt = $con->query("INSERT INTO signup(firstName, lastName, email, password, number, date, gender)
values("'.$firstName.'","'.$lastName.'","'.$email.'","'.$password.'","'.$number.'","'.$date.'","'.$gender.'")");
if ($con->query($stmt) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$con->close();
}//end of else of connection
?>
Add type in your submit button.
<button type='submit' style="background-color:orangered;border-color:dodgerblue;color:lightyellow">Signup</button>
and also your question marks and params ara not matching. it should be match. otherwise data won't store your db
correct that line also
The main problem is you are not loading code via apache server try to open http://localhost/signup.html instead of C:/xmapp/htdocs/connect.php
It seems you want to user PDO but your connection string not correct
<?php
$firstName = trim($_POST['firstName']);
$lastName = trim($_POST['lastName']);
$email = trim($_POST['email']);
$password = md5(trim($_POST['password']));
$number = trim($_POST['number']);
$date = trim($_POST['date']);
$gender = trim($_POST['gender']);
$con= new PDO("mysql:host=127.0.0.1;dbname=phpdata", 'root', 'root');
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqli = "INSERT INTO signup(firstName, lastName, email, password, number, date, gender)
values(?,?,?,?,?,?,?)";
try {
$stmt= $con->prepare($sqli);
$stmt->bindParam(1,$firstName);
$stmt->bindParam(2,$lastName);
$stmt->bindParam(3,$email);
$stmt->bindParam(4,$password);
$stmt->bindParam(5,$number);
$stmt->bindParam(6,$date);
$stmt->bindParam(7,$gender);
$status = $stmt->execute();
echo "Sign up successful";
$stmt->close();
$con->close();
} catch(PDOException $e) {
echo "Error ".$e->getMessage();
}
?>
another problem is with your html form button type is missing
<button type="submit".... />
Here is the complete code after analyzing it for a lot of time. in your $stmt variable there was no query, it was empty. This code works fine just copy and paste it.
<?php
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$password = $_POST['password'];
$number = $_POST['number'];
$date = $_POST['date'];
$gender = $_POST['gender'];
// Making Connection with database
$con = new mysqli('localhost','root','','abc');
if ($con -> connect_error) {
die('Connection failed :'.$conn -> connect_error);
}
else{
$sql = "INSERT INTO signup(firstName, lastName, email, password, number, date, gender)
values('$firstName','$lastName','$email','$password','$number','$date','$gender')";
if ($con->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
$con->close();
}//end of else of connection
?>

Uncaught Error: Call to a member function prepare() on boolean ... Stack trace: #0 {main} thrown in [duplicate]

This question already has answers here:
Why does this PDO statement silently fail?
(2 answers)
Closed 3 years ago.
I'm trying to use Ajax and PHP to send my input data database without refreshing the page. But I am getting this error and it's been couple of hours of me solving this issue but I still can't. Please help me. Thanks!
This is my index.php file where I placed my ajax script and html codes.
$(document).ready(function() {
$('#myForm').submit(function(event) {
event.preventDefault();
$.ajax({
url: 'insert.php',
method: 'post',
data: $('form').serialize(),
dataType: 'text',
success: function(strMessage) {
$('#result').text(strMessage);
$('#myForm')[0].reset();
}
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h5 class="alert-heading">
ADD INFORMATION
</h5>
<hr>
<form id="myForm" method="post" action="">
<div class="form-group">
<label>Full name</label>
<input type="text" autofocus="on" class="form-control" name="fullname" placeholder="Enter your name here" required>
</div>
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" name="address" placeholder="Address" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<div class="alert alert-success" role="alert" id="result"></div>
And here's my insert.php file
<?php
try {
include_once 'classes/Db.php';
$fullname = addslashes($_POST['fullname']);
$address = addslashes($_POST['address']);
$sql = "INSERT INTO users (null, fullname, address) VALUES ('$fullname', '$address')";
$stmt = $conn->prepare($sql);
$stmt->execute();
} catch (PDOException $e) {
echo "ERROR IN INSERTING DATA! : " . $e->getMessage();
}
?>
And my classes/Db.php file
<?php
$localhost = 'localhost';
$dbname = 'test_icon';
$username = 'root';
$password = '';
try {
$sql = 'mysql:localhost=' .$localhost. '; dbname=' .$dbname;
$stmt = new PDO($sql, $username, $password);
$conn = $stmt->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "CONNECTION FAILED: " .$e->getMessage(). '<br/>';
die();
}
?>
First fix ;
$sql = 'mysql:localhost=' .$localhost. '; dbname=' .$dbname;
Should be :
$sql = 'mysql:host=' .$localhost. '; dbname=' .$dbname;
Then :
$sql = "INSERT INTO users (fullname, address) VALUES (?,?)";
$stmt = $conn->prepare($sql);
$stmt->execute([$fullname,$address]);
When you create your PDO instance you are setting the connection to the result of setAttribute which is a boolean indicating whether the function succeeded or not. You should be setting it to the output of the constructor:
$conn = new PDO($sql, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

PHP/MYSQL Log-in update troubles

I have been working on this Login script for awhile and everything works, except this update function. I have tried changing variable name and everything else. On UpdateUser.php, the code works if I insert variables instead of the $[POST] variables. I am at a loss. Any help would be greatly appreciated. Sorry for the messy code, this is a class assignment, so I wasn't worried about password security at the moment.
This is index4.php
<form id="form" action="index4.php" method="post">
<h2>Update Your Login</h2>
UserName:<br>
<input type="text" id="useuserName" required />
<br>
Password:<br>
<input type="text" id="usepassWord" required />
<br>
First Name:<br>
<input type="text" id="usefirstName" required />
<br>
Last Name:<br>
<input type="text" id="uselastName" required />
<br>
<input id="updateuser" type ="submit" />
</form>
<script>
$('#updateuser').click(function() {
var useID = $_SESSION["id"];
var useuserName = $("#useuserName").val();
var usepassWord = $("#usepassWord").val();
var usefirstName = $("#usefirstName").val();
var uselastName = $("#uselastName").val();
var usePermissions = $_SESSION["Permissions"];
$.ajax({
type : 'POST',
url : '',
data :{action:'updateuser', useID:useID, useuserName:useuserName, uselastName:uselastName, usePermissions:usePermissions},
error: function (html) {
alert( "What the duck" );
},
});
});
</script>
This is the UpdateUser.php file
<?php
//Update
if($_POST['action'] == 'updateuser'){
//Set Variables
$servername = "localhost";
$username = "root";
$password = "";
$db = "userdb";
//Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection: Failed! " . $conn->connect_error);
}
//Actual Code
$useID = $_POST['useID'];
$useuserName = $_POST['useuserName'];
$usepassWord = $_POST['usePassword'];
$usefirstName = $_POST['usefirstName'];
$uselastName = $_POST['uselastName'];
$usePermissions = $_POST['usePermissions'];
//Create Query
$sql = "UPDATE users SET userName = '$useuserName', Pass = '$usepassWord', firstName = '$usefirstName', lastname = '$uselastName', Permissions = '$usePermissions' WHERE id =" . $useID ."";
//Did it work Check
if ($conn->query($sql) === TRUE) {
echo "Cool";
} else {
echo "What " . $conn->error;
}
//Close Out
$conn->close();
}
?>

Fetch and insert data into mysql using angularjs

I am unable to connect insert the date into sql server using angularjs & php.
I want to know how to insert data in sql and fetch the data from db.
<body>
<div ng-app="myapp" ng-controller="empcontroller">
<form>
Employe No. <input type="text" ng-model="emp_no" /><br/>
First Name. <input type="text" ng-model="first_name" /><br/>
Last Name. <input type="text" ng-model="last_name" /><br/>
Department. <input type="text" ng-model="dept_name" /><br/>
<input type="button" value="submit" ng-click="insertdata()"/> <br/>
</form>
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular-route.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script type="text/javascript">
var app = angular.module('myapp',[]);
app.controller('empcontroller', function($scope, $http){
$scope.insertdata=function(){
$http.post("insert.php",{'emp_no':$scope.emp_no,'first_name':$scope.first_name,'last_name':$scope.last_name,'dept_name':$scope.dept_name})
.success(function(data,status,headers,config){
console.log("data insert succesfully");
});
}
});
</script>
</body>
PHP CODE:
$data = json_decode(file_get_contents("php://input"));
$empno = mysql_real_escape_string($data->emp_no);
$fname = mysql_real_escape_string($data->first_name);
$lname = mysql_real_escape_string($data->last_name);
$dept = mysql_real_escape_string($data->dept_name);
$con = mysql_connect("localhost", "root", "root");
mysql_select_db("company", $con);
mysql_query("INSERT INTO employee('emp_no', 'first_name', 'last_name', 'dept_name')VALUES('".$empno."','".$fname."','".$lname."','".$dept."')");
Here You go Try this
HTML
<div ng-app="myapp" ng-controller="empcontroller">
<form>
Employe No. <input type="text" ng-model="emp_no" /><br/>
First Name. <input type="text" ng-model="first_name" /><br/>
Last Name. <input type="text" ng-model="last_name" /><br/>
Department. <input type="text" ng-model="dept_name" /><br/>
<button ng-click="postData()">Submit</button><br>
</form>
</div>
CONTROLLER:
app.controller('empcontroller', function ($scope, $http) {
/*
* This method will be called on click event of button.
*/
$scope.postData = function () {
var request = $http({
method: "post",
url: window.location.href + "insert.php",
data: {
emp_no: $scope.emp_no,
first_name: $scope.first_name,
last_name: $scope.last_name,
dept_name: $scope.dept_name,
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
}
});
PHP CODE:
<?php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$emp_no = $request->emp_no;
$first_name = $request->first_name;
$last_name = $request->last_name;
$dept_name = $request->dept_name;
$servername = "localhost";
$username = "root";
$password = "root"; //Your User Password
$dbname = "myDB"; //Your Database Name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO employee (emp_no, first_name, last_name, dept_name)
VALUES ($emp_no, $first_name, $last_name , $dept_name)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Three problems with your code:
When executing $scope functions with ng-click, best practice is to pass in the variables as you use them.
Since your PHP controller is expecting JSON, you should form a JSON object and indicate it in the headers.
.success() is being deprecated. You should use the promise .then() instead.
HTML:
<!-- need to pass model in the ng-click function -->
<input type="button" value="submit" ng-click="insertdata(emp_no, first_name, last_name, dept_name)"/>
Controller:
$scope.insertata = function(empNo, firstName, lastName, deptName) {
//make json payload object
var payload = {
emp_no: empNo,
first_name: firstName,
last_name: lastName,
dept_name: deptName
};
//pass to API
$http.post('insert.php', payload, {
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).then(function(data, status, headers, config) {
//success
}, function(data, status, headers, config) {
//an error occurred
});
}
well, using the code of KKKKKKKK now you need a php code.
To retrieve information from a json file posted using post to php you should do something like this:
$json = file_get_contents('php://input');
$obj = json_decode($json); // this will retrieve the json.
And now manipulate as you want.

How can I pass the data to database?

In this form I am trying to redirect the user to the given url. There I can only use get method to pass parameters. But my form data are not save in the database when I use the get method. I want to save the data at the same time in the database.
Here is my code:
<?php
include_once 'CryptoUtils.php';
include_once 'dbconnect.php';
if(isset($_POST['btn-signup']))
{
$mobile = mysql_real_escape_string($_POST['Mnumber']);
$email = mysql_real_escape_string($_POST['email']);
$fname = mysql_real_escape_string($_POST['fname']);
$address = mysql_real_escape_string($_POST['address']);
$sitename = mysql_real_escape_string($_POST['sitename']);
$q = ("INSERT INTO template_users(Mnumber,email,fname,address,sitename) VALUES('$mobile','$email','$fname','$address','$sitename')");
mysql_query ($q) or die("Problem with the query: $q<br>" . mysql_error());
}
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Ipayy </title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<center>
<div id="login-form">
<form action="http://api.ipayy.com/v001/c/oc/dopayment" method="get" >
<table align="left" width="40%" border="0">
<h1 align="left">Create Your Web Site</h1></br></br>
<input type="hidden" name="gh" value="<?php echo $encrypted_string; ?>" />
<tr>
<td><input type="text" name="Mnumber" value="" placeholder="Your Mobile Number" required /></td>
</tr>
<tr>
<td><input type="email" name="email" value="" placeholder="Your Email" required /></td>
</tr>
<tr>
<td><input type="text" name="fname" value="" placeholder="Your First Name" required /></td>
</tr>
<tr>
<td><input type="text" name="address" value="" placeholder="Your Address" required /></td>
</tr>
<tr>
<td><input type="text" name="sitename" value="" placeholder="Your Site name" required /></td>
</tr>
<tr>
<td><button type="submit" name="btn-signup" onclick="myFunction()">Create My gomobi website</button></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
Here is my db connection:
<?php
if(!mysql_connect("localhost","root",""))
{
die('oops connection problem ! --> '.mysql_error());
}
if(!mysql_select_db("ipay"))
{
die('oops database selection problem ! --> '.mysql_error());
}
?>
As you are sending requests to an external link and also want to process the same request in your own server, then either you have to use AJAX to send two requests or you have to use curl to send one request to external link. Hope the following may help.
<button type="button" name="btn-signup" onclick="myFunction()">Create My gomobi website</button>
Check above button code, I changed it to type button as I prefer you to post the form data using your myFunction() and by AJAX. Now below is the possible code for myFunction() . [Note: You must have some code already in myFunction(), which I dont know, you just keep them if needed and also add the following code to it] In case ajax form posting you need not to use method or action in your form tag.
function myFunction()
{
var gh = $('input[name=gh]').val();
var Mnumber = $('input[name=Mnumber]').val();
var email = $('input[name=email]').val();
var fname= $('input[name=fname]').val();
var address= $('input[name=address]').val();
var sitename= $('input[name=sitename]').val();
$.get("http://api.ipayy.com/v001/c/oc/dopayment",
{
gh : gh,
Mnumber : Mnumber,
email : email,
fname : fname,
address : address,
sitename : sitename
},
function(data,status){
//console.log(data);
if(status == 'success')
{
//another POST or GET ajax method can be initiated with same data
//but differant url (the url of your php code which is inserting data to database)Here is an example below
$.post("storedatatodb.php",
{
gh : gh,
Mnumber : Mnumber,
email : email,
fname : fname,
address : address,
sitename : sitename
},
function(data,status)
{
if(status == 'success')
{
// do something - redirect to some page
}
});
}
else
{
//show error message
// or do nothing
}
});
}
In the above case the storedatatodb.php will be like follows
<?php
include_once 'dbconnect.php';
$mobile = mysql_real_escape_string($_POST['Mnumber']);
$email = mysql_real_escape_string($_POST['email']);
$fname = mysql_real_escape_string($_POST['fname']);
$address = mysql_real_escape_string($_POST['address']);
$sitename = mysql_real_escape_string($_POST['sitename']);
$q = ("INSERT INTO template_users(Mnumber,email,fname,address,sitename) VALUES('$mobile','$email','$fname','$address','$sitename')");
mysql_query ($q) or die("Problem with the query: $q<br>" . mysql_error());
?>
ANOTHER method is to use PHP curl .
In this case you may use any method of GET or POST in form tag and in action , use the url of the php file processing your data to insert into db. Assume the file is storedatatodb.php . The code will be like follows
<?php
include_once 'dbconnect.php';
$gh = $_POST['gh'];
$mobile = mysql_real_escape_string($_POST['Mnumber']);
$email = mysql_real_escape_string($_POST['email']);
$fname = mysql_real_escape_string($_POST['fname']);
$address = mysql_real_escape_string($_POST['address']);
$sitename = mysql_real_escape_string($_POST['sitename']);
$q = ("INSERT INTO template_users(Mnumber,email,fname,address,sitename) VALUES('$mobile','$email','$fname','$address','$sitename')");
mysql_query ($q) or die("Problem with the query: $q<br>" . mysql_error());
//curl to send data to external URL
// In case of GET request
$geturl = "http://api.ipayy.com/v001/c/oc/dopayment?gh=".$gh."&mobile=".$mobile."&email=".$email."&fname=".$fname."&address=".$address."&sitename=".$sitename;
// Get cURL resource
$curl = curl_init();
// Set some options
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $geturl
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
//Print error if any
if(curl_errno($curl))
{
echo 'error:' . curl_error($curl);
}
// Close request to clear up some resources
curl_close($curl);
?>
If you are submitting data to same page
then
change from
<form action="http://api.ipayy.com/v001/c/oc/dopayment" method="get" >
to
<form action="">
and also change from
<?php
include_once 'CryptoUtils.php';
include_once 'dbconnect.php';
if(isset($_POST['btn-signup']))
{
$mobile = mysql_real_escape_string($_POST['Mnumber']);
$email = mysql_real_escape_string($_POST['email']);
$fname = mysql_real_escape_string($_POST['fname']);
$address = mysql_real_escape_string($_POST['address']);
$sitename = mysql_real_escape_string($_POST['sitename']);
$q = ("INSERT INTO template_users(Mnumber,email,fname,address,sitename) VALUES('$mobile','$email','$fname','$address','$sitename')");
mysql_query ($q) or die("Problem with the query: $q<br>" . mysql_error());
}
?>
to
<?php
include_once 'CryptoUtils.php';
include_once 'dbconnect.php';
if(isset($_POST['btn-signup']))
{
$mobile = mysql_real_escape_string($_GET['Mnumber']);
$email = mysql_real_escape_string($_GET['email']);
$fname = mysql_real_escape_string($_GET['fname']);
$address = mysql_real_escape_string($_GET['address']);
$sitename = mysql_real_escape_string($_GET['sitename']);
$q = ("INSERT INTO template_users(Mnumber,email,fname,address,sitename) VALUES('$mobile','$email','$fname','$address','$sitename')");
mysql_query ($q) or die("Problem with the query: $q<br>" . mysql_error());
}
?>

Categories