PDA

View Full Version : Auto posting Form


shiroimin
10-05-2007, 02:37 PM
Hello, I am new to this site, in hope of finding some help please. My boss needs me to do something on his site, and I do not have the knowledge to do that yet.

He needs something very similar to craigslist type of posting. The user clicks "Post Here", fills out a form (Name, email, location of sale, 1-5(10) pictures), clicks "Post", and a link with one image will appear on the frontpage as well as a separate new page for the post. We do have SQL database. No, we are not creating a craigslist like site, but we are joining with our local newspaper, and we want people who read the newspaper, to be able to post their items and location of yardsales.

If somebody could help me out with either the code itself, or point me in the right dorection as to where I would be able to learn that. I have basic HTML knowledge, and able to use MS Frontpage or Macromedia Dreamweaver.

Thank you in advance if someone can help me please.

ess
10-05-2007, 03:12 PM
What programming language does your server support?

Does it support ASP, ASP.NET, PHP, JAVA EE, Ruby, Perl, Python????

There are loads of open source content management systems...but may require modifications and code re-write to customize it to your requirements.

Find out what programming/scripting language your sever supports..and do a google search on CMS plus the language that is supported by your server.

if you get stuck, come back and post again...

cheers
~E

shiroimin
10-05-2007, 03:14 PM
Thanks for the help, I will look around, btw it supports ASP and PHP

shiroimin
10-05-2007, 03:32 PM
Uhm, CMS mostly only allows me to manage my whole website, any specific one you would recommend that can do what I need? My boss does not like to wait at all, and would like to have something done today. I am looking for something user friendly and easy to setup.

shiroimin
10-05-2007, 06:39 PM
Ok, I found a PHP site, that has just what I need, but while going trough their setup, I found out the coding is PHP v4, and I beleive I have PHP v5 and was told that the coding is a little different. Can someone please help me with this coding? (private information has the >private info<)

SystemComponent.php
<?php
class SystemComponent {

var $settings;

function getSettings() {

// System variables
$settings['siteDir'] = '>private info<';

// Database variables
$settings['dbhost'] = '>private info<';
$settings['dbusername'] = '>private info<';
$settings['dbpassword'] = '>private info<';
$settings['dbname'] = '>private info<';

return $settings;
}
}
?>

DbConnector.php
<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: DbConnector
// Purpose: Connect to a database, MySQL version
///////////////////////////////////////////////////////////////////////////////////////
require_once 'SystemComponent.php';

class DbConnector extends SystemComponent {

var $theQuery;
var $link;

//*** Function: DbConnector, Purpose: Connect to the database ***
function DbConnector(){

// Load settings from parent class
$settings = SystemComponent::getsettings();

// Get the main settings from the array we just loaded
$host = $settings['dbhost'];
$db = $settings['dbname'];
$user = $settings['dbusername'];
$pass = $settings['dbpassword'];

// Connect to the database
$this->link = mysql_connect($host, $user, $pass);
mysql_select_db($db);
register_shutdown_function(array(&$this, 'close'));

}

//*** Function: query, Purpose: Execute a database query ***
function query($query) {

$this->theQuery = $query;
return mysql_query($query, $this->link);

}

//*** Function: fetchArray, Purpose: Get array of query results ***
function fetchArray($result) {

return mysql_fetch_array($result);

}

//*** Function: close, Purpose: Close the connection ***
function close() {

mysql_close($this->link);
}
}
?>

newArticle.php
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');

// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){

// Create an instance of DbConnector
$connector = new DbConnector();

// IMPORTANT!! ADD FORM VALIDATION CODE HERE - SEE THE NEXT ARTICLE

// Create an SQL query (MySQL version)
$insertQuery = "INSERT INTO cmsarticles (title,tagline,section,thearticle) VALUES (".
"'".$HTTP_POST_VARS['title']."', ".
"'".$HTTP_POST_VARS['tagline']."', ".
$HTTP_POST_VARS['section'].", ".
"'".$HTTP_POST_VARS['thearticle']."')";

// Save the form data into the database
if ($result = $connector->query($insertQuery)){

// It worked, give confirmation
echo '<center><b>Article added to the database</b></center><br>';

}else{

// It hasn't worked so stop. Better error handling code would be good here!
exit('<center>Sorry, there was an error saving to the database</center>');

}

}
?>

<body>
<form name="form1" method="post" action="newArticle.php">
<p>&nbsp;Title:
<input name="title" type="text" id="title">
</p>
<p>&nbsp;Tagline:
<input name="tagline" type="text" id="tagline">
</p>
<p>&nbsp;Section:
<input name="section" type="text" id="section">
</p>
<p>&nbsp;Article:
<textarea name="thearticle" cols="50" rows="6" id="thearticle"></textarea>
</p>
<p align="center">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>




I hope someone can help me with this code. I am so close to making my boss happy ^_^

rmedek
10-05-2007, 06:46 PM
I'm moving this to the PHP section since that's the direction this is going. You should be able to get better help there. ;)

shiroimin
10-05-2007, 07:09 PM
sorry for that, thank you

Pennimus
10-06-2007, 01:55 AM
Well, what exactly isn't working?

shiroimin
10-06-2007, 04:40 AM
When I try to use newArticle.php , it tells me that it can not save to the database.