SQLSTATE[42000]: Syntax error or access violation: 1064 Error in setting Variable in bindparam
up vote
0
down vote
favorite
I want to get data from DB and add string to theme and put them in another query . When I run code I've got this error :
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or
access violation: 1064 You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ''goldhyipPID', 'goldhyipPayStatus',
programName,'goldhyipLastPayout') VALUES ('1' at line 1 in
C:wamp64wwwallmonitorstest.php on line 69
<?php
set_time_limit(3600);
require_once 'fetchdetails/func.php';
require_once 'config.php';
$stmt = $conn->prepare("SELECT * FROM `monitors`");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $monitor) {
$monitorName = $monitor['monitorName'];
$monitorNamePID = $monitorName . 'PID';
$monitorNameLastPayout = $monitorName . 'LastPayout';
$monitorNamePayStatus = $monitorName . 'PayStatus';
$siteURL = $monitor['monitorurl'];
$pattern1GetPID = $monitor['monitorPatternGetPID'];
$patternLastPayOut = $monitor['monitorPatternLastPayout'];
$patternPStatus = $monitor['monitorPatternPayStatus'];
$patterndetailsurl = $monitor['monitorDetailsLink'];
$patterngotositesurl = $monitor['monitorPatternGoSite'];
$content = getPageContent($siteURL);
preg_match_all($pattern1GetPID, $content, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $pid) {
$id = $pid[1];
$detailsurl = $patterndetailsurl . $id;
$gositesurl = $patterngotositesurl . $id;
$details = getPageContent($detailsurl);
preg_match_all($patternPStatus, $details, $status);
$payingStatusNumber = $status[1][0];
if ($payingStatusNumber == 4) {
$payingStatus = 'Not Paying';
} elseif ($payingStatusNumber == 3) {
$payingStatus = 'Problem';
} elseif ($payingStatusNumber == 2) {
$payingStatus = 'Waiting';
} elseif ($payingStatusNumber == 1) {
$payingStatus = 'Paying';
}
preg_match_all($patternLastPayOut, $details, $payout);
if (isset($payout[1][0])) {
$payoutdate = $payout[1][0];
} else {
$payoutdate = ' Not Set';
};
$stmt2 = $conn->prepare('SELECT * FROM programs where :monitorNamePID=:id');
$stmt2->bindParam('monitorNamePID', $monitorNamePID);
$stmt2->bindParam('id', $id);
$stmt2->execute();
$numofupdates = $stmt2->rowCount();
if ($numofupdates >= 1) {
$stmt3 = $conn->prepare("UPDATE programs SET :monitorNamePayStatus=:payingstatus , :monitorNameLastPayout=:goldhyiplastpayout WHERE :monitorNamePID=:goldhyippid ");
$stmt3->bindParam('monitorNamePayStatus', $monitorNamePayStatus);
$stmt3->bindParam('monitorNameLastPayout', $monitorNameLastPayout);
$stmt3->bindParam('monitorNamePID', $monitorNamePID);
$stmt3->bindParam('payingstatus', $payingStatus);
$stmt3->bindParam('goldhyiplastpayout', $payoutdate);
$stmt3->bindParam('goldhyippid', $id);
$stmt3->execute();
echo 'P ID Updated : ' . $id . '<br>';
} else {
$siteAddress = get_redirect_final_host_url($gositesurl);
echo $siteAddress;
$stmt3 = $conn->prepare('INSERT INTO programs (:monitorNamePID, :monitorNamePayStatus, programName,:monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
$stmt3->bindParam('monitorNamePID', $monitorNamePID);
$stmt3->bindParam('monitorNamePayStatus', $monitorNamePayStatus);
$stmt3->bindParam('monitorNameLastPayout', $monitorNameLastPayout);
$stmt3->bindParam('goldhyippid', $id);
$stmt3->bindParam('payingstatus', $payingStatus);
$stmt3->bindParam('progname', $siteAddress);
$stmt3->bindParam('goldhyiplastpayout', $payoutdate);
$stmt3->execute();
echo 'P ID inserted : ' . $id . '<br>';
}
}
echo "Fetching $siteURL Done <br>";
}
I took details from sql, and add string to them, use in PDO query. When I write column name its ok but when I use Variable I got error.
php mysql pdo
add a comment |
up vote
0
down vote
favorite
I want to get data from DB and add string to theme and put them in another query . When I run code I've got this error :
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or
access violation: 1064 You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ''goldhyipPID', 'goldhyipPayStatus',
programName,'goldhyipLastPayout') VALUES ('1' at line 1 in
C:wamp64wwwallmonitorstest.php on line 69
<?php
set_time_limit(3600);
require_once 'fetchdetails/func.php';
require_once 'config.php';
$stmt = $conn->prepare("SELECT * FROM `monitors`");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $monitor) {
$monitorName = $monitor['monitorName'];
$monitorNamePID = $monitorName . 'PID';
$monitorNameLastPayout = $monitorName . 'LastPayout';
$monitorNamePayStatus = $monitorName . 'PayStatus';
$siteURL = $monitor['monitorurl'];
$pattern1GetPID = $monitor['monitorPatternGetPID'];
$patternLastPayOut = $monitor['monitorPatternLastPayout'];
$patternPStatus = $monitor['monitorPatternPayStatus'];
$patterndetailsurl = $monitor['monitorDetailsLink'];
$patterngotositesurl = $monitor['monitorPatternGoSite'];
$content = getPageContent($siteURL);
preg_match_all($pattern1GetPID, $content, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $pid) {
$id = $pid[1];
$detailsurl = $patterndetailsurl . $id;
$gositesurl = $patterngotositesurl . $id;
$details = getPageContent($detailsurl);
preg_match_all($patternPStatus, $details, $status);
$payingStatusNumber = $status[1][0];
if ($payingStatusNumber == 4) {
$payingStatus = 'Not Paying';
} elseif ($payingStatusNumber == 3) {
$payingStatus = 'Problem';
} elseif ($payingStatusNumber == 2) {
$payingStatus = 'Waiting';
} elseif ($payingStatusNumber == 1) {
$payingStatus = 'Paying';
}
preg_match_all($patternLastPayOut, $details, $payout);
if (isset($payout[1][0])) {
$payoutdate = $payout[1][0];
} else {
$payoutdate = ' Not Set';
};
$stmt2 = $conn->prepare('SELECT * FROM programs where :monitorNamePID=:id');
$stmt2->bindParam('monitorNamePID', $monitorNamePID);
$stmt2->bindParam('id', $id);
$stmt2->execute();
$numofupdates = $stmt2->rowCount();
if ($numofupdates >= 1) {
$stmt3 = $conn->prepare("UPDATE programs SET :monitorNamePayStatus=:payingstatus , :monitorNameLastPayout=:goldhyiplastpayout WHERE :monitorNamePID=:goldhyippid ");
$stmt3->bindParam('monitorNamePayStatus', $monitorNamePayStatus);
$stmt3->bindParam('monitorNameLastPayout', $monitorNameLastPayout);
$stmt3->bindParam('monitorNamePID', $monitorNamePID);
$stmt3->bindParam('payingstatus', $payingStatus);
$stmt3->bindParam('goldhyiplastpayout', $payoutdate);
$stmt3->bindParam('goldhyippid', $id);
$stmt3->execute();
echo 'P ID Updated : ' . $id . '<br>';
} else {
$siteAddress = get_redirect_final_host_url($gositesurl);
echo $siteAddress;
$stmt3 = $conn->prepare('INSERT INTO programs (:monitorNamePID, :monitorNamePayStatus, programName,:monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
$stmt3->bindParam('monitorNamePID', $monitorNamePID);
$stmt3->bindParam('monitorNamePayStatus', $monitorNamePayStatus);
$stmt3->bindParam('monitorNameLastPayout', $monitorNameLastPayout);
$stmt3->bindParam('goldhyippid', $id);
$stmt3->bindParam('payingstatus', $payingStatus);
$stmt3->bindParam('progname', $siteAddress);
$stmt3->bindParam('goldhyiplastpayout', $payoutdate);
$stmt3->execute();
echo 'P ID inserted : ' . $id . '<br>';
}
}
echo "Fetching $siteURL Done <br>";
}
I took details from sql, and add string to them, use in PDO query. When I write column name its ok but when I use Variable I got error.
php mysql pdo
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to get data from DB and add string to theme and put them in another query . When I run code I've got this error :
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or
access violation: 1064 You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ''goldhyipPID', 'goldhyipPayStatus',
programName,'goldhyipLastPayout') VALUES ('1' at line 1 in
C:wamp64wwwallmonitorstest.php on line 69
<?php
set_time_limit(3600);
require_once 'fetchdetails/func.php';
require_once 'config.php';
$stmt = $conn->prepare("SELECT * FROM `monitors`");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $monitor) {
$monitorName = $monitor['monitorName'];
$monitorNamePID = $monitorName . 'PID';
$monitorNameLastPayout = $monitorName . 'LastPayout';
$monitorNamePayStatus = $monitorName . 'PayStatus';
$siteURL = $monitor['monitorurl'];
$pattern1GetPID = $monitor['monitorPatternGetPID'];
$patternLastPayOut = $monitor['monitorPatternLastPayout'];
$patternPStatus = $monitor['monitorPatternPayStatus'];
$patterndetailsurl = $monitor['monitorDetailsLink'];
$patterngotositesurl = $monitor['monitorPatternGoSite'];
$content = getPageContent($siteURL);
preg_match_all($pattern1GetPID, $content, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $pid) {
$id = $pid[1];
$detailsurl = $patterndetailsurl . $id;
$gositesurl = $patterngotositesurl . $id;
$details = getPageContent($detailsurl);
preg_match_all($patternPStatus, $details, $status);
$payingStatusNumber = $status[1][0];
if ($payingStatusNumber == 4) {
$payingStatus = 'Not Paying';
} elseif ($payingStatusNumber == 3) {
$payingStatus = 'Problem';
} elseif ($payingStatusNumber == 2) {
$payingStatus = 'Waiting';
} elseif ($payingStatusNumber == 1) {
$payingStatus = 'Paying';
}
preg_match_all($patternLastPayOut, $details, $payout);
if (isset($payout[1][0])) {
$payoutdate = $payout[1][0];
} else {
$payoutdate = ' Not Set';
};
$stmt2 = $conn->prepare('SELECT * FROM programs where :monitorNamePID=:id');
$stmt2->bindParam('monitorNamePID', $monitorNamePID);
$stmt2->bindParam('id', $id);
$stmt2->execute();
$numofupdates = $stmt2->rowCount();
if ($numofupdates >= 1) {
$stmt3 = $conn->prepare("UPDATE programs SET :monitorNamePayStatus=:payingstatus , :monitorNameLastPayout=:goldhyiplastpayout WHERE :monitorNamePID=:goldhyippid ");
$stmt3->bindParam('monitorNamePayStatus', $monitorNamePayStatus);
$stmt3->bindParam('monitorNameLastPayout', $monitorNameLastPayout);
$stmt3->bindParam('monitorNamePID', $monitorNamePID);
$stmt3->bindParam('payingstatus', $payingStatus);
$stmt3->bindParam('goldhyiplastpayout', $payoutdate);
$stmt3->bindParam('goldhyippid', $id);
$stmt3->execute();
echo 'P ID Updated : ' . $id . '<br>';
} else {
$siteAddress = get_redirect_final_host_url($gositesurl);
echo $siteAddress;
$stmt3 = $conn->prepare('INSERT INTO programs (:monitorNamePID, :monitorNamePayStatus, programName,:monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
$stmt3->bindParam('monitorNamePID', $monitorNamePID);
$stmt3->bindParam('monitorNamePayStatus', $monitorNamePayStatus);
$stmt3->bindParam('monitorNameLastPayout', $monitorNameLastPayout);
$stmt3->bindParam('goldhyippid', $id);
$stmt3->bindParam('payingstatus', $payingStatus);
$stmt3->bindParam('progname', $siteAddress);
$stmt3->bindParam('goldhyiplastpayout', $payoutdate);
$stmt3->execute();
echo 'P ID inserted : ' . $id . '<br>';
}
}
echo "Fetching $siteURL Done <br>";
}
I took details from sql, and add string to them, use in PDO query. When I write column name its ok but when I use Variable I got error.
php mysql pdo
I want to get data from DB and add string to theme and put them in another query . When I run code I've got this error :
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or
access violation: 1064 You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ''goldhyipPID', 'goldhyipPayStatus',
programName,'goldhyipLastPayout') VALUES ('1' at line 1 in
C:wamp64wwwallmonitorstest.php on line 69
<?php
set_time_limit(3600);
require_once 'fetchdetails/func.php';
require_once 'config.php';
$stmt = $conn->prepare("SELECT * FROM `monitors`");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $monitor) {
$monitorName = $monitor['monitorName'];
$monitorNamePID = $monitorName . 'PID';
$monitorNameLastPayout = $monitorName . 'LastPayout';
$monitorNamePayStatus = $monitorName . 'PayStatus';
$siteURL = $monitor['monitorurl'];
$pattern1GetPID = $monitor['monitorPatternGetPID'];
$patternLastPayOut = $monitor['monitorPatternLastPayout'];
$patternPStatus = $monitor['monitorPatternPayStatus'];
$patterndetailsurl = $monitor['monitorDetailsLink'];
$patterngotositesurl = $monitor['monitorPatternGoSite'];
$content = getPageContent($siteURL);
preg_match_all($pattern1GetPID, $content, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $pid) {
$id = $pid[1];
$detailsurl = $patterndetailsurl . $id;
$gositesurl = $patterngotositesurl . $id;
$details = getPageContent($detailsurl);
preg_match_all($patternPStatus, $details, $status);
$payingStatusNumber = $status[1][0];
if ($payingStatusNumber == 4) {
$payingStatus = 'Not Paying';
} elseif ($payingStatusNumber == 3) {
$payingStatus = 'Problem';
} elseif ($payingStatusNumber == 2) {
$payingStatus = 'Waiting';
} elseif ($payingStatusNumber == 1) {
$payingStatus = 'Paying';
}
preg_match_all($patternLastPayOut, $details, $payout);
if (isset($payout[1][0])) {
$payoutdate = $payout[1][0];
} else {
$payoutdate = ' Not Set';
};
$stmt2 = $conn->prepare('SELECT * FROM programs where :monitorNamePID=:id');
$stmt2->bindParam('monitorNamePID', $monitorNamePID);
$stmt2->bindParam('id', $id);
$stmt2->execute();
$numofupdates = $stmt2->rowCount();
if ($numofupdates >= 1) {
$stmt3 = $conn->prepare("UPDATE programs SET :monitorNamePayStatus=:payingstatus , :monitorNameLastPayout=:goldhyiplastpayout WHERE :monitorNamePID=:goldhyippid ");
$stmt3->bindParam('monitorNamePayStatus', $monitorNamePayStatus);
$stmt3->bindParam('monitorNameLastPayout', $monitorNameLastPayout);
$stmt3->bindParam('monitorNamePID', $monitorNamePID);
$stmt3->bindParam('payingstatus', $payingStatus);
$stmt3->bindParam('goldhyiplastpayout', $payoutdate);
$stmt3->bindParam('goldhyippid', $id);
$stmt3->execute();
echo 'P ID Updated : ' . $id . '<br>';
} else {
$siteAddress = get_redirect_final_host_url($gositesurl);
echo $siteAddress;
$stmt3 = $conn->prepare('INSERT INTO programs (:monitorNamePID, :monitorNamePayStatus, programName,:monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
$stmt3->bindParam('monitorNamePID', $monitorNamePID);
$stmt3->bindParam('monitorNamePayStatus', $monitorNamePayStatus);
$stmt3->bindParam('monitorNameLastPayout', $monitorNameLastPayout);
$stmt3->bindParam('goldhyippid', $id);
$stmt3->bindParam('payingstatus', $payingStatus);
$stmt3->bindParam('progname', $siteAddress);
$stmt3->bindParam('goldhyiplastpayout', $payoutdate);
$stmt3->execute();
echo 'P ID inserted : ' . $id . '<br>';
}
}
echo "Fetching $siteURL Done <br>";
}
I took details from sql, and add string to them, use in PDO query. When I write column name its ok but when I use Variable I got error.
php mysql pdo
php mysql pdo
edited Nov 11 at 5:44
Tân Nguyễn
1
1
asked Nov 11 at 5:39
misagh ahmadi
83
83
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Column names shouldn't be prepended with a colon. Remove colon :
from your column names in both UPDATE
and INSERT
queries. Binding a table (or column) name doesn't work.
$stmt3 = $conn->prepare("UPDATE programs SET monitorNamePayStatus=:payingstatus , monitorNameLastPayout=:goldhyiplastpayout WHERE monitorNamePID=:goldhyippid ");
$stmt3 = $conn->prepare('INSERT INTO programs (monitorNamePID, monitorNamePayStatus, programName, monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
add a comment |
up vote
0
down vote
accepted
Binding a table (or column) name doesn't work
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Column names shouldn't be prepended with a colon. Remove colon :
from your column names in both UPDATE
and INSERT
queries. Binding a table (or column) name doesn't work.
$stmt3 = $conn->prepare("UPDATE programs SET monitorNamePayStatus=:payingstatus , monitorNameLastPayout=:goldhyiplastpayout WHERE monitorNamePID=:goldhyippid ");
$stmt3 = $conn->prepare('INSERT INTO programs (monitorNamePID, monitorNamePayStatus, programName, monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
add a comment |
up vote
0
down vote
Column names shouldn't be prepended with a colon. Remove colon :
from your column names in both UPDATE
and INSERT
queries. Binding a table (or column) name doesn't work.
$stmt3 = $conn->prepare("UPDATE programs SET monitorNamePayStatus=:payingstatus , monitorNameLastPayout=:goldhyiplastpayout WHERE monitorNamePID=:goldhyippid ");
$stmt3 = $conn->prepare('INSERT INTO programs (monitorNamePID, monitorNamePayStatus, programName, monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
add a comment |
up vote
0
down vote
up vote
0
down vote
Column names shouldn't be prepended with a colon. Remove colon :
from your column names in both UPDATE
and INSERT
queries. Binding a table (or column) name doesn't work.
$stmt3 = $conn->prepare("UPDATE programs SET monitorNamePayStatus=:payingstatus , monitorNameLastPayout=:goldhyiplastpayout WHERE monitorNamePID=:goldhyippid ");
$stmt3 = $conn->prepare('INSERT INTO programs (monitorNamePID, monitorNamePayStatus, programName, monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
Column names shouldn't be prepended with a colon. Remove colon :
from your column names in both UPDATE
and INSERT
queries. Binding a table (or column) name doesn't work.
$stmt3 = $conn->prepare("UPDATE programs SET monitorNamePayStatus=:payingstatus , monitorNameLastPayout=:goldhyiplastpayout WHERE monitorNamePID=:goldhyippid ");
$stmt3 = $conn->prepare('INSERT INTO programs (monitorNamePID, monitorNamePayStatus, programName, monitorNameLastPayout) VALUES (:goldhyippid, :payingstatus, :progname, :goldhyiplastpayout)');
edited Nov 11 at 8:02
answered Nov 11 at 7:55
Samir
5,1232626
5,1232626
add a comment |
add a comment |
up vote
0
down vote
accepted
Binding a table (or column) name doesn't work
add a comment |
up vote
0
down vote
accepted
Binding a table (or column) name doesn't work
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Binding a table (or column) name doesn't work
Binding a table (or column) name doesn't work
answered Nov 20 at 17:20
misagh ahmadi
83
83
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246148%2fsqlstate42000-syntax-error-or-access-violation-1064-error-in-setting-variabl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown