I am making a script to create a CSV file to pull data out of ze DB. When I run the script it comes back with unexpected T_Variable on line 173 # '$body'. I have checked it a few times and also looked up other incidents with this issue. Perhaps I am overlooking (lack of sleep). Any help would be greatly appreciated!
#!/usr/bin/php
<?php
mysql_connect('localhost', '******', '********');
mysql_select_db('*****');
$id_query = mysql_query("SELECT `id` FROM `leads` WHERE `status` = 'Passed' AND `campaign_id` = '22d0cf4f-0f81-28b1-d8dc-4f06bd1d8ee'");
$id = mysql_fetch_row($id_query);
echo $id[0];
$first_name_query = mysql_query("SELECT `first_name`
FROM `leads`
WHERE `id` = '$id[0]'");
$first_name = mysql_fetch_row($first_name_query);
$url_first_name = $first_name[0];
echo $url_first_name;
$last_name_query = mysql_query("SELECT `last_name`
FROM `leads`
WHERE `id` = '$id[0]'");
$last_name = mysql_fetch_row($last_name_query);
$url_last_name = $last_name[0];
echo $url_last_name;
$phone_home_query = mysql_query("SELECT `phone_home`
FROM `leads`
WHERE `id` = '$id[0]'");
$phone_home = mysql_fetch_row($phone_home_query);
$url_phone_home = $phone_home[0];
echo $url_phone_home;
$primary_address_street_query = mysql_query("SELECT `primary_address_street`
FROM `leads`
WHERE `id` = '$id[0]'");
$primary_address_street = mysql_fetch_row($primary_address_street_query);
$url_primary_address_street = $primary_address_street[0];
echo $url_primary_address_street;
$primary_address_city_query = mysql_query("SELECT `primary_address_city`
FROM `leads`
WHERE `id` = '$id[0]'");
$primary_address_city = mysql_fetch_row($primary_address_city_query);
$url_primary_address_city = $primary_address_city[0];
echo $url_primary_address_city;
$primary_address_state_query = mysql_query("SELECT `primary_address_state`
FROM `leads`
WHERE `id` = '$id[0]'");
$primary_address_state = mysql_fetch_row($primary_address_state_query);
$url_primary_address_state = $primary_address_state[0];
echo $url_primary_address_state;
$primary_address_postalcode_query = mysql_query("SELECT `primary_address_postalcode`
FROM `leads`
WHERE `id` = '$id[0]'");
$primary_address_postalcode = mysql_fetch_row($primary_address_postalcode_query);
$url_primary_address_postalcode = $primary_address_postalcode[0];
echo $url_primary_address_postalcode;
$dateofbirth_c_query = mysql_query("SELECT `dateofbirth_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$dateofbirth_c = mysql_fetch_row($dateofbirth_c_query);
$url_dateofbirth_c = $dateofbirth_c[0];
echo $url_dateofbirth_c;
$gender_c_query = mysql_query("SELECT `gender_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$gender_c = mysql_fetch_row($gender_c_query);
$g2 = substr($gender,0,1);
$url_gender = $g2[0];
echo $url_gender_c;
$testblood_c_query = mysql_query("SELECT `testblood_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$testblood_c = mysql_fetch_row($testblood_c_query);
$b2 = substr($testblood_c,0,1);
$url_testblood_c = $b2[0];
echo $url_testblood_c;
$physicianlastname_c_query = mysql_query("SELECT `physicianlastname_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$physicianlastname_c = mysql_fetch_row($physicianlastname_c_query);
$url_physicianlastname_c = $physicianlastname_c[0];
echo $url_physicianlastname_c;
$physicianfirstname_c_query = mysql_query("SELECT `physicianfirstname_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$physicianfirstname_c = mysql_fetch_row($physicianfirstname_c_query);
$url_physicianfirstname_c = $physicianfirstname_c[0];
echo $url_physicianfirstname_c;
$physiciancity_c_query = mysql_query("SELECT `physiciancity_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$physiciancity_c = mysql_fetch_row($physiciancity_c_query);
$url_physiciancity_c = $physiciancity_c[0];
echo $url_physiciancity_c;
$physicianstate_c_query = mysql_query("SELECT `physicianstate_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$physicianstate_c = mysql_fetch_row($physicianstate_c_query);
$url_physicianstate_c = $physicianstate_c[0];
echo $url_physicianstate_c;
$physicianphone_c_query = mysql_query("SELECT `physicianphone_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$physicianphone_c = mysql_fetch_row($physicianphone_c_query);
$url_physicianphone_c = $physicianphone_c[0];
echo $url_physicianphone_c;
$physicianfax_c_query = mysql_query("SELECT `physicianfax_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$physicianfax_c = mysql_fetch_row($physicianfax_c_query);
$url_physicianfax_c = $physicianfax_c[0];
echo $url_physicianfax_c;
$physiciannpi_c_query = mysql_query("SELECT `physiciannpi_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$physiciannpi_c = mysql_fetch_row($physiciannpi_c_query);
$url_physiciannpi_c = $physiciannpi_c[0];
echo $url_physiciannpi_c;
$primaryinsurance_c_query = mysql_query("SELECT `primaryinsurance_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$primaryinsurance_c = mysql_fetch_row($primaryinsurance_c_query);
$url_primaryinsurance_c = $primaryinsurance_c[0];
echo $url_primaryinsurance_c;
$policynumber_c_query = mysql_query("SELECT `policynumber_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$policynumber_c = mysql_fetch_row($policynumber_c_query);
$url_policynumber_c = $policynumber_c[0];
echo $url_policynumber_c;
$vendorid_c_query = mysql_query("SELECT `vendorid_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$vendorid_c = mysql_fetch_row($vendorid_c_query);
$url_vendorid_c = $vendorid_c[0];
echo $url_vendorid_c;
$groupnumber_c_query = mysql_query("SELECT `groupnumber_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$groupnumber_c = mysql_fetch_row($groupnumber_c_query);
$url_groupnumber_c = $groupnumber_c[0];
echo $url_groupnumber_c;
$pcn_number_c_query = mysql_query("SELECT `pcn_number_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$pcn_number_c = mysql_fetch_row($pcn_number_c_query);
$url_pcn_number_c = $pcn_number_c[0];
echo $url_pcn_number_c;
$bin_number_c_query = mysql_query("SELECT `bin_number_c`
FROM `leads_cstm`
WHERE `id_c` = '$id[0]'");
$bin_number_c = mysql_fetch_row($bin_number_c_query);
$url_bin_number_c = $bin_number_c[0];
echo $url_bin_number_c;
if ($first_name != ''){
$date = date("m-d-y");
$time = time();
$blank = "";
$timestamp = 'A03-'.$date.'-'.$time;
$header = 'BeneficiaryFirstName,BeneficiaryLastName,BeneficiaryAddress1,BeneficiaryAddress2,BeneficiaryCity,BeneficiaryState,BeneficiaryZipCode,BeneficiaryPhone,BeneficiaryDOB,EMail,VendorCustomerID,DoctorNPI,DoctorName,DoctorAddress1,DoctorAddress2,DoctorCity,DoctorState,DoctorZipCode,DoctorPhone,DoctorFax,InsuranceType,InsuranceID,GroupID,BIN,PCN,InsuranceCompanyName,DailyTest,BeneficiaryGender,BestTimeToCall,SourceIP,CurrentMethod,LeadSource,Dependent,Password,ProductTypeID,Incentive';
$body = $url_first_name.','.$url_last_name.','.$url_primary_address_street.','.$blank.','.$url_primary_address_city.','.$url_primary_address_state.','.$url_primary_address_postalcode.','.$url_phone_home.','.$url_dateofbirth_c.','.$blank.','.$url_phone_home.','.$url_physiciannpi_c.','.$blank.','.$blank.','.$blank.','.$url_physiciancity_c.','.$url_physicianstate_c.','.$blank.','$url_physicianphone_c.','.$url_physicianfax_c.','.$url_primaryinsurance_c.','.$url_policynumber_c.','.$url_groupnumber_c.','.$url_bin_number_c.','.$url_pcn_number_c.','.$url_primaryinsurance_c.','.$url_testblood_c.','.$url_gender_c.','.$blank.','.$blank.','.$blank.','.$blank.','.$blank.','.$blank.','.$blank;
$filename = '/home/orsini/Ol-'.$timestamp.'.csv';
$handle = fopen($filename,'w');
fwrite($handle,$header."\n");
fwrite($handle,$body."\n");
fclose($handle);
mysql_query("UPDATE leads SET `status` = 'sold_orsini' WHERE `id` = '$id[0]'");
}
?>
You forgot one dot in your line with $body = $url_first_name at the very end:
,'$url_physicianphone_c.'
Why not use an IDE??
Here is your proper line with $body. You just missed a ..
$body = $url_first_name
.','
.$url_last_name
.','
.$url_primary_address_street
.','
.$blank
.','
.$url_primary_address_city
.','
.$url_primary_address_state.','.$url_primary_address_postalcode.','
.$url_phone_home.','.$url_dateofbirth_c.','.$blank.','.$url_phone_home.','.$url_physiciannpi_c.','
.$blank.','.$blank.','.$blank.','.$url_physiciancity_c.','.$url_physicianstate_c.','
.$blank.','.$url_physicianphone_c . ',' . $url_physicianfax_c
.',' . $url_primaryinsurance_c . ','
.$url_policynumber_c . ',' . $url_groupnumber_c . ',' . $url_bin_number_c . ',' . $url_pcn_number_c . ',' . $url_primaryinsurance_c . ',' . $url_testblood_c
. ',' . $url_gender_c . ',' . $blank . ',' . $blank . ',' . $blank . ',' . $blank . ',' . $blank . ',' . $blank . ',' . $blank;
Found it $url_physicianphone_c. should be .$url_physicianphone_c. Now it has .$url and works.
You can improve things if you consolidated all these queries into just a few. Use table joins to improve this. The DB will be faster at searching and sorting than your PHP.
That said you should also use the PHP CSV functions. Check it out here: http://us.php.net/manual/en/function.fputcsv.php
Related
I have the following code and i get the data for columns except the flag_images and flag_created.
the rows flag_images contain integer 0 but when i try to echo them i get noting.
what might be the issue?
please help
$product = [];
$row_count++;
// echo "\r\n [".$row_count."] " . $data[0] . " <=======\r\n";
$amazon_db = sprintf("select `ratings`,`manufacturer`,`reviews`,`old_price`,`stock`,`asin`,`product_name`,`price`,`description`,`zap_price`,`product_link`,`shipping_o_price`,`images`,`flag_images`,`flag_created` from `amazon-crawler` WHERE `asin` ='%s' limit 0,1", $data[0]);
$amazon_result = $amazon_conn->query($amazon_db);
if (#$amazon_result->num_rows > 0) {
while ($row = $amazon_result->fetch_assoc()) {
$product['asin'] = $row['asin'];
$product['manufacturer'] = $row['manufacturer'];
$product['price'] = $row['price'];
$product['zap_link_price'] = $row['zap_price'];
$product['product_link'] = $row['product_link'];
$product['shipping_o_price'] = $row['shipping_o_price'];
$product['images'] = $row['images'];
**$product['flag_images'] = $row['flag_images'];
$product['flag_created'] = $row['flag_created'];**
echo $product['flag_created'];
echo $product['flag_images'];
$product['stock'] = $row['stock'];
$product['amazon_ratings'] = $row['ratings'];
I'm trying to get the data from my database according to the certain id if the database.
Here is my code. But they are not working else
$selectquery,$resultsgetdata,$countprodu
<?php
$profrom = $_GET['id'];
$selectquery = "SELECT * FROM tbl_name WHERE proid = '$profrom'";
$resultsgetdata = mysql_query($selectquery);
$countprodu= mysql_num_rows($resultsgetdata);
if($countprodu>0)
{
$proidid = $row['proid'];
$proidName = $row['proName'];
$proidDescription = $row['proDescription'];
$Category = $row['proCategory'];
$Price = $row['Price'];
$Photo1name = $row['Photo1name'];
}
echo $proidid;
?>
your forgot to fetch the value try this
<?php
$profrom = $_GET['id'];
$selectquery = "SELECT * FROM tbl_name WHERE proid = '$profrom'";
$resultsgetdata = mysql_query($selectquery);
$countprodu= mysql_num_rows($resultsgetdata);
if($countprodu>0)
{
while($row = mysql_fetch_assoc($resultsgetdata){
$proidid = $row['proid'];
$proidName = $row['proName'];
$proidDescription = $row['proDescription'];
$Category = $row['proCategory'];
$Price = $row['Price'];
$Photo1name = $row['Photo1name'];
}
}
?>
You need to use mysql_fetch_assoc().
<?php
$profrom = $_GET['id'];
$selectquery = "SELECT * FROM tbl_name WHERE proid = '$profrom'";
$resultsgetdata = mysql_query($selectquery);
$countprodu= mysql_num_rows($resultsgetdata);
if($countprodu>0)
{
while($row = mysql_fetch_assoc($resultsgetdata))
{
$proidid = $row['proid'];
$proidName = $row['proName'];
$proidDescription = $row['proDescription'];
$Category = $row['proCategory'];
$Price = $row['Price'];
$Photo1name = $row['Photo1name'];
echo $proidid;
}
}
?>
Try this I hope it will work,
<?php
$profrom = $_GET['id'];
$selectquery = "SELECT * FROM tbl_name WHERE proid = '$profrom'";
$resultsgetdata = mysql_query($selectquery);
$countprodu= mysql_num_rows($resultsgetdata);
if($countprodu>0)
{
while($row = mysql_fetch_array($resultsgetdata))
{
$proidid = $row['proid'];
$proidName = $row['proName'];
$proidDescription = $row['proDescription'];
$Category = $row['proCategory'];
$Price = $row['Price'];
$Photo1name = $row['Photo1name'];
echo $proidid;
}
}
?>
I have this code which is supposed to delete two image files from two diffrent folders at the same time. The issue is, only one image is deleted. the other is not. I have tried different methods but still the same issue.
Below is my code.
<?php
$colname_albumedit = "-1";
if (isset($_GET['arf'])) {
$colname_albumedit = $_GET['arf'];
}
$query_album = "SELECT * FROM galbum WHERE alID = '" . $colname_albumedit . "'";
$result_album = mysqli_query($connKcla, $query_album);
$row_album = mysqli_fetch_assoc($result_album);
$totalRows_album = mysqli_num_rows($result_album);
$query_album_images = "SELECT * FROM gimage WHERE alID = '" . $colname_albumedit . "'";
$result_album_images = mysqli_query($connKcla, $query_album_images);
$row_album_images = mysqli_fetch_assoc($result_album_images);
$totalRows_album_images = mysqli_num_rows($result_album_images);
if ((isset($_POST["form_del"])) && ($_POST["form_del"] == "adalbumdel")) {
$target = "../gallery/albums/";
$targett = "../gallery/images/";
$imID = $_GET['arf'];
$sql_query = "SELECT alImage FROM galbum WHERE alID = $imID";
$photoresult = mysqli_query($connKcla, $sql_query);
$row_album = mysqli_fetch_assoc($photoresult);
if (($row_album['alImage']) != 0) {
unlink($target . $row_album['alImage']);
}
$sql_queryy = "SELECT albumRef FROM gimage WHERE albumRef = $imID";
$photoresultt = mysqli_query($connKcla, $sql_queryy);
$row_album_images = mysqli_fetch_assoc($photoresultt);
if (($row_album_images['albumRef']) != 0) {
unlink($targett . $row_album_images['albumRef']);
}
$query_del = "DELETE FROM galbum WHERE alID = $colname_albumedit";
$result_del = mysqli_query($connKcla, $query_del);
$queryy_del = "DELETE FROM gimage WHERE alID = $colname_albumedit";
$resultt_del = mysqli_query($connKcla, $queryy_del);
if ($result_del && $resultt_del) {
$updateGoTo = "confirm.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header("Location: " . $updateGoTo);
} else {
header("Location: error.php");
}
}
The table gImage looks like this:
CREATE TABLE IF NOT EXISTS gimage (
imID bigint(20) NOT NULL AUTO_INCREMENT,
imImage varchar(255) DEFAULT NULL,
albumRef bigint(20) DEFAULT NULL,
PRIMARY KEY (imID), KEY alID (albumRef)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
Think, just replace this code
$sql_queryy = "SELECT albumRef FROM gimage WHERE albumRef = $imID";
$photoresultt = mysqli_query($connKcla, $sql_queryy);
$row_album_images = mysqli_fetch_assoc($photoresultt);
if (($row_album_images['albumRef']) != 0) {
unlink($targett . $row_album_images['albumRef']);
}
with this code.
$sql_queryy = "SELECT imImage FROM gimage WHERE albumRef = $imID";
$photoresultt = mysqli_query($connKcla, $sql_queryy);
$row_album_images = mysqli_fetch_all($photoresultt);
foreach ($row_album_images as $row) {
unlink($targett . $row[0]);
}
Recommendation
Rename your variable $imID cause it is in reality the albumId. As you can see in your code in the lines
$imID = $_GET['arf'];
$sql_query = "SELECT alImage FROM galbum WHERE alID = $imID";
$data = mysql_query(" SELECT * FROM user_pokemon_db WHERE user_id = '".$id."' ");
while($rows = mysql_fetch_array($data))
{
$pkmn_id = $rows['pkmn_id'];
$path = mysql_query(" SELECT path FROM pokemons WHERE pk_id = '".$pkmn_id."' ");
$poke = mysql_result($path, 0, "path");
echo $poke;
echo "<br />";
$level = $rows['level'];
echo $level;
echo "<br />";
$exp = $rows['exp'];
echo $exp;
This is my PHP code, its showing an error:
Array to string conversion in C:\wamp\www\slots.php on line 18
Line 18 is this:while($rows = mysql_fetch_array($data))
I haven't used any array?? but this used to work! but suddenly this error started coming??
Check if $id is an array, it seems that it causes this problem.
$id = "'" . implode("', '", $id) . "'";
$data = mysql_query(" SELECT * FROM user_pokemon_db WHERE user_id IN ({$id}) ");
Full error:
Parse error: syntax error, unexpected T_VARIABLE in /home/u572186424/public_html/safe.php on line 56
I have been staring at line 56 and cannot figure it out...
exit();
The whole file follows:
<?php
include_once("connect.php");
?>
<?
$sql = "SELECT * FROM users WHERE id='" . mysql_real_escape_string($_SESSION['user_id']) . "'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$id = htmlspecialchars($row->id);
$userip = htmlspecialchars($row->userip);
$username = htmlspecialchars($row->username);
$password = htmlspecialchars($row->password);
$account_type = htmlspecialchars($row->account_type);
$money = htmlspecialchars($row->money);
$exp = htmlspecialchars($row->exp);
$req_exp = htmlspecialchars($row->req_exp);
$level = htmlspecialchars($row->level);
$health = htmlspecialchars($row->health);
$max_health = htmlspecialchars($row->max_health);
$lastactive = htmlspecialchars($row->lastactive);
$energy = htmlspecialchars($row->energy);
$max_energy = htmlspecialchars($row->max_energy);
$will = htmlspecialchars($row->will);
$max_will = htmlspecialchars($row->max_will);
$brave = htmlspecialchars($row->brave);
$max_brave = htmlspecialchars($row->max_brave);
$strength = htmlspecialchars($row->strength);
$agility = htmlspecialchars($row->agility);
$guard = htmlspecialchars($row->guard);
$labor = htmlspecialchars($row->labor);
$iq = htmlspecialchars($row->iq);
$rank = htmlspecialchars($row->rank);
?>
<?php
$sql = "SELECT * FROM sitestats WHERE id='1'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$admins = htmlspecialchars($row->admins);
$mods = htmlspecialchars($row->mods);
$hdo = htmlspecialchars($row->hdo);
$admins_ip = htmlspecialchars($row->admins_ip);
$mods_ip = htmlspecialchars($row->mods_ip);
$admin_array = explode("-", $admins);
$mod_array = explode("-", $mods);
$hdo_array = explode("-", $hdo);
$admin_ip_array = explode("-", $admins_ip);
$mod_ip_array = explode("-", $mods_ip);
?>
<html>
<body>
<?
if(isset($_SESSION['user_id'])) {
$sql = "UPDATE users SET lastactive=NOW() WHERE id='" . mysql_real_escape_string($_SESSION['user_id']) . "'";
mysql_query($sql);
}
else{
header("Location: logout.php");
exit(); // Error here
}
$query = "SELECT account_type,rank FROM users WHERE username= "$username";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
if($row['account_type'] == 1){
$row['rank'] = "Player";
$rank = "Player";
}
elseif($row['account_type'] == 2){
$row['rank'] = "VIP";
$rank = "VIP";
}
elseif($row['account_type'] == 3){
$row['rank'] = "HDO";
$rank = "HDO";
}
elseif($row['account_type'] == 4){
$row['rank'] = "Moderator";
$rank = "Moderator";
}
elseif($row['account_type'] == 5){
$row['rank'] = "Admin";
$rank = "Admin";
}
elseif($row['account_type'] == 6){
$row['rank'] = "Owner";
$rank = "Owner";
}
?>
</body>
</html>
How can I fix this problem?
The syntax highlighting shows you. Problem is the extra quote " here:
$query = "SELECT account_type,rank FROM users WHERE username= "$username";
Try:
$query = "SELECT account_type,rank FROM users WHERE username= '$username'";
There are no dots when you concatenate the query and $username:
$query = "SELECT account_type,rank FROM users WHERE username= "$username";