Jump to content

Quick Script Review


proggR

Recommended Posts

I'm changing my site from text files to a database and wrote out the scripts on paper here at work. I just wanted to get someone to look them over to see if there's any gaping holes at all. There's also a few things I'm not 100% sure about in the script so if someone brings them up I'll know I was wrong :P

Normally I wouldn't just dump code but in this case I just need

 

<?php
*****UPDATE PAGE*****
connect(){
$host = 'localhost';
$user = 'root';
$passwd = 'password';

$conn = mysql_connect($host, $user, $passwd) or die ("Could not connect to the database");
$db = 'database_name';
mysql_connect($db);
}

disconnect(){
mysql_close($db);
}

//declare variables
$file = $_POST["date"]."_".$_POST["course"]."_".$_POST["title"].".php";
$path= "Class/".$filename;

$title = $_POST["title"];

$description = $_POST["description"];

$content = $_POST["content"]; //assigns the content of form.php to the variable content

$course= $_POST["course"];

$rss = "<item> \n<title>".$title."</title> \n<description>".$description."</description> \n
<link>http://127.0.0.1/".$filename."</link> \n </item>";

$header = "<?xml version=\"1.0\"?> \n<rss version=\"2.0\"> \n<channel> \n";

$footer = "</channel> \n</rss>";
//end declaring variables


connect();

$query = "INSERT INTO table VALUES (null, $title, $content, $course, $file)";//
mysql_query($query) or die ("Could not update database records");

disconnect();


**********************************************************************
*****GET INFO**********************************************************
***note, this is a separate file from the first section and grabs the values to include them***
**********************************************************************
get_some($keyword){
$limit_start = ($page-1)*5;
$query = "SELECT file FROM table WHERE course=$keyword LIMIT $limit_start,5"
$response  = mysql_query($query);
$counter = 0;
while($row=mysql_fetch_array($result)){
	$path[$counter]=$row['file'];//if I'm only grabbing one column I probably don't need to make $row an array like this
	$counter = $counter+1;
}

}

get_all(){
$limit_start = ($page-1)*5;
$query = "SELECT file FROM table LIMIT $limit_start,5"
$response  = mysql_query($query);
$counter = 0;
while($row=mysql_fetch_array($result)){
	$path[$counter]=$row['file'];//if I'm only grabbing one column I probably don't need to make $row an array like this
	$counter = $counter+1;
}

}

//start actual script
if(isset($_GET["page"])){
$page=$_GET["page"];
}
else{
$page=1;	
}


connect();
if(isset($_GET["keyword"])){
$keyword = $_GET["keyword"];
get_some($keyword);
$symbol = "?keyword=".$keyword."&";//used to switch between pages with only that keyword being used, not all
}
else{
get_all();
$symbol="?";
}

disconnect();




******INCLUDE VALUES*******
foreach ($path as $value){
include("Folder/".$value);
echo "<br";
}


?>

 

And I just noticed that It sees the ?> in my XML section as the end of the PHP code. Sorry for the confusion there. It doesn't affect the actual script at home I don't think (the RSS feed updates fine).

Link to comment
Share on other sites

Oops. The original scrip had $filename but I switched it to $file, but aparently not thoroughly.

Same with the $response/$result thing.

The select_db was one of the things i wasn't sure on. Thanks.

Anything else?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.