PERFECT CODE IS NOT WORKING!

for OMITTEDing 2 hours im trying to solve this idiot shit mother OMITTEDing code which is 100% right but doesnt work

[php]
$sql = “INSERT INTO adfly_ads (uid,type,ad_title,ad_link,ad_uid,ad_price,ad_amount,ad_owner_id,date) VALUES (’$uid’,‘4’,’$ad_name’,’$ad_link’,’$ad_uid’,’$ad_price’,’$ad_amount’,’$owner’,’$date’)”;
$sql_money = “UPDATE user_accounts SET user_balance=’$balance_updated’ WHERE id=’$id’”;
mysqli_query($conn,$sql);
mysqli_query($conn,$sql_money);
mysqli_close($conn);
[/php]
$sql_money function always works and updates user_account but not $sql that little OMITTEDer just adds data when ever it wants i post some shit and it will only add that data to table only 1 or 2 times out of 10 but there is no error it doesnt show anything but that peace of shit doesnt work WHY WHY IT IS ALL RIGHT and if it is not right then why the OMITTED it is adding other data
and if i try post that same data that OMITTEDed added before it wont add it again

$sql = "INSERT INTO adfly_ads (uid,type,ad_title,ad_link,ad_uid,ad_price,ad_amount,ad_owner_id,date) VALUES ('$uid','4','$ad_name','$ad_link','$ad_uid','$ad_price','$ad_amount','$owner','$date')"; $sql_money = "UPDATE user_accounts SET user_balance='$balance_updated' WHERE id='$id'"; mysqli_query($conn,$sql); mysqli_query($conn,$sql_money); mysqli_close($conn);

Your code is putting the values directly into the sql query statement, where sql special characters in the data can break the sql query syntax produce a query error and you don’t have any error handling for the mysqli statements, so you won’t get any errors if any characters in the data or the numerical values (out of range) are causing an error.

You need to use a prepared query, with place-holders in the sql query statement, then supply the actual data values when you execute the query and you need to ALWAYS have error handling for database statements so that you will know when and why they are failing.

You should also not UPDATE a total in a column. This will result in duplicate submissions or lost/error submissions giving an incorrect total. You should instead store each amount as it’s own row, so that you will know all the who, what, when, where, and why information about the data, the same as what your bank or credit card does, then, any time you need the total, just run a query with a SUM() in it to get the result.

You would do better to spend the two hours learning basic debugging techniques such as turning on error reporting and reading the server error log. Php is more than happy to tell you exactly what is wrong if you ask it to.

Additionally, you never ever put variables in a query. You need to use Prepared statements, preferably using PDO. https://phpdelusions.net/pdo

i have 3 more codes like this and i use this same thing but it always works there really no idea why just this can’t, i see you are trying to suggest me better code, but i would like to understand why this is not working and how to fix it

and also i got error
Error: INSERT INTO adfly_ads (uid,type,ad_title,ad_link,ad_uid,ad_price,ad_amount,ad_owner_id,date) VALUES (‘59dfd5f3df356’,‘4’,‘123’,‘32’,‘JMF5QJB5Q’,‘1’,‘1’,‘16’,‘12.10.2017’)
Duplicate entry ‘1’ for key ‘PRIMARY’

i have set ad_price Primary, actually i dont even know what does PRIMARY do i only set it to primary because i figure out that if one column is set to primary then i can edit whole table from myphp admin

actually i dont even know what does PRIMARY

Then don’t do it. Use google and find out what that is for and then you will have learned something new today.

i tried but i didnt really understand what it does, i only undertood that i have to use it on UNIQUE values like id
now i made new table and everything is working but i got something interesting in my code
my code and predict future

$alph = “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
$ad_uid=’’;
$i=0;
while($i<9){
$position=rand(0,35);
$ad_uid=$ad_uid.substr($alph,$position,1);
$i++;
}
makes random numbers + letters
lets say i got http://localhost/adfly.php?ad=MABCNDQCH
in ad_link i put http://localhost/adfly.php?ad=MABCNDQCH but in ad_uid i take MABCNDQCH
in db it shows ad_link = http://localhost/adfly.php?ad=MABCNDQCH but ad_uid = HWM0EWEWQ
and this HWM0EWEWQ is not anywhere and next time i refesh page i see this HWM0EWEWQ
as my random

Perhaps you should start by telling us the problem you are trying to solve instead of your attempt at it. This is a classic XY Problem.

If you want something remotely secure don’t come up with your own concoction.

Instead use
[php]$bytes = random_bytes(5); // length in bytes
var_dump(bin2hex($bytes));
// output similar to: string(10) “385e33f741”[/php]

or use
[php]random_int(1,20);[/php]

why you are doing looks like utter nonsense in my opinion.

What the #$%* are you actually trying to do?

nothing, i fixed everything problem was in primary key

Sponsor our Newsletter | Privacy Policy | Terms of Service