[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
4Archive logo
Can any of you faggots code PHP/MySQL?
If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

You are currently reading a thread in /g/ - Technology

Thread replies: 15
Thread images: 1
File: potassium.gif (137 KB, 250x250) Image search: [iqdb] [SauceNao] [Google]
potassium.gif
137 KB, 250x250
I'm trying to make a simple like button. I've spent about 2 days non-stop on dealing with this cursed nigger code and I'm ready to fucking kill myself.

Like button:

> <input type="image" src="img/like.png" alt="Like" value="Like">
> <input type="hidden" name="IP" value="<?php $_SERVER ["REMOTE_ADDR"] ?>">

Gay PHP/MySQL:

> <?php
> if (!empty($_POST)) {
> $connection = mysqli_connect ("db_like");
> $statement = mysqli_prepare ($connection, "INSERT INTO Like (User, PageId) VALUES (?, > ?)");
> mysqli_stmt_bind_param ($statement, "si", $_POST["IP"], $_GET["id"]);
> mysqli_stmt_execute ($statement);
> exit;
> }
> ?>

It's here that I just want to display the amount of likes on the page with the corresponding like botton:

> $connection = mysqli_connect ("realhdgi_like");
> $statement = mysqli_prepare ($connection, "SELECT * FROM Like WHERE PageId=$_GET["id"];");

Which gives me this error:

>Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

WHAT THE FUCK DOES THAT MEAN? SPEAK ENGLISH YOU SATANIC MEXICAN

>NO HABLO PHP
>Stackoverflow keeps banning me for being stupid
>Help me or I'm sudoku
>>
I see where the error is, but first tell me, what do you want to create?
>>
>>52479837
A special video site where clicking the like button redirects the user to another random video. So does the dislike button, but I don't count the dislikes as they don't matter.
>>
>>52479891
In strings to access array elements you don't use $a["b"] but $a[b]. Yes, php is weird. That'sthe error.

Also, what are you doing? You are sending a hidden field with the IP addr that anyone can change. I could just spam your site with IP addresses.

Also there's SQL injection everywhere.

I would VERY STRONGLY advise you to forget about this code and use Laravel. PHP is a big mess with no design and it creates very messy code without a framework.
Read this tutorial: https://laravel.com/docs/5.1/quickstart
>>
>>52479891
>>52479943
No, seriously, do as I say. A site with SQL injection vulnerabilities will be quickly taken down by scripts and your (even if meaningless) data will be stolen.
>>
>>52479943
Fucking shit. Thanks.

How else would I prevent people from voting twice than with IPs?

Do you personally know a good resource for learning to prevent SQL injecting?
>>
>>52480006
Use. A. Framework. Such as Laravel.

The more correct answer would be to use a SQL library to prepare statements (which is in Laravel as well), but there's a lot more gotchas in PHP that a framework (such as Laravel) helps you with.
>>
>>52480006
Use pdo instead of mysql _connect
>>
>>52480056
Okay. I'll probably drink bleach before I figure out how to do this. My brain is ruined and now I have to learn Laravel. It's just a fucking like button, I thought it would be simple. Now 2 days of work is down the drain. I'm fucking stupid and coding is fucking stupid.
>>
>>52480006
Also you are having a logical error here. You are sending the IP addr to a client, then when the client clicks like you are retrivering his IP addres that you told him he has.. why? Just use $_SERVER['REMOTE_ADDRESS'] instead of $_POST['IP'] in the button handling.

>>52480149
It'll be easier from there.
>>
>>52480149
Not necessary to learn this. Just have a look at PDO and consider using a template system like smarty to avoid a messy php<>HTML mixed code.
>>
Use AJAX to autoupdate the counter with php.
>>
>>52480210
Not necessary, the user is redirected to another page upon click
>>
>>52480168
Doesn't surprise me It's a miracle anything managed to be correct in this abomination of a like button code.
>>
>>52480185
Do you really think that he is capable of that?
Thread replies: 15
Thread images: 1
Thread DB ID: 445159



[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.
If a post contains personal/copyrighted/illegal content, then use the post's [Report] link! If a post is not removed within 24h contact me at [email protected] with the post's information.