[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 / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Can any of you faggots code PHP/MySQL?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

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

Thread replies: 15
Thread images: 1
File: potassium.gif (137 KB, 250x250) Image search: [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

banner
banner
[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 / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.