Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=Poo Monst3r;40259540]sorry. its not easy to post tidy code on facepunch. fixed it now though[/QUOTE]
Your indent style is tearing this family apart.
Tidied up a bit more.
[PHP]
<?php
if($_GET['a'] == '1'){
/* Add Work */
if(isset($_POST['clientName']) && !empty($_POST['clientName'])){
if(countRows('clients', 'clientID', $_POST['clientName']) > 0){
$cid = $_POST['clientName'];
}else{
$error[6] = "The client selected does not appear to exist within the database";
}
}else{
$error[0] = "Please select the client for which this work is to be added to";
}
if(isset($_POST['title']) && $_POST['title'] != "Film Title"){
$title = strip_tags($_POST['title']);
}else{
$error[1] = "Film title is required";
}
if(isset($_POST['genre']) && $_POST['genre'] != "Genre"){
$genre = strip_tags($_POST['genre']);
}else{
$error[2] = "Film genre is required";
}
if(isset($_POST['runtime']) && $_POST['runtime'] != "Runtime"){
$runtime = $_POST['runtime'];
}else{
$error[3] = "Film runtime is required";
}
if(isset($_POST['desc']) && $_POST['desc'] != "Description (1500 Characters Max)"){
$desc = strip_tags($_POST['desc']);
}else{
$error[4] = "Film description is required";
}
if(isset($_POST['preview']) && $_POST['preview'] != "Link to Preview"){
$preview = strip_tags($_POST['preview']);
}else{
$error[5] = "Film preview is required";
}
/* After everything has been checked and validated */
if(isset($cid) && isset($title) && isset($genre) && isset($runtime) && isset($desc) && isset($preview)){
$workSQL = $db->prepare("INSERT INTO portfolio (clientID, title, genre, runtime, preview, description) VALUES (:clientID, :title, :genre, :runtime, :preview, :description)");
$workSQL->bindParam(':clientID', $cid, PDO::PARAM_INT, 5);
$workSQL->bindParam(':title', $title, PDO::PARAM_STR, 50);
$workSQL->bindParam(':genre', $genre, PDO::PARAM_STR);
$workSQL->bindParam(':runtime', $runtime, PDO::PARAM_STR, 25);
$workSQL->bindParam(':preview', $preview, PDO::PARAM_STR, 100);
$workSQL->bindParam(':description', $desc, PDO::PARAM_STR, 1500);
if($workSQL->execute()){
echo "Successfully submitted this film to the portfolio!";
}else{
echo "There was an error submitting this film to the portfolio, please try again";
}
}else{
if(isset($error)){
foreach($error as $printed){
echo $printed . "<br />";
}
?>
<!---------------- STICKY FORM --------------------->
<form name="addClient" method="POST" action="addWork.php?a=1">
<select id="clientName" name="clientName">
<option value ="">Select Client</option>
<?php
$clientsSQL = $db->prepare("SELECT * FROM clients");
$clientsSQL->execute();
foreach($clientsSQL as $client){
if(isset($_POST['clientName'])){
if($_POST['clientName'] == $client['clientID']){
echo "<option value=".$client['clientID']." selected>".stripslashes($client['name'])."</option>";
}else{
echo "<option value=".$client['clientID'].">".stripslashes($client['name'])."</option>";
}
}
}
?>
</select>
<div id="info">
<input type="text" name="title" id="title" value="<?php echo (isset($_POST['title']))? $_POST['title'] : "Film Title"; ?>" size="50"
onfocus="if (this.value=='Film Title') { this.value=''; this.style.color='#000'; }"
onblur="if (this.value=='Film Title' || this.value=='') { this.style.color='#9E9898'; this.value='Film Title'}" />
<br />
<input type="text" name="genre" id="genre" value="<?php echo (isset($_POST['genre']))? $_POST['genre'] : "Genre"; ?>" size="20"
onfocus="if (this.value=='Genre') { this.value=''; this.style.color='#000'; }"
onblur="if (this.value=='Genre' || this.value=='') { this.style.color='#9E9898'; this.value='Genre'}" />
<input type="text" name="runtime" id="runtime" value="<?php echo (isset($_POST['runtime']))? $_POST['runtime'] : "Runtime"; ?>" size="10"
onfocus="if (this.value=='Runtime') { this.value=''; this.style.color='#000'; }"
onblur="if (this.value=='Runtime' || this.value=='') { this.style.color='#9E9898'; this.value='Runtime'}" />
</div> <!-- /info -->
<span class="countdown"></span>
<textarea name="desc" id="desc" rows="10" class="desc" cols="70"
onfocus="if (this.value=='Description (1500 Characters Max)') { this.value=''; this.style.color='#000'; }"
onblur="if (this.value=='Description (1500 Characters Max)' || this.value=='') { this.style.color='#9E9898'; this.value='Description (1500 Characters Max)'}">
<?php echo (isset($_POST['desc']))? $_POST['desc'] : "Description (1500 Characters Max)"; ?>
</textarea>
<input type="text" name="preview" id="preview" value="<?php echo (isset($_POST['preview']))? $_POST['preview'] : "Link to Preview"; ?>" size="50"
onfocus="if (this.value=='Link to Preview') { this.value=''; this.style.color='#000'; }"
onblur="if (this.value=='Link to Preview' || this.value=='') { this.style.color='#9E9898'; this.value='Link to Preview'}" />
<input type="submit" id="submit" value="Add to Portfolio" />
</form>
<?php
}
}
}
?>
[/PHP]
[QUOTE=CBastard;40259726]Your indent style is tearing this family apart.
Tidied up a bit more.
[/QUOTE]
Thank you sir.
Anyone have any ideas why this code would cause a 403 when all the values are correct? And also cause the clientName query to not even run if the sticky form needs to be loaded?
This is some weird shit man.
[editline]12th April 2013[/editline]
Something that might help...
I tried changing the preview link in my form from a youtube video link to just "google.ca" and it inserted the query correctly. So, I thought maybe the strip_tags() was fucking with the URL somehow and removed it, but that did nothing. This code is actually fucked - that, or my server is totally fucked which wouldn't make sense since its professionally hosted. I'm definitely the most confused I've ever been.
one problem I had with developing something and then uploading it was that the online one had a earlier version of PHP.. Didn't bother to read yours though, but it might help :v:
I want to create a navigation system similar to this website: [URL]http://www.sancarlo.co.uk/[/URL]
When the mouse hovers a menu item, the background color and text color changes. I have tried doing this but I can only get the text color to change. This is the html I have for my navigation system
[code]
<div id = "navigationbox">
<div class = "navigation">
Home
</div>
<div class = "navigation">
<a href = "menus.htm">Menus</a>
</div>
<div class = "navigation">
<a href = "gallery.htm">Gallery</a>
</div>
<div class = "navigation">
<a href = "reviews.htm">Reviews</a>
</div>
<div class = "navigation">
<a href = "contact.htm">Contact us</a>
</div>
</div>
[/code]
All I need is for the background color and text color of "navigation" to change when the menu item is hovered over, like the website I linked to. I'd rather do this with just CSS. I tried .navigation:hover and giving the changed properties however the text color does not change because it is contained within the <a> tag
-snip-
(I only know the solution for the text if you use ul & li)
put it on jsfiddle
[img] http://filesmelt.com/dl/ScreenCap_2013-04-12_a_13.09_.31_1.png[/img]
How do I fix this.
I'm trying to make them go onto rows instead of being in big blocks.
[code]
<div id="preferenceList">
<li>
<div id="item_row">
<div class="imageColumn">
<img width="50" height="50" title="Kritzkrieg" alt="Kritzkrieg" src="http://media.steampowered.com/apps/440/icons/c_overhealer.b5ed539b534216652b45694e19c78d2aaebcfe5e.png">
</div> <!--imageColumn-->
<div="35">
<div id="35">
<div id="all">
<br>All:
<input type="radio" onchange="selectAll('35_nochange');" name="all_35">
<input type="radio" onchange="selectAll('35_off');" name="all_35">
<input type="radio" onchange="selectAll('35_on');" name="all_35">
</div>
<div class="normal"> </div>
<div class="genuine"> </div>
<div class="vintage">
N<input type="radio" class="35_nochange" name="35[3]">
H<input type="radio" class="35_off" name="35[3]">
S<input type="radio" class="35_on" name="35[3]">
</div>
<div class="unusual"> </div>
<div class="unique">
N<input type="radio" class="35_nochange" name="35[6]">
H<input type="radio" class="35_off" name="35[6]">
S<input type="radio" class="35_on" name="35[6]">
</div>
<div class="strange">
N<input type="radio" class="35_nochange" name="35[11]">
H<input type="radio" class="35_off" name="35[11]">
S<input type="radio" class="35_on" name="35[11]">
</div>
<div class="uncraftable">
N<input type="radio" class="35_nochange" name="35[600]">
H<input type="radio" class="35_off" name="35[600]">
S<input type="radio" class="35_on" name="35[600]">
</div>
</div>
</div="35">
</div>
</li><br>
[/code]
and the relevant CSS
[code]
#preferenceList li
{
display: inline-block;
}
#item_row div
{
width: 100px;
float: left;
}[/code]
[QUOTE=01271;40268890][img] http://filesmelt.com/dl/ScreenCap_2013-04-12_a_13.09_.31_1.png[/img][/QUOTE]
are you sure its not other way around? or is the image cut off.
[editline]13th April 2013[/editline]
remake in jsfiddle pls. also look in to [css]display:inline-block;[/css]
[editline]13th April 2013[/editline]
We need to make it a rule to use jsfiddle.
[url]http://jsfiddle.net/rsYsV/4/[/url]
I already have inline-block. At that that does is make my lines not mess up and go side by side.
Where are you learning this from?
[html]<div="35">
</div="35">[/html]
the indentation is so confusing on jsfiddle
relearn html.
[editline]13th April 2013[/editline]
[url]http://en.wikipedia.org/wiki/Indent_style[/url]
also, random </form> tag?
[QUOTE=01271;40269673][url]http://jsfiddle.net/rsYsV/4/[/url]
I already have inline-block. At that that does is make my lines not mess up and go side by side.[/QUOTE]
Was it this you wanted?
[IMG]http://i.imgur.com/WdVd0or.png[/IMG]
[QUOTE=01271;40269673][url]http://jsfiddle.net/rsYsV/4/[/url]
I already have inline-block. At that that does is make my lines not mess up and go side by side.[/QUOTE]
You are setting #item_row div to 100px, everything inside is being limited to that width so they are appearing on multiple lines.
Edit: It's pretty hard to see what you want to achieve.
[QUOTE=CBastard;40269932]You are setting #item_row div to 100px, everything inside is being limited to that width so they are appearing on multiple lines.[/QUOTE]
Plus he counts on browser default sizes and fonts.
[QUOTE=djjkxbox360;40266844]I want to create a navigation system similar to this website: [URL]http://www.sancarlo.co.uk/[/URL]
When the mouse hovers a menu item, the background color and text color changes. I have tried doing this but I can only get the text color to change. This is the html I have for my navigation system
[code]
<div id = "navigationbox">
<div class = "navigation">
Home
</div>
<div class = "navigation">
<a href = "menus.htm">Menus</a>
</div>
<div class = "navigation">
<a href = "gallery.htm">Gallery</a>
</div>
<div class = "navigation">
<a href = "reviews.htm">Reviews</a>
</div>
<div class = "navigation">
<a href = "contact.htm">Contact us</a>
</div>
</div>
[/code]
All I need is for the background color and text color of "navigation" to change when the menu item is hovered over, like the website I linked to. I'd rather do this with just CSS. I tried .navigation:hover and giving the changed properties however the text color does not change because it is contained within the <a> tag[/QUOTE]
Instead of '.navigation:hover' use '.navigation a:hover'.
This applies it to all the <a> tags that have a parent that have the class 'navigation'.
[url]http://www.w3.org/TR/CSS2/selector.html[/url] is an interesting read if you want to learn about more of these tricks.
[QUOTE=CBastard;40269932]You are setting #item_row div to 100px, everything inside is being limited to that width so they are appearing on multiple lines.
Edit: It's pretty hard to see what you want to achieve.[/QUOTE]
Oh there we go,
#item_row div div
Makes it work.
That was surprisingly easy.
[QUOTE=jung3o;40269800]Where are you learning this from?
[html]<div="35">
</div="35">[/html]
the indentation is so confusing on jsfiddle
relearn html.
[editline]13th April 2013[/editline]
[url]http://en.wikipedia.org/wiki/Indent_style[/url]
also, random </form> tag?[/QUOTE]
[QUOTE=gokiyono;40269978]Plus he counts on browser default sizes and fonts.[/QUOTE]
I just copied my code directly from firebug and added a tiny bit of indentation to make it readable.
Making readable HTML via PHP never crossed my mind before, didn't learn to do that yet.
Also the random form tag is because I've only cut out relevant parts of my code which I know is frowned upon but I don't want to show too much of my site yet because I'm keeping it somewhat secret atm and my mistakes are already driving my "tutor" crazy.
The <div id="35"></div="35">is a bug in my PHP code that I didn't notice before.
This is a part of my first serious website and I learned so much from making it so far, a lot of my site's parts are me doing that kind of thing for the first time.
I'm not very familiar with the htaccess redirects and stuff. It's more of a one time learning thing and then I forget when I'm done with whatever I'm done with.
I need help shrinking this
[html]<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index/?$ index.php [L]
RewriteRule ^create/?$ create.php [L]
RewriteRule ^create_link/?$ create_link.php [L]
RewriteRule ^tutorial/?$ tutorial.php [L]
RewriteRule ^contact/?$ contact.php [L]
RewriteRule ^i/?$ get.php [L]
RewriteRule ^i/(.*)$ get.php?i=$1 [L,NC]
RewriteRule ^index\.(php|html?)$ http://jung3o.com/dynamiclibs/ [R=301,L]
</IfModule>
[/html]
Whatever I do, it gives me server error because there are too much loops on the get.php
one of the reason might be because of
[php]if(empty($_GET['i']))
{
if(substr($_SERVER['REQUEST_URI'],-1) == "/") header('location: ../index');
else header('location: ./');
}[/php]
The last rewrite rule matches the following:
[code]
i/
i/something
i/other/thing
[/code]
i'm not sure if that effects anything, though
[QUOTE=Ac!dL3ak;40306963]The last rewrite rule matches the following:
[code]
i/
i/something
i/other/thing
[/code]
i'm not sure if that effects anything, though[/QUOTE]
oops, i fixed it [code]([0-9]+)[/code]
So I started a new project in RoR and decided this time to use TDD as much as I can to get a feeling of it since everyone that uses it says it's great.
These are a few of my tests right now, but having more than one 'expect' feels weird to me, so I was wondering if they are valid ways to test.
[code] specify "should have a name between 2 and 12 characters" do
user.name = "B"
expect(user.valid?).to eq(false)
user.name = "ThisHasExactl"
expect(user.valid?).to eq(false)
user.name = "Bobby"
expect(user.valid?).to eq(true)
end
specify "should have a valid email" do
user.email = ""
expect(user.valid?).to eq(false)
user.email = "wwas"
expect(user.valid?).to eq(false)
user.email = "example@example.com"
expect(user.valid?).to eq(true)
end
[/code]
Baffled as to why my jQuery plugin won't load. I'm pretty sure the script initialises it properly, but it just won't do anything on the page. Indenting doesn't look THAT bad on my editor, either. Sorry!
[CODE]<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.timelinr-0.9.53.js"></script>
<script>
$(function(){
$().timelinr({
orientation: 'vertical',
issuesSpeed: 300,
datesSpeed: 100,
arrowKeys: 'true',
startAt: 3
})
});[/CODE]
HTML:
[CODE] <div id="timeline">
<ul id="dates">
<li><a href="#">date1</a></li>
<li><a href="#">date2</a></li>
</ul>
<ul id="issues">
<li id="date1">
<p>Lorem ipsum.</p>
</li>
<li id="date2">
<p>Lorem ipsum.</p>
</li>
</ul>
<a href="#" id="next">+</a> <!-- optional -->
<a href="#" id="prev">-</a> <!-- optional -->
</div>[/CODE]
}); instead of }) maybe?
[QUOTE=Slater;40313396]Baffled as to why my jQuery plugin won't load. I'm pretty sure the script initialises it properly, but it just won't do anything on the page. Indenting doesn't look THAT bad on my editor, either. Sorry!
[CODE]<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/jquery.timelinr-0.9.53.js"></script>
<script>
$(function(){
$().timelinr({
orientation: 'vertical',
issuesSpeed: 300,
datesSpeed: 100,
arrowKeys: 'true',
startAt: 3
})
});[/CODE]
HTML:
[CODE] <div id="timeline">
<ul id="dates">
<li><a href="#">date1</a></li>
<li><a href="#">date2</a></li>
</ul>
<ul id="issues">
<li id="date1">
<p>Lorem ipsum.</p>
</li>
<li id="date2">
<p>Lorem ipsum.</p>
</li>
</ul>
<a href="#" id="next">+</a> <!-- optional -->
<a href="#" id="prev">-</a> <!-- optional -->
</div>[/CODE][/QUOTE]
You forgot a container div.
[code] containerDiv: '#timeline',[/code]
and probably something else.
[url]http://www.csslab.cl/2011/08/18/jquery-timelinr/[/url]
[QUOTE=asantos3;40313561]}); instead of }) maybe?[/QUOTE]
Still nothing. Thanks for the suggestion though.
[QUOTE=asantos3;40313561]}); instead of }) maybe?[/QUOTE]
Javascript doesn't care if you skip a ';' before a '}', you'll see this in a lot of minified js files.
[editline]17th April 2013[/editline]
[QUOTE=Slater;40313604]Still nothing. Thanks for the suggestion though.[/QUOTE]
If you press F12 and look in the console, does it give any errors?
[editline]17th April 2013[/editline]
[QUOTE=Slater;40313604]Still nothing. Thanks for the suggestion though.[/QUOTE]
Also, in the demo:
[url]http://www.csslab.cl/ejemplos/timelinr/latest/vertical.html[/url]
his <li> work like this:
[code]<li><a href="#1930">1930</a></li>[/code]
yours are like this:
[code]<li><a href="#">date1</a></li>[/code]
Maybe you need to change the href to "#date1" as well?
Does it give error on ur chrome console? Are you sure youre requesting ur plugin correctly
Doesn't matter now, sorry guys. I managed to do something else instead. Thanks for your help, anyway.
[QUOTE=eternalflamez;40313889]Javascript doesn't care if you skip a ';' before a '}', you'll see this in a lot of minified js files.[/QUOTE]
Didn't know that. Can I get a why?
[QUOTE=asantos3;40314613]Didn't know that. Can I get a why?[/QUOTE]
Uhm, iirc because newlines = semicolons for javascript. So as long as you have a newline it's okay.
For instance place this in jsfiddle:
[code]var a = 1
var b = 2
alert(a+b)[/code]
It'll alert "3". Remove the newlines, and it's suddenly broken.
Why they let newlines act as semicolons? Not sure, maybe to save some bytes?
Oh, feeling like an idiot now. I already knew that, didn't remember though because I always add a ;
[QUOTE=asantos3;40314613]Didn't know that. Can I get a why?[/QUOTE]
JavaScript has something called Automatic Semicolon Insertion (ASI).
There is a bit of a debate about this at the moment but the standard is to use semicolons because it is explicit. Also some JavaScript minifiers and validators have problems with it.
[QUOTE=CBastard;40314883]JavaScript has something called Automatic Semicolon Insertion (ASI).
There is a bit of a debate about this at the moment but the standard is to use semicolons because it is explicit. Also some JavaScript minifiers and validators have problems with it.[/QUOTE]
I know that but I didn't remember it because I always add the semicolon. Maybe I'll change my mind like I did with self-closing tags.
Sorry, you need to Log In to post a reply to this thread.