How to put a $thing in the api script

roofgah

New member
Joined
Oct 10, 2006
Messages
2
Hello

I'm working with the api but i have some questions. I have a database with usernames and i want to select the usernames from the mysql database as username in DA.

So this is my scipt for db connect

Code:
<?php 

mysql_connect("localhost", "xxxxxx", "xxxx"); 
mysql_select_db("xxxxx"); 

$res = mysql_query("SELECT voornaam FROM informatie"); 
while ($arr = mysql_fetch_assoc($res)) { 
  echo $arr["voornaam"]." "; 

} 
mysql_free_result($res);

He selects voornaam(dutch for name) from informatie(dutch for information) (the name what he will select is rutger)

Now I put the api script with it:



Code:
<?php 

mysql_connect("localhost", "xxxxxxx", "xxxxxx"); 
mysql_select_db("xxxxxxx"); 

$res = mysql_query("SELECT voornaam FROM informatie"); 
while ($arr = mysql_fetch_assoc($res)) { 
  echo $arr["voornaam"]." "; 

} 
mysql_free_result($res); 

include("httpsocket.php"); 

$sock = new HTTPSocket; 


$sock->connect("domain.com",2222); 
$sock->set_login("xxxxxx","xxxxxxx"); 

$sock->set_method("POST"); 

$sock->query("/CMD_ACCOUNT_USER",  
    array(  
"domain" => "domain.com",  
"action" => "create",
"add" => "submit",
"username" => "$arr["voornaam"]." ";",
"email" => "[email protected]",
"passwd" => "123456789",
"passwd2" => "123456789",
"domain" => "domain.com",
"package" => "Linkservice",
"ip" => "xx.xxx.xx.xxx",
"notify" => "yes",
));  

$result = $sock->fetch_body();  
echo $result;  

?>

When I open this .php page in the browser I get this:
Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /xxxxx/xxxxxx/xxxxx/xxxxxx/public_html/mysql.php on line 34

line 34 is this line: "username" => "$arr["voornaam"]." ";",

What's wrong with this line?

Greetings Rutger
 
Last edited:
When you spend some seconds to look at the line you should see that it has to be:

PHP:
"username" => $arr["voornaam"]." ",
or
PHP:
"username" => $arr["voornaam"],
without the trailing space.

Syntax is right, I don't know if the meaning is right. That's up to you.
 
it doesn't work neither. Is it possible to get information from a database in a api?

Kind Regards Rutger
 
Sure it is. But you have to be sure to post all data correctly. We can't help you on this.
 
Back
Top