Gamoc
Smiley Abuser & Big Word Abuser..
Defying Gravity!
Posts: 3,935
|
Post by Gamoc on Sept 24, 2007 17:06:59 GMT -5
<?php
#Thread process script #by Pikablu
require ("database.php"); include ("functions.php);
mysql_connect('localhost','password','username'); mysql_select_db('threads') my
$allowUBBC = isset($_POST['allowUBBC'] ? true : false;
$allowSmileys = isset($_POST['allowSmileys] ? true : false;
$nosubject = "(NO SUBJECT)";
$name = $_COOKIE['user'];
$subject = isset($_POST['Subject']) ? $_POST['subject']: $nosubject";
$message = $_POST['message'];
$tehDate = dat("d/m/y h:i:s"); if(isset($_POST['subject'])) { if(isset($message) || !empty($message)) { if(!strlen($message) > 250050) { $messageInsert = "INSERT INTO threads(message, subject, date) VALUES($message, $subject, $date)"; mysql_query($messageInsert); } else { $error1 = "<li>Your message cannot be more than 250050 characters</li>"; } if(!exists($name)) { $noName = "Guest"; $insertNoName = "INSERT INTO threads(name) VALUES($noName)"; mysql_query($insertNoName); } else { $insertName = "INSERT INTO threads(name) VALUES($name)"; mysql_query($insertName); } if(!$allowUBBC == false && !$allowSmileys == false) { $otherInserts = INSERT INTO threads(allowUBBC, allowSmileys) VALUES($allowUBBC, $allowSmileys); mysql_query($otherInserts); } else { $error2 = "<li>You must have a message</li>"; } $arrayOfErrors = array($error1, $error2); foreach ($arrayOfErrors as $errors) { echo "<ul>".$errors."</ul>"; } }
?>
How does that look? Does it look like it could be improved, or anything? Something added?
Are there any suggestions on things that would make the script cleaner?
|
|
Simie
Coding Admin
Why are you all still here?
Posts: 721
|
Post by Simie on Sept 26, 2007 15:11:17 GMT -5
Well, the $arrayOfErrors looks as if it could be done better. You'd be better to do something like this: (Near beginning of script): $arrayOfErrors = Array(); And that SQL looks seriously mucked up. That would create about 4 different posts with one execution. You have to use something like this: INSERT INTO posts VALUES('1', 'Post Title', 'Post Content', 'Post Poster' etcetc) You can't just do a query to add it all to the same post. (Every time there is an error): $arrayOfErrors[] = 'Error ! '; Then use the foreach statement you used to output it.
|
|
Gamoc
Smiley Abuser & Big Word Abuser..
Defying Gravity!
Posts: 3,935
|
Post by Gamoc on Sept 29, 2007 16:22:16 GMT -5
Okay, wow, I had a lot of problems.
<?php #Thread process script #by Pikablu
require ("database.php"); include ("functions.php);
mysql_connect('localhost','password','username'); mysql_select_db('threads');
$boookmark = isset($_POST['bookmark']) ? true : false;
if(checkLogin() == 2) { $ann = isset($_POST['ann']) ? true : false;
$stiky = isset($_POST['sticky']) ? true : false;
$lokc = isset($_POST['lock']) ? true : false; } else { $ann = 'false'; $stiky = 'false';
$lokc = 'false'; }
$nosubject = "(NO SUBJECT)";
$name = $_COOKIE['user'];
$subject = isset($_POST['Subject']) ? $_POST['subject']: $nosubject;
$message = $_POST['message'];
$tehDate = dat("d/m/y h:i:s");
$arrayOfErrors = Array();
if(isset($_POST['submit'])) { if(!isset($message) || empty($message)) { $arrayOfErrors[] = "<li>You must have a message</li>"; } else { if(strlen($message) > 255000) { $arrayOfErrors[] = "<li>Your message cannot be more than 255000 characters</li>"; } } else { if(!exists($name)) { $noName = "Guest"; INSERT INTO threads(user, subject, message, date) VALUE($noName, $subject, $message, $tehDate); } else { INSERT INTO threads(user, subject, message, date, ann, lock, sticky) VALUES($name, $subject, $message, $tehDate, $ann, $lokc, $stiky); } foreach ($arrayOfErrors as $errors) { echo "<ul>".$errors."</ul>"; } }
?>
Here is the new script, while rewriting it, I noticed a lot of bugs. Thanks for pointing these out to me.
|
|