Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=Hammond;43116434]Hi again. I have a trigger, which activates a link, like
[url]http://localhost/crap/join.php?uid=1337&gold=1000&bank=2000[/url].
Basicly, all I want to do is to check, if there's already a row with uid=1337, and if yes, then just update the gold / bank info. If no, then insert the whole thing in. I've made something up, and yes, I know it's a mess, but I'm not exactly sure what's not working. Thanks :)
Code so far:
[code]
$selected = $_GET['uid'];
$gold = $_GET['gold'];
$bank = $_GET['bank'];
$rows = mysql_query("SELECT * FROM player_data", $connect);
$rows2 = mysql_query("SELECT * FROM player_data WHERE game_id=$selected", $connect);
$num_row = mysql_num_rows($rows);
$num_row2 = mysql_num_rows($rows2);
$id_row = $num_row + 1;
if($num_row2==0){
$order="INSERT INTO player_data (id,game_id,gold,bank) VALUES ('$id_row','$selected','$gold','$bank')";
}else{
$order2="UPDATE player_data SET gold=$gold+10, bank=$bank+10 WHERE game_id=$selected";
}
[/code]
So far it just duplicates itself on the trigger.[/QUOTE]
Oh god that is going to explode the next second you run it.
First, drop mysql_ and change to PDO or MYSQLi. You're doing something relating a currency, which makes it even more likely to find people trying to exploit it.
Second, you're grabbing the entire table on your first query. The moment it gets bigger, it's going to shit itself. Try selecting COUNT(*) if you need to know all the rows on a table.
Third, when you use PDO/MYSQLi, please change the variables on the query to prepared ones. (This should be obvious if you read any manual, but people still do that, sooo).
[QUOTE=Coment;43116561]Oh god that is going to explode the next second you run it.
First, drop mysql_ and change to PDO or MYSQLi. You're doing something relating a currency, which makes it even more likely to find people trying to exploit it.
Second, you're grabbing the entire table on your first query. The moment it gets bigger, it's going to shit itself. Try selecting COUNT(*) if you need to know all the rows on a table.
Third, when you use PDO/MYSQLi, please change the variables on the query to prepared ones. (This should be obvious if you read any manual, but people still do that, sooo).[/QUOTE]
For first, the whole process is done by a game server,which sends the code, the player just activates a trigger, so I don't think (but I'm sure that I'm mistaking though) that they can exploit it.
For the second, I see, makes sense, thank you :)
Third: I'm not entirely sure about the meaning of prepared variables. Do you mean like bank=$bank+10 etc? (For the record, I've bought a little PHP / Mysql introduction book a few years ago, and that's all my experience, not counting internet tutorials n shit.)
Thank you, I'll try to do it with your method!
[QUOTE=Coment;43116561]Oh god that is going to explode the next second you run it.
First, drop mysql_ and change to PDO or MYSQLi. You're doing something relating a currency, which makes it even more likely to find people trying to exploit it.
Second, you're grabbing the entire table on your first query. The moment it gets bigger, it's going to shit itself. Try selecting COUNT(*) if you need to know all the rows on a table.
Third, when you use PDO/MYSQLi, please change the variables on the query to prepared ones. (This should be obvious if you read any manual, but people still do that, sooo).[/QUOTE]
I know exactly what tutorial they got
$order="INSERT INTO player_data (id,game_id,gold,bank) VALUES ('$id_row','$selected','$gold','$bank')";
from. That tutorial has made so many sites exploitable...
It LOOKS like a prepared statement but it simply isn't.
also
[QUOTE=Hammond;43116715]For first, the whole process is done by a game server,which sends the code, the player just activates a trigger, so I don't think (but I'm sure that I'm mistaking though) that they can exploit it.[/QUOTE]
if you are using GET then it's extremely easy to just send data to your URL too.
[QUOTE=01271;43116881]if you are using GET then it's extremely easy to just send data to your URL too.[/QUOTE]
The game has a trigger, which looks like [url](send_player_url:file.php?smt=1)[/url], thus activating it. I don't know if there's a way to post it, because I'm only doing the php part of the thing, but it also requires a password (big deal.).
[QUOTE=Hammond;43116715](For the record, I've bought a little PHP / Mysql introduction book a few years ago, and that's all my experience, not counting internet tutorials n shit.)
Thank you, I'll try to do it with your method![/QUOTE]
This be kept in logs too: I meant manuals about PDO/mysqli, but Facepunch's editor was screwing up and not letting me edit. (Without that explanation, it looks even a bit rude.)
What would be the best way of storing tags for something like an image?
[QUOTE=mac338;43115889]I haven't found a jquery stickypost feature, only a jquery sticky element feature. And I don't know Java.[/QUOTE]
most javascript coders don't know java btw
[QUOTE=gokiyono;43121423]What would be the best way of storing tags for something like an image?[/QUOTE]
It depends on how you intend to use them. If you want to be able to select a tag and have all the images with that tag appear then a separate tags table in your database (id, image_id, tagname). This would be the cleanest way, easily allowing the addition and removal of tags.
If however you want the tags to be searchable in a way that does not just search for TagA or TagB but prioritises having both TagA and TagB then what I would do would be to make it so that every time the tags are modified a combined string of them ('TagA TagB') are put into a Text field in the images table allowing you to perform a 'full-text search' on it.
[QUOTE=CBastard;43121543]It depends on how you intend to use them. If you want to be able to select a tag and have all the images with that tag appear then a separate tags table in your database (id, image_id, tagname). This would be the cleanest way, easily allowing the addition and removal of tags.
If however you want the tags to be searchable in a way that does not just search for TagA or TagB but prioritises having both TagA and TagB then what I would do would be to make it so that every time the tags are modified a combined string of them ('TagA TagB') are put into a Text field in the images table allowing you to perform a 'full-text search' on it.[/QUOTE]
Thank you.
I forgot to ask, what would the best way to get them from an input be
[QUOTE=gokiyono;43121832]Thank you.
I forgot to ask, what would the best way to get them from an input be[/QUOTE]
I would probably go for a single input then separate the tags based on spaces and/or commas.
[code]
<?php
if(is_numeric($_GET['id'])){
$image_id = $_GET['id'];
}else{
// Invalid ID send them back
header('Location: /');
exit;
}
if(isset($_POST['tags'])){
// Remove all currently associated tags
// Pseudocode DB class
$db->prep('DELETE FROM tags WHERE image_id = :image_id');
$db->bind('image_id', $image_id);
$db->execute();
if(!empty($_POST['tags'])){
$str = $_POST['tags'];
$result = preg_replace('/[^a-z0-9åäö\s]/ui', '', $str); // make everything comma separated
$tags = preg_split('/\s+/', $result, 6); // Split into an array
$db->prep('INSERT INTO tags (image_id, tagname) VALUES(:image_id, :tagname)');
// Insert each tag
foreach($tags as $tag){
$db->bind('image_id', $image_id);
$db->bind('tagname', $tag);
$db->execute();
}
// combined string for fulltext searching
$db->prep('UPDATE images SET tags = :tags WHERE id = :id');
// Assuming here that the tags are being added after the image itself has already been submitted,
// Insert if that's not the case.
$db->bind('id', $image_id);
$db->bind('tags', implode(', ', $tags));
$db->execute();
}
}
// Display the form
// Pseudocode DB class
$db->prep('SELECT FROM tags WHERE image_id = :image_id');
$db->bind('image_id', $image_id);
$db->execute();
$current_tags = '';
if($current_tags_array = $db->get_array()){
$current_tags = implode(', ', $current_tags_array);
}
?>
<form method="post">
<label for="tags">Tags:</label>
<input type="text" name="tags" value="<?php echo $current_tags ?>">
<input type="submit" value="Submit">
</form>
[/code]
In addition to this to make it more user friendly, I'd implement something like this: [URL="http://aehlke.github.io/tag-it/"]http://aehlke.github.io/tag-it/[/URL]
[QUOTE=CBastard;43121968]I would probably go for a single input then separate the tags based on spaces and/or commas.
[code]
code('PHP');
[/code]
In addition to this to make it more user friendly, I'd implement something like this: [URL="http://aehlke.github.io/tag-it/"]http://aehlke.github.io/tag-it/[/URL][/QUOTE]
I actually wanted to go with comma separated tags for the user input, but I wasn't sure weather or not it was good practice.
Comma separated tags it is, and tag-it looks really nice, thanks a lot.
Would someone who has at least minor PHP or jQuery abilities like to buddy with me to help me build/improve this website?
I like to communicate on IRC, Skype and Steam ofc.
[URL]http://almost-there.org[/URL]
[URL]https://github.com/Almost-There/almostThere[/URL]
I'm really lonely.
(We should have a buddy thread on the board)
[B]Edit:[/B]
I made one! [URL]http://facepunch.com/showthread.php?t=1332201[/URL]
Guys, I need some help making this thing responsive...
I am currently making a very basic loadingurl for my servers, and since I'm a complete beginner in HTML & CSS I have no clue how to position things so I decided to just get this crappy (or so I've heard) Google Web Designer program since it's so easy to position my images and text.
Anyways, basically the entire loadingurl is a 1920x1080 image where I place some text & images onto using PHP and javascript.
The issue is that I don't know how to make it resposive so that people who play on diffrent resolutions don't get a cut-off or too small page.
This is pretty much the code that GWD gave me:
[CODE]
<!DOCTYPE html>
<html>
<head data-gwd-animation-mode="proMode">
<title>undefined</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="Google Web Designer 1.0.1.1025">
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0px;
}
body {
background-color: transparent;
-webkit-transform: perspective(1400px) matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
-webkit-transform-style: preserve-3d;
}
.gwd-img-ev3l {
position: absolute;
width: 1920px;
height: 1080px;
left: -15px;
top: 0px;
}
.gwd-img-u6jw {
position: absolute;
width: 64px;
height: 64px;
left: 933px;
top: 709px;
-webkit-transform-origin: -99.3888888889px 27.8055555556px 0px;
-webkit-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
}
.gwd-div-p8gb {
position: absolute;
width: 282.1180555556px;
height: 43.8046553498px;
text-align: center;
font-family:'Arial Black';
color: rgb(6, 147, 150);
left: 825.6421750503446px;
top: 651.6143290544333px;
}
.gwd-span-6av4 {
font-size: 25px;
}
.gwd-div-1t5v {
position: absolute;
width: 318.75px;
height: 104.1666666667px;
left: 812px;
top: 786px;
text-align: left;
font-family:'Arial Black';
color: rgb(249, 0, 0);
}
.gwd-div-hbmj {
text-align: center;
}
.gwd-div-0b6d {
text-align: center;
}
.gwd-span-u1ph {
font-size: 12px;
color: rgb(255, 255, 255);
}
.gwd-div-61pv {
text-align: center;
}
.gwd-span-ugy2 {
font-size: 12px;
color: rgb(255, 255, 255);
}
.gwd-div-325q {
text-align: center;
}
.gwd-span-p11u {
font-size: 12px;
color: rgb(255, 255, 255);
}
.gwd-div-7wlo {
position: absolute;
width: 286.8055555556px;
height: 33.3333333333px;
font-family:'Times New Roman';
color: rgb(0, 0, 0);
text-align: center;
left: 826.6413085559477px;
top: 904.1734006733934px;
}
.gwd-span-cmk0 {
color: rgb(255, 255, 255);
font-family:'Arial Black';
}
.gwd-span-4nv2 {
color: rgb(255, 255, 255);
font-family:'Arial Black';
}
.gwd-div-zfhd {
position: absolute;
width: 1118.4000000447px;
height: 75.600000003px;
text-align: center;
font-family:'Arial Black';
color: rgb(255, 255, 255);
font-size: 30px;
left: 413.7699463326943px;
top: 970.4526315916997px;
}
.gwd-span-afiy {
font-size: 25px;
}
</style>
</head>
<script type="text/javascript">
function DownloadingFile(fileName) {
document.getElementsByClassName("gwd-span-afiy")[0].innerHTML=fileName;
}
function SetFilesNeeded (needed) {
document.getElementsByClassName("gwd-span-4nv2")[1].innerHTML=needed;
}
</script>
<body>
<img src="images/background_new.jpg" class="gwd-img-ev3l">
<div class="gwd-div-1t5v">
<div class="gwd-div-hbmj"></div>
<div class="gwd-div-0b6d"><span class="gwd-span-u1ph">SteamID: <? echo $steamid; ?></span>
</div>
<div class="gwd-div-61pv"><span class="gwd-span-ugy2">Current Pointshop Points: <? echo $points; ?></span>
</div>
<div class="gwd-div-325q"><span class="gwd-span-p11u">Rank: User</span>
</div>
</div>
<? echo '<img src="'.$avatar.'" class="gwd-img-u6jw">'; ?>
<div class="gwd-div-7wlo editable"><span class="gwd-span-4nv2">Total files to download: </span><span class="gwd-span-4nv2">40</span>
</div>
<div class="gwd-div-p8gb"><span class="gwd-span-6av4"><? echo $playername; ?></span>
<br>
</div>
<div class="gwd-div-zfhd"><span class="gwd-span-afiy">materials/models/player/custom/hud/body.vmt</span>
</div>
</body>
</html>
[/CODE]
I use PHP to output the content that I get from Steam's API.
Anyone have a tip or trick on how to make this responsive?
Here's the live preview with my own community ID: [url]http://tjservers.org/loadingurl/tttmc/index.php?communityid=76561197988494194[/url]
To make it responsive you need to have media queries in your CSS. (I would show you but i'm on phone, sorry!)
Take a look at bootstrap and foundation's css to understand what i mean (or go through their docs and implement one of them to your actual loadingurl).
Sorry I can't be more help, like I said i'm posting from phone.
Add is green
Remove is red
What is the colour of edit?
[QUOTE=gokiyono;43144290]Add is green
Remove is red
What is the colour of edit?[/QUOTE]
Yellow?
Hello dudes and dudettes!
I'm very inexperienced and don't really know much of the general terminology, so trying to search for it myself yielded me zero results. I'd like to know how I would go on about having some input fields assigned to certain html and css values, like i.e type in 100 in to the an input field and it sets like [B]x[/B]px to 100px? I only really need some basic directions for where to look and what to search for, I'm sure I'll be able to sort it out from there. Thank you in advance!
[QUOTE=gokiyono;43144290]Add is green
Remove is red
What is the colour of edit?[/QUOTE]
I think blue is a neutral colour, so blue maybe?
Hi again.
[PHP] I wish to count, get the type, and then display every column in a table.
It'd look like:
[url]www.hamstudio.weboldala.net/lister/Files/tt.png[/url]
So far I have problems with both methods.
The first might be pretty simple, but I've still have no idea. If I have a request happening, how can I insert something in between, which will not duplicate every time the query is done?
For example:
[code]
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo "<td colspan='3'><b>".mysql_field_name($result, $i)."</b></td>";
/* Insert it between the two things only once */echo "</tr><tr>";
echo "
<td><small>max_length:</small> $meta->max_length</td>
<td><small>name:</small> $meta->name</td>
<td><small>type:</small> $meta->type</td>";
}
[/code]
The other one is supposed to be working, but gives me an error code, which after googling it, still couldn't manage to solve it.
It's pretty much the same thing, just in a worse way, since I put the same code in again.[code]
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo "<td align='center' colspan='3'><b>".mysql_field_name($result, $i)."</b></td>";
}
/* Works so far */
echo "</tr><tr>";
$meta = mysql_fetch_field($result, $i); #If I put a number in the place of $i, it works, but otherwise it gives me an error code.
for ($i = 0; $i < mysql_num_fields($result); $i++){ #I also tried placing in an other variable, like $e, no change.
echo "
<td><small>max_length:</small> ".$meta->max_length."</td>
<td><small>name:</small> ".$meta->name."</td>
<td><small>type:</small> ".$meta->type."</td>";
}[/code]
The error codes:
[i]Warning: mysql_fetch_field() [function.mysql-fetch-field]: Bad field offset in ...
Notice: Trying to get property of non-object in...[/i]
@Hammond
Here are a few things to help with your code which should make it easy to implement what you want.
The 'mysql' functions are depreciated use mysqli or PDO instead.
[code]
<?php
for ($i = 0; $i < mysql_num_fields($result); $i++){
[/code]
This is a bad way to do this, it means that you are calling mysql_num_fields every single time it loops to get a value that wont change. It's more efficient to do this:
[code]
<?php
$count = mysql_num_fields($result);
for ($i = 0; $i < $count; $i++){
[/code]
Although far better is to iterate over a results array.
[code]
<?php
// mysql_ functions shouldn't be used but I've left them here since you are already using them
$resource = mysql_query("SELECT name, date, banana FROM mytable");
$results = mysql_fetch_assoc($resource);
foreach($results as $result){
}
[/code]
Also if you're writing HTML with a for/while/if/switch/foreach etc you can use this which gives you cleaner source:
[code]
<?php foreach($results as $result): ?>
<td><?php echo $result['name'] ?></td>
<td><?php echo $result['date'] ?></td>
<td><?php echo $result['banana'] ?></td>
<?php endforeach; ?>
[/code]
I want to break up a blog post using headers. Is this the correct HTML5 way to do that?
[code]
<article>
<section>
<h1>First Section</h1>
...
</section>
<section>
<h1>Second Section</h1>
...
</section>
<section>
<h1>And so on...</h1>
...
</section>
...
</article>
[/code]
[QUOTE=Larikang;43147377]I want to break up a blog post using headers. Is this the correct HTML5 way to do that?
[code]
<article>
<section>
<h1>First Section</h1>
...
</section>
<section>
<h1>Second Section</h1>
...
</section>
<section>
<h1>And so on...</h1>
...
</section>
...
</article>
[/code][/QUOTE]
According to this website, it's the other way around.
[url]http://coding.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/[/url]
[QUOTE=Larikang;43147377]I want to break up a blog post using headers. Is this the correct HTML5 way to do that?
[code]
<article>
<section>
<h1>First Section</h1>
...
</section>
<section>
<h1>Second Section</h1>
...
</section>
<section>
<h1>And so on...</h1>
...
</section>
...
</article>
[/code][/QUOTE]
I would say h2 or h3 instead.
It's like in golf, the lower the number the higher the rank, so h1 is numero uno of the headers, and I think there should only be one of them.
[QUOTE=gokiyono;43148063]I would say h2 or h3 instead.
It's like in golf, the lower the number the higher the rank, so h1 is numero uno of the headers, and I think there should only be one of them.[/QUOTE]
I should have checked the standard first! [url]http://www.w3.org/html/wg/drafts/html/master/sections.html#headings-and-sections[/url]
The last code example says it's okay (and even has some advantages).
[QUOTE=Jelly;43144423]Yellow?[/QUOTE]
[QUOTE=BeatAlex;43145348]I think blue is a neutral colour, so blue maybe?[/QUOTE]
:v:
[QUOTE=gokiyono;43148219]:v:[/QUOTE]
I think it should be green as well. Since you're adding information. (Even if you are effectively removing some.) But it depends on context I would say. If you edit something that shouldn't be edited on a whim (like let's say a slug for an article) then it should be orange.
What are your views on using frameworks like Foundation or Bootstrap to do your responsive design for you?
Obviously in terms of design, you can edit it heavily so you get your own theme you want, but I've been using Foundation a lot to do some responsive work for me and wasn't sure if it was better to write my own media query rules or let a framework such as Foundation/Bootstrap do it for me.
Are there any really good tutorials on PDO for PHP SQL stuff?
Im finding it really hard to get my head around. Could somone point me to a tutorial that even a dumb ass 5 year old could understand?
Thanks!
[QUOTE=BeatAlex;43151256]What are your views on using frameworks like Foundation or Bootstrap to do your responsive design for you?
Obviously in terms of design, you can edit it heavily so you get your own theme you want, but I've been using Foundation a lot to do some responsive work for me and wasn't sure if it was better to write my own media query rules or let a framework such as Foundation/Bootstrap do it for me.[/QUOTE]
You're eventually going to end up writing your own when you use those frameworks anyways unless your site is incredibly simple. Let them do what they can for you, but you should [B]absolutely[/B] be checking over everything and making your own breakpoints/adjustments as needed as well.
So, I don't know if this really counts as a question (or set of questions) for this thread, but I've wanted to ask a few questions about databases:
- Is there any difference between Postgres and MySQL, in relation to internals (as in, is there any benefit other than standards compliance?)
- Why shouldn't you use MongoDB with relations between documents? Is this because of MongoDB itself, or the document model in general?
- The usual example for graph databases are social networks. What other kinds of applications could graph databases be used for, and where would they be better than relational databases?
Sorry, you need to Log In to post a reply to this thread.