PDA

View Full Version : What's?



Shibby-Shabs
19-09-2010, 09:47 AM
What's wrong with this code, some strings are on config.php




<?php
include('config.php');
$submit = $_POST['submit'];
$host = "localhost";
$user = "root";
$pass = "123";
$database = "jacksphp";
$date = date('Y-d-m');
$message = $_POST['message'];

$connect = mysql_connect('localhost','root','123') or die('MySQL couldnt connect!');
mysql_select_db('jacksphp') or die(' Couldnt connect to database!');

if ($submit)
{
if ($_POST['on'])
$status = $_POST['on'];
else
{
$status = $_POST['off'];

$query = mysql_query("UPDATE notice SET message='$message' status='$status' date='$date' WHERE id='1'");
echo "Updated!";


}

}
else
{
echo '
<form action="edit.php" method="POST">
<table border="0">
<tr>
<td><input type="checkbox" name="on" value="On"> <u>Message On</u> </td></tr><br />
<tr><td><input type="checkbox" name="off" value="Off"> <u>Message Off</u></td> <br />
</tr>
<tr>
<td><textarea name="message" cols="25"></textarea> </td>
</tr>
</table>
<input type="submit" name="submit">
<form>
';
}
?>

Dentafrice
19-09-2010, 05:26 PM
After $status = $_POST['on']; you're missing a curly bracket for } else {.

LMS16
19-09-2010, 06:21 PM
After $status = $_POST['on']; you're missing a curly bracket for } else {.



http://bytes.com/topic/php/answers/5071-curly-brackets-necessary-php :)

Sometimes they aint needed...

Lew.

Dentafrice
19-09-2010, 07:19 PM
I know this... I just quickly glanced at it and that was the first thing that popped up while scanning down through the lines, either way.. it's ugly and not a good practice, especially when you get into veryyy structured applications. Brackets separate them all very nicely.

Shibby-Shabs
20-09-2010, 12:01 AM
I usually do but because it's only one line I didn't really need to.

Dentafrice
20-09-2010, 11:34 AM
Then there's nothing wrong with it? It has no errors as far as I can tell / you've told us?

No you really didn't *need* to.. but it looks like crap when you're reading it and especially looks like crap when you start coding where it looks good and start aligning everything.. not everything aligned to the left.

HotelUser
20-09-2010, 11:47 AM
Then there's nothing wrong with it? It has no errors as far as I can tell / you've told us?

No you really didn't *need* to.. but it looks like crap when you're reading it and especially looks like crap when you start coding where it looks good and start aligning everything.. not everything aligned to the left.

There is no right way to do it. You shouldn't force your preference upon him.

Dentafrice
20-09-2010, 06:34 PM
I'm not forcing my preference on anyone... but you have to admit it makes it a whole lot easier to debug and see what's wrong when it's not all jumbled up and separated out...

HotelUser
20-09-2010, 07:24 PM
I'm not forcing my preference on anyone... but you have to admit it makes it a whole lot easier to debug and see what's wrong when it's not all jumbled up and separated out...

I'm inclined to disagree because if I was write:



while(statement)
{
foreach(statement)
{
if(statement)
{
echo 'x';
}
}
}


I would prefer to do



while(statement)
foreach(statement)
if(statement)
echo 'x';

Dentafrice
20-09-2010, 08:19 PM
You misunderstood everything I said.. "when it's not all jumbled up".... everything you did above is fine... but if you're going to use brackets in some places and not others... it's better to pick one method.

this.. is jumbled up..


if ($submit)
{
if ($_POST['on'])
$status = $_POST['on'];
else
{
$status = $_POST['off'];

$query = mysql_query("UPDATE notice SET message='$message' status='$status' date='$date' WHERE id='1'");
echo "Updated!";


}

}
else
{

HotelUser
20-09-2010, 11:25 PM
You misunderstood everything I said.. "when it's not all jumbled up".... everything you did above is fine... but if you're going to use brackets in some places and not others... it's better to pick one method.

this.. is jumbled up..

I can certainly see where you're coming from although both look extremely messy.

Please tell me you write neater than that :P

Dentafrice
20-09-2010, 11:42 PM
Haha bud, I just copied it from his first post :P of course I write neater then that! see....



<?php
include "config.php";
$name=$_GET["name"];
//isnt this neat
$name2=$_GET["name2"];
// this is nice
//sdfkasd iomment
?>
Isn't it neat?

p.s. that was a joke ;p

HotelUser
21-09-2010, 02:04 AM
Haha bud, I just copied it from his first post :P of course I write neater then that! see....



<?php
include "config.php";
$name=$_GET["name"];
//isnt this neat
$name2=$_GET["name2"];
// this is nice
//sdfkasd iomment
?>
Isn't it neat?

p.s. that was a joke ;p

Good! Theres a Habbox horror story here. I won't reference to which script I am referring to only that it's a rather large one, nor will I say who coded it as they're now long gone but it consists of one folder of about 60 assorted php files, in which every single last one of them has absolutely no spacing to speak of and genuinely takes an hour of investigating and even recoding to poke and pry towards changing even the most simplest of things.

Dentafrice
21-09-2010, 02:47 AM
His name is Caleb... he's sitting right here... and it's called Housekeeping haha. Talk about the old days.. a new file for each and every action... config file was dbConfig.php, index.php, login.php, add_user.php, remove_user.php, so many my gosh lol.

So many features removed and added and left in there.. awful!

Want to hide these adverts? Register an account for free!