Ok , so when someone buys item from my site, it is ment to insert that item ID into the database , but it doesnt for some reason.
$mysql_host = 'localhost'; //Leave at localhost
$mysql_user = ''; //DB User
$mysql_pass = ''; //DB Pass
$mysql_db = ''; //DB Name
$file = 'paypal.log'; //Paypal Log Name will be placed in the same location as your ipn.php file
$payer_email = $_REQUEST['payer_email'];
$ip = $_SERVER['REMOTE_ADDR'];
$time = date("F j, Y, g:i a");
$paylist = array("5.00" => 15017, "0.01" => 18830, "10.00" => 13840, "10.01" => 13842, "9.99" => 13729, "15.00" => 19111, "60.00" => 1046, "40.00" => 1050, "14.99" => 6199);
// connect db
$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die(mysql_error());
$custom = stripslashes(ucwords(strtolower(trim($_REQUEST['custom']))));
$receiver_email = $_REQUEST['receiver_email'];
$payment_status = $_REQUEST['payment_status'];
$mc_gross = $_REQUEST['mc_gross'];
mysql_select_db($mysql_db, $db);
if ($_REQUEST['debug']){
print $payment_status . '\n';
print (isset($paylist[$mc_gross])) ? 1 : 0 . '\n';
print $receiver_email . '\n';
print $custom . '\n';
}
if ($payment_status == "Completed" && $receiver_email == "justincopp77#yahoo.com" && isset($paylist[$mc_gross])) {
$query = "INSERT `status` SET `item` = '$itemid' ,`username` = '$custom'";
$result2 = mysql_query($query) or die(mysql_error());
$prem = mysql_fetch_array($result);
$somecode = "'$time' '$custom' '$payer_email' '$mc_gross' '$ip'\r\n";
// figure out how much to give
$give = $paylist[$mc_gross];
$itemid = $prem['item'] + $give;
// $points = mysql_query($prem)
$qry2 = "SELECT `item` FROM `status` WHERE `username` = '$custom'";
// Log Paypal Transaction
$hak = fopen($file, "a");
fwrite($hak, $somecode);
fclose($hak);
$result2 = mysql_query($qry2) or die(mysql_error());
}
?>
you can see its not putting the item ID in
Does anyone know why it wont inset item id into the database?
What will i need to change to fix it
Thanks in advance
your sql syntax is wrong
$query = "INSERT INTO `status` (item, username) VALUES ('$itemid' ,'$custom')";
Related
SO i want to insert my item id and together with my item name into a distribution_item,it only insert item id but not the name because of the array
i use item[$i] whenever there is a item in the table row, so it get the data and insert.
#$recipient = $_POST['recipient'];
#$address = $_POST['address'];
#$contact = $_POST['contact'];
#$date = $_POST['in_date'];
#$itemID = $_POST['id'];
#$remark = $_POST['remark'];
#$spec_remark = $_POST['spec_remark'];
$itemBalance = $_POST["count"];
$count = count($itemID);
// authentication to the database
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "hopeplace";
//Create connection
$Conndb = mysqli_connect($servername, $username, $password, $dbName);
// Check connection
if (!$Conndb) {
die("Connection failed: " . $Conndb->connect_error);
}
else {
// select database
mysqli_select_db($Conndb, $dbName);
$full_name = "SELECT * FROM recipient WHERE `FULL_NAME` = '$recipient'";
$result = mysqli_query($Conndb, $full_name);
$rec = mysqli_fetch_array($result);
$recipient_id = $rec['HP_ID'];
$item_id = "SELECT ITEM_NAME FROM inventory WHERE ITEM_ID = '$itemID'";
$result2 = mysqli_query($Conndb, $item_id);
$rec2 = mysqli_fetch_array($result2);
$item_name = $rec2["ITEM_NAME"];
$string = implode(',',$item_id);
$sql = "SHOW TABLE STATUS WHERE `Name` = 'distribution';";
$result = mysqli_query($Conndb, $sql);
$data = mysqli_fetch_assoc($result);
$DISTRIBUTION_ID = $data['Auto_increment'];
// Add into distribution table
$sql = "INSERT INTO distribution(DISTRIBUTION_ID,HP_ID,FULL_NAME, ADDRESS, CONTACT, DISTRIBUTION_DATE, SPEC_REMARK) VALUES ('$DISTRIBUTION_ID','$recipient_id','$recipient', '$address', '$contact', '$date', '$spec_remark')";
if (mysqli_query($Conndb, $sql)) {
//Add item into distribution_item table
$item_count = 0;
for ($i=0; $i<$count; $i++){
$sql = "INSERT INTO distribution_item (DISTRIBUTION_ID, ITEM_ID,ITEM_NAME,OUT_QUANTITY,REMARK) VALUES ('$DISTRIBUTION_ID', '$itemID[$i]','$string[$i]','$itemBalance[$i]', '$remark[$i]')";
if (mysqli_query($Conndb, $sql)){
$out = "UPDATE inventory set QUANTITY = QUANTITY - '$itemBalance[$i]' where ITEM_ID= '$itemID[$i]'";
mysqli_query($Conndb, $out);
//echo "<p>Item $itemID[$i] has been added to $DISTRIBUTION_ID</p>";
$item_count++;
} else {
echo "Error: $sql <br />" . mysqli_error($Conndb);
}
}
if ($item_count == $count){
echo "<div>
<script>
window.alert('Record added successfully!');
</script>
</div>";
}
} else {
echo "Error: $sql <br />" . mysqli_error($Conndb);
}
}
mysqli_close($Conndb);
?>
it pop out an error like this
Notice: Array to string conversion in C:\xampp\htdocs\hopeplace\distribution\add_distribution.php on line 55
Warning: implode(): Invalid arguments passed in C:\xampp\htdocs\hopeplace\distribution\add_distribution.php on line 56
it seems like i have to convert my array to string so i can pass the value into table. my database table is something like this
DISTRIBUTION_ID | ITEM_NAME | ITEM_NAME|
1 1 APPLE
1 2 ORANGE
The problem here is that $string[$i] cannot be found because no $string array exists, since $string = implode(', ',$item_id) can only work if $item_id is an array.
In the question, $item_id = "SELECT ITEM_NAME FROM inventory WHERE ITEM_ID = '$itemID'"; gives $item_id as a string. That is why the warning error indicates that the implode function cannot work. The notice error shows that you cannot get an array element from the $string variable, and this is because that variable is not an array.
To get $string as an array, you would have to correct the following code:
$item_id = "SELECT ITEM_NAME FROM inventory WHERE ITEM_ID = '$itemID'";
$result2 = mysqli_query($Conndb, $item_id);
$rec2 = mysqli_fetch_array($result2);
$item_name = $rec2["ITEM_NAME"];
$string = implode(',',$item_id);
For example, the above code could be changed to the following:
$string = [];
$item_id = "SELECT ITEM_NAME FROM inventory WHERE ITEM_ID = '$itemID'";
$result2 = mysqli_query($Conndb, $item_id);
while($rec2 = mysqli_fetch_array($result2){
$string[] = $rec2["ITEM_NAME"];
}
Then in the sql query for inserting the item name you would first define the counting variable as $count = count($string);
I am having some problems with checking if the field is empty or not in SQL using PHP without using mysql_fetch_array().
I have this code:
date_default_timezone_set('Asia/Taipei');
$remarks = $_POST['remarks'];
$date_added = date ("Y-m-d");
$time_added = date ("h:i:s a");
$lname = $_SESSION['user']['last_name'];
$fname = $_SESSION['user']['first_name'];
$minitial = $_SESSION['user']['middle_initial'];
$con = mysqli_connect("localhost", "root", "", "thisdb");
if(empty(`TIME_IN_1`)) {
$query = "INSERT INTO time_logs (LAST_NAME, FIRST_NAME, MIDDLE_INITIAL, DATE, TIME_IN_1, TIME_IN_1_REMARKS) VALUES('$lname', ' $fname', '$minitial', '$date_added', '$time_added', '$remarks')";
}
else {
$query = "UPDATE time_logs SET TIME_IN_2 = '$time_added' where LAST_NAME = '$lname' AND DATE = '$date_added'";
}
$save = mysqli_query($con, $query);
header("Location: time_in_complete.php");
What I basically want to accomplish is if the TIME_IN_1 field is empty, the data will be added there. If it is not empty, then the data will be added to the TIME_IN_2.
Apprently, this line:
if(empty(`TIME_IN_1`))
doesn't seem to work.
$first_query = "SELECT TIME_IN_1 FROM time_logs WHERE LAST_NAME = '" . $lname . "' AND FIRST_NAME = '" . $fname . "'";
$data = mysqli_query($con, $first_query);
$num_row = mysqli_num_rows($data);
if($num_row == 0) {
$query = "INSERT INTO time_logs (LAST_NAME, FIRST_NAME, MIDDLE_INITIAL, DATE, TIME_IN_1, TIME_IN_1_REMARKS) VALUES('$lname', ' $fname', '$minitial', '$date_added', '$time_added', '$remarks')";
}
else {
$query = "UPDATE time_logs SET TIME_IN_2 = '$time_added' where LAST_NAME = '$lname' AND DATE = '$date_added'";
}
$save = mysqli_query($con, $query);
header("Location: time_in_complete.php");
Try a query like:
SELECT TIME_IN_1 from time_logs where LAST_NAME = '$lname' AND DATE = '$date_added'
Then:
// Default to true and set this false if we find a value
$bIsEmpty = true;
// Check if any rows match
if ($result->num_rows > 0){
// Yes a row matches, so check if we have a value
$row = $result->fetch_object();
if ($row->TIME_IN_1 != "")
$bIsEmpty = false;
}
if ($bIsEmpty === true){
// Do your insert
} else {
// Do your update
}
Hi i am having an issue selecting a value form my table into a variable in the PHP so that I can calculate the cost of something
here is the code I have so far I want to be able to select a "cost" value from the table C_price where the values of I_type and a_type match
E.g. the table structure looks like this
ID=1,A_type=line,I_type=Head,cost=5
if on the form i enter line and head
i need to be able to get the value 5 in to a venerable i can use in calculations and insert into another table AKA i need to get cost into a variable somehow
the following was my try and i need help im new at all this so please help
$E_C;
$T_cost = "1";
$date = date("d.m.y");
$name = $_POST["from"];
$email = $_POST["email"];
$ref = $_POST["link"];
$i_type = $_POST["i_type"];
$a_type = $_POST["a_type"];
$extra = $_POST["extra"];
$des = $_POST["description"];
$BG = $_POST["BG"];
$bg_type = $_POST["BGtype"];
$msg = $_POST["message"];
$auto_reply = ("thanks for the email we will get back to you as soon as we can about the cost and how you can pay");
$msg = wordwrap($msg, 70);
$host = "localhost";// hostname
$USER = "root";// username
$PASS = "Password";// password
$DBNAME = "andrea";// databace name
$tbl_name = "c_price";// table name
$con = mysqli_connect("localhost", $USER, $PASS, $DBNAME)or die("mySQL server connection failed");
$all = "SELECT cost FROM C_price WHERE a_type=$a_type,i_type=$i_type";
$result = mysqli_query($con,$all) or die("Error getting total storse");
while($row = mysqli_fetch_array($result))
{
echo $row['cost'];
}
if ($a_type = 'waist' && $extra='Y')
{
$E_C = $cost * .3;
}
elseif ($a_type = 'knee' && $extra='Y')
{
$E_C = $cost * .35;
}
elseif ($a_type ='full' && $extra='Y')
{
$E_C = $cost * .4;
}
else
{
$E_C = 0;
}
$T_cost = $cost + $E_C;
if ($BG = 'y')
{
$T_cost = $T_cost + 10;
}
You can't use mysqli and mysql at a same time.. Mysqli is a class... So first change that things...
while($row = mysqli_fetch_array($result))
{
echo $row['cost'];
}
$news1 = mysqli_result($result, 0); // 0 is the index of the field, not the row
echo $news1;
echo $cost;`
Query should be like this...
$all = "SELECT cost FROM C_price WHERE a_type='$a_type'and i_type='$i_type'";
You cant mix mysql and mysqli
change this line In the while loop and add for error mysqli_error
$news1 = mysql_result($result, 0);
$news1 = mysqli_result($result) or die(mysqli_error());
and your query is wrong as well and A_type is not same as A_type and same goes for I_type as well
$all = "SELECT cost FROM C_price WHERE a_type=$a_type,i_type=$i_type";
//Change it to
$all = "SELECT cost FROM C_price WHERE A_type='$a_type'and I_type='$i_type'";
//and A_type is not same as a_type and same goes for I_type as well
I got a problem with PDO...
I have this code:
<center>
<?php
/*
$payid = $_GET["payid"];
$data = mysql_connect('localhost','cheapacc_ross2','dsaikoepwq2312','cheapacc_account');
mysql_select_db('cheapacc_account',$data);
$pay1 = mysql_query("SELECT ID,Categorie,Naam,Email,md5_ID FROM acount_Betalingen WHERE md5_ID = '".$payid."' ");
$pay = mysql_fetch_object($pay1);
if($pay){
echo 'betaling is gelukt';
}else{
echo 'Oops jij liegt ons voor?? '.$pay->md5_ID .mysql_error();
}
*/
$flag=0;
require_once '../../include/config.php';
require_once '../../include/processes.php';
$Login_Process = new Login_Process;
$Login_Process->check_status($_SERVER['SCRIPT_NAME']);
$type = base64_decode($_GET["t"]);
$amount = (int)base64_decode($_GET["a"]);
$host = "localhost";
$username = "root";
$password = "20101998";
$dbname = "ross23";
try
{
$db = new PDO("mysql:host=" . $host . ";dbname=" . $dbname, $username, $password);
}
catch(PDOException $e)
{
exit("Error database connection. E: " . $e);
}
$info = $_SESSION['info'];
if(!isset($_GET["t"]) || !isset($_GET["a"]) || !isset($_GET["h"]) || sha1(md5($info)) != $_GET["h"])
{
exit("1: FOUT! / You may not change the url, or you get a ip ban!");
}
if(isset($_GET["t"]) && isset($_GET["a"]) && isset($_GET["h"]) && sha1(md5($info)) == $_GET["h"])
{
$q = $db->query("SELECT COUNT(*) FROM account_" . $type . " ");
$count = $q->fetchColumn();
if($count < $amount)
{
die("Er zijn te weinig accounts voor jouw betaling, meld dit aan de administrator!");
}
for($i = 0; $i < $amount; $i++)
{
$flag=0;
$getid = $db->prepare("SELECT id FROM account_".$type." WHERE used = ?");
$getid->execute( array('0') );
$pid = $getid->fetch();
if($pid[0] == null)
{
exit("Er zijn geen accounts over, meld dit aan de administrator!");
}
$id = $pid[0];
$stmt = $db->prepare("SELECT * FROM account_" . $type . " WHERE id = ? AND used = ?");
$stmt->execute( array($id, '0') );
$result = $stmt->fetch();
if(!$result)
{
exit("2: FOUT! / You may not change the url, or you get a ip ban.");
}
$userinfo = $db->prepare("SELECT userid FROM cw_users WHERE info = ?");
$userinfo->execute( array($info) );
$userinfo = $userinfo->fetch();
$sql = $db->prepare("INSERT INTO account_lijst SET user_id = ? WHERE account = ?");
$sql->execute(array($userinfo[0], $result));
$user_id = $_SESSION['userid'] ;
// query
$sql = "INSERT INTO account_lijst (user_id,soort) VALUES (:user_id,:soort)";
$q = $db->prepare($sql);
$q->execute(array(':author'=>$user_id,
':title'=>$type));
$account_info = explode(":", $result[1]);
$html = "Account Username: " . $account_info[0] . "<br />";
$html .= "Account Password : " . $account_info[1];
$html .= "<br /><br />";
$flag = 1;
if ($flag==1){
$sql = $db->prepare("UPDATE account_" . $type . " SET used = ? WHERE ID = ?");
$sql->execute( array("1", $id) );
echo $html;
}
echo 'test';
}
}
The most of the part works but by INSERT INTO account_lijst
It doesn't works...
But i checked everything but i think everything is fine:S...
Can someone help me with this code please?
*EDIT SQL
CREATE TABLE IF NOT EXISTS `account_lijst` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`account` text NOT NULL,
`date` text NOT NULL,
`soort` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
On your query :
$sql = $db->prepare("INSERT INTO account_lijst SET user_id = ? WHERE account = ?");
$sql->execute(array($userinfo[0], $result));
Try that instead :
$sql = $db->prepare("INSERT INTO account_lijst SET user_id = :user_id WHERE account = :account");
$sql->bindValue(':user_id', $userinfo['0']);
$sql->bindValue(':account', $result);
$sql->execute();
Should work perfectly if the parameters you gave are the good ones?
If you it doesn't can you please dump the parameters used into the query and the table's structure so we can debug deeper? :)
Check your code i guess (probably) there is an error near of this line due to the way you wrote the where clause:
$userinfo = $db->prepare("SELECT userid FROM cw_users WHERE info = ?");
Try this instead:
$userinfo = $db->prepare("SELECT userid FROM cw_users WHERE info = ' ? ' ");
As well in your insert you should use simple apostrophe in ordert o execute that insert:
$sql = $db->prepare("INSERT INTO account_lijst SET user_id = ? WHERE account = ?");
Hope it heps!!
Relating to a previous question i had
SQL not Updating from PHP form
I have changed and played with the code but am getting the following errors.
Query was emptyArray ( [imei] => 1 [serial] => 1 [status] => 1 [msisdn_no] => 0827910119
[card_no] => 89604900000001868482 [client_name] => 1 [inst_date] => 2013-09-10 [tech] => 1
[inst_cert] => 1 [isp] => Vodacom [account] => 1 [account_price] => 1 [deposit] => 1
[cont_start] => 1 [cont_end] => 1 [rica] => 1 [date_rica] => 1 [prod] => 1 [active] => 1
[suspended] => 1 [loaded_by] => 1 [send] => Submit ) : mysql err no : 1065 Your Number has
been registered and Location has been Captured. Please click here for your Map and
Location
This is my update PHP code
//Drawn from Form Information used to Update Database
$imei = $_POST['imei'];
$serial = $_POST['serial'];
$status = $_POST['status'];
$msisdn_no = $_POST['msisdn_no'];
$card_no = $_POST['card_no'];
$client_name = $_POST['client_name'];
$inst_date = $_POST['inst_date'];
$tech = $_POST['tech'];
$inst_cert = $_POST['inst_cert'];
$isp = $_POST['isp'];
$account = $_POST['account'];
$account_price = $_POST['account_price'];
$deposit = $_POST['deposit'];
$cont_start = $_POST['cont_start'];
$cont_end = $_POST['cont_end'];
$rica = $_POST['rica'];
$date_rica = $_POST['date_rica'];
$prod = $_POST['prod'];
$suspended = $_POST['suspended'];
$loaded_by = $_POST['loaded_by'];
$id =$_POST['id'] ;
//update database
update_lbs($msisdn, $reqby1, $reqdate, $reqtime, $client, $clientcase, $saps, $cas,
$reason, $reqby, $long, $lat, $msisdn, $dist, $response);
//update database
function update_lbs($imei, $serial, $status, $msisdn_no, $card_no, $client_name,
$inst_date, $tech, $inst_cert, $isp, $account, $account_price, $deposit, $cont_start,
$cont_end, $rica, $date_rica, $prod, $suspended, $loaded_by)
{ global $host;
global $username;
global $password;
global $db_name;
date_default_timezone_set('Africa/Johannesburg');
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d") ;
$time = date("H:i:s");
$insertSuccessful = false;
if ($con = mysql_connect($host, $username, $password)) {
if (mysql_select_db($db_name)) {
$query = "UPDATE tracking_sim SET
imei = '$imei',
serial = '$serial',
status = '$status',
msisdn_no = '$msisdn_no',
card_no = '$card_no',
client_name = '$client_name',
tech = '$tech',
inst_cert = '$inst_cert',
isp = '$isp',
account = '$account',
account_price = '$account_price',
deposit = '$deposit',
cont_start = '$cont_start',
cont_end = '$cont_end',
rica = '$rica',
date_rica = '$date_rica',
prod = '$prod',
date_rica = '$date_rica',
suspended = '$suspended',
loaded_by = '$loaded_by'
WHERE id = '$id';";
if (mysql_query($sql, $con)) {
$insertSuccessful = true;
} else {
echo mysql_error ();
echo $sql;
print_r($_POST);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
echo "mysql err no : " . mysql_errno($con);
}
return $insertSuccessful;
}
}
}
?>
My form has the following
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM tracking_sim WHERE id='$id'");
$rows = mysql_fetch_array($result);
?>
<form id="form1" method="post" action="../control_tracking/tracking_sim_updated.php">
I have tried the form action with both GET and POST same error also I have changed $_POST to $_REQUEST and tried it that way as well with no avail
you are use different sql variable,
$query and $sql,
"if (mysql_select_db($db_name)) {
**$query =** "UPDATE tracking_sim SET "
if (mysql_query(**$sql**, $con)) {
Try removing the semi-colon at the end of your update statement. The one after WHERE id='$id'.