0

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!

3
Contributors
4
Replies
23
Views
3 Years
Discussion Span
Last Post by pritaeas
0

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?)

Edited by Zagga

0

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

1

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

Votes + Comments
Yeah that's what I was afraid of, thanks!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.