Jump to content

Archived

This topic is now archived and is closed to further replies.

Mr Chris

include files!

Recommended Posts

Hi Guys,

Trying to ‘tidy-up’ things on my site and trying to use include php files. So I have this form, which posts data from a website page to a database which has include files:

[code]
<?php

include 'librarys/config.php';
include 'librarys/opendb.php';
  

// POST variables
$section = $_POST['section'];
$added_by = $_POST['added_by'];
$headline = $_POST['headline'];
$byline_name = $_POST['byline_name'];
$appeared = $_POST['appeared'];
$opening = $_POST['opening'];
$body_text = $_POST['body_text'];
$pic_caption = $_POST['pic_caption'];
$pic_ref = $_POST['pic_ref'];
$notes = $_POST['notes'];


// If submit is hit then insert data into database
if(isset($_POST['upload'])){

  $query = "INSERT INTO cms_stories ( section,added_by,headline,byline_name,appeared,opening,body_text,pic_caption,pic_ref,notes) VALUES ('$section','$added_by','$headline','$byline_name','$appeared','$opening','$body_text','$pic_caption','$pic_ref','$notes')";
  $msg = "A new story has been added to the database - Please Click <a href=\"menu.php\">Here</a> to return to the main menu";
}

?>
[/code]

[b]Config file[/b]
[code]
<?php
// db properties
$dbhost = 'localhost';
$dbuser = '**********';
$dbpass = '*********';    
$dbname = '*********'
?>
[/code]

[b]Opendb file[/b]
[code]
<?php
$conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($dbname);
?>
[/code]

But since I created the opendb file and config file holding the password data and connection data my form no longer posts to the mysql database? There are no mysql errors, so can anyone please see why it does not post to the db table?

Thanks

Chris

Share this post


Link to post
Share on other sites
You never run the query. Try using mysql_query().

Share this post


Link to post
Share on other sites
Hi

You missed to call mysql_query() fuction after creating the query
[code]
mysql_query($query);
[/code]

Share this post


Link to post
Share on other sites

×

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.