Hey guys, so I'm having some issues putting my script together.. Basically, I'm trying to loop through my database and send each entry username to a url, and once through all entries, send 'done'.

Using PHPStorm and getting an "Expecting statement' error. Here's what I have so far:

<?php

define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASS', '');
define('DB_HOST', '');



$action=$_POST['action'];
$targeturl=$_POST['url'];
$avatarname = $_POST['avatarname'];


$database_link = mysql_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!isset($database_link))
{
    die('Connection Failure: '.mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $database_link);
if(!isset($db_selected))
{
    die('Can\'t use '.DB_NAME.': '.mysql_error());
}

if($action == 'download')
{
     $loop = mysql_query("SELECT * FROM accesslist") or die (mysql_error());

     while ($row = mysql_fetch_array($loop))
     {
         $myvars = 'myvar1='.$row['avatarname'];

         $ch = curl_init( $targeturl );
         curl_setopt( $ch, CURLOPT_POST, 1);
         curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
         curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt( $ch, CURLOPT_HEADER, 0);
         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

         $response = curl_exec( $ch );
     }

     else
     {
         $myvars = 'myvar1='.'done';

         $ch = curl_init( $targeturl );
         curl_setopt( $ch, CURLOPT_POST, 1);
         curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
         curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt( $ch, CURLOPT_HEADER, 0);
         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

         $response = curl_exec( $ch );
    }
}

?>

Thanks!

Using PHPStorm and getting an "Expecting statement' error. Here's what I have so far:

On which line?

Member Avatar for Zagga

This looks like a nesting issue.

PHP is seeing line 43 as the end of your WHILE loop, not the end of the first IF condition.
(Move line 58 to line 44?)

So.. are you saying close the if statement between the while and the else?

Wouldn't that negate what I'm trying to do with the else? Also, is it even possible to use an else in this way, in else of a while statement?

Thanks

A while does not have an else. You'll have to put an if before the while.

commented: Yeah that's what I was afraid of, thanks! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.