How do I FORMAT a Get Url for Ajax WHERE x=post

Get help using Construct 2

Post » Mon Aug 25, 2014 10:18 pm

getdata.png
Hi all,
I am trying to use Ajax to get some data out of the base.
The bit i am stuck on is in Construct2 where the url to request is

Code: Select all
"http://mysite.com/myphps/getdata.php?name="&textbox1.text


the result i am looking to compute is
$name=post_['name']
Data from base WHERE name =$name.

All the videos i have seen so far don't have the a variable to play with and I am running out of ideas.
thanks.
You do not have the required permissions to view the files attached to this post.
B
13
S
4
Posts: 60
Reputation: 1,001

Post » Tue Aug 26, 2014 6:57 am

Not sure what exactly your stuck on...

If it is the php part; post_['name'] doesn't look correct. Try $_POST["name"]

If that isn't the problem then:
1. Can you output textbox1.text somewhere to see it is getting the correct text?, you'll need to url encode it so that it doesn't cause problem with spaces and special characters!
2. Can you post the php you have so far if the problem is there?
B
32
S
7
G
2
Posts: 317
Reputation: 2,851

Post » Tue Aug 26, 2014 11:53 am

IndieKiwi wrote:Not sure what exactly your stuck on...

If it is the php part; post_['name'] doesn't look correct. Try $_POST["name"]

If that isn't the problem then:
1. Can you output textbox1.text somewhere to see it is getting the correct text?, you'll need to url encode it so that it doesn't cause problem with spaces and special characters!
2. Can you post the php you have so far if the problem is there?


Hi IndieKiwi, Thanks for helping,

Heres the php ,

Code: Select all
<?php
header('Access-Control-Allow-Origin: *');




$host="mysite.com/ect"; // Host name
$username="username1"; // Mysql username
$password="passwordtest"; // Mysql password
$db_name="dbname1"; // Database name
$tbl_name="table1"; // Table name

$name = mysqli_real_escape_string($con, $_POST['name']);

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Retrieve data from database
$sql="SELECT * FROM pits WHERE name='$name' ";
$result=mysql_query($sql);

// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
echo $rows['name'] . "|" . $rows['info1'] . "|". $rows['info2'] . "|";

// close while loop
}

// close MySQL connection
mysql_close();
?>

When I change this
Code: Select all
$sql="SELECT * FROM pits WHERE name='$name' ";

to this
Code: Select all
 $sql="SELECT * FROM pits ";[/code
I get all the data from the base back

and when i change to
[code]$sql="SELECT * FROM pits WHERE name='bob' ";

I get bob's data back ,

this leads me to believe that I have screwed up the Construct2 line.
B
13
S
4
Posts: 60
Reputation: 1,001

Post » Tue Aug 26, 2014 1:10 pm

I have not worked with PHP for quite a while now, but I doubt that AJAX is sending a POST-Request. I think the correct syntax should be $_GET['name'] instead
B
44
S
10
G
8
Posts: 437
Reputation: 6,463

Post » Tue Aug 26, 2014 2:33 pm

Ubivis wrote:I have not worked with PHP for quite a while now, but I doubt that AJAX is sending a POST-Request. I think the correct syntax should be $_GET['name'] instead

Thank you,

I have changed the php to read

Code: Select all
$name = $_GET['name'];
$sql = "SELECT * FROM pits WHERE name=$name ";


this duz not compute to wanted output. just keep getting a blank page.

However if i change it to select from a different column like id ,
Code: Select all
$id = $_GET['id'];
$sql = "SELECT * FROM pits WHERE id=$id ";

and use a URL like " mysite.com/myphps/get.php?id=1"

I get all the data from line 1 or 2 or 3 what ever line i put at "?id= " {it also works with other columns that hold numbers for data } but not any of the text columns,

is there a setting to stop the php reading and searching text columns ?
B
13
S
4
Posts: 60
Reputation: 1,001

Post » Tue Aug 26, 2014 2:38 pm

I imagine your column "name" is string and "id" is numeric?
In this case, try this:

Code: Select all
$name = $_GET['name'];
$sql = "SELECT * FROM pits WHERE name='$name'";
B
44
S
10
G
8
Posts: 437
Reputation: 6,463

Post » Tue Aug 26, 2014 4:59 pm

Ubivis wrote:I imagine your column "name" is string and "id" is numeric?
In this case, try this:

Code: Select all
$name = $_GET['name'];
$sql = "SELECT * FROM pits WHERE name='$name'";

WONDERFULL Ubivis , thank you very much , and thank you again,
-------------------------------------------------------
Ajax OUT working
-------------------------------------------------------
B
13
S
4
Posts: 60
Reputation: 1,001


Return to How do I....?

Who is online

Users browsing this forum: yiuyiu6666 and 17 guests