Intranet Journal

Go Back   IT Management Forum > Intranet Journal

Intranet Journal The new discussion forum for Intranet Journal readers. Leave comments and questions for IJ authors. Suggest story ideas and provide feedback.

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-22-2008, 12:05 PM
robeysan robeysan is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
CMS Tutoial, article three

I get this error whent I try to add an article to the database.
Code:
Warning: require_once() [function.require-once]: Unable to access ../include/DbConnector.php in /data/www/net.athost.vhosts/r/robeysan.athost.net/public_html/cmsadmin/newArticle.php on line 3

Warning: require_once(../include/DbConnector.php) [function.require-once]: failed to open stream: Invalid argument in /data/www/net.athost.vhosts/r/robeysan.athost.net/public_html/cmsadmin/newArticle.php on line 3

Fatal error: require_once() [function.require]: Failed opening required '../include/DbConnector.php' (include_path='.:/usr/local/share/pear') in /data/www/net.athost.vhosts/r/robeysan.athost.net/public_html/cmsadmin/newArticle.php on line 3
the browser is pointing to newArticle.php when this happens

Any help you can provide would be greatly aprectiated.

Last edited by robeysan; 11-04-2008 at 12:14 PM.
Reply With Quote
  #2 (permalink)  
Old 10-23-2008, 08:58 AM
robeysan robeysan is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
Question Upon checking through the fourms

Upon checking through the fourms I relized that the fourm I used should have been included in the newArticle.php file.

My newArticle.php:
Code:
<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,article) VALUES (".
"'".$HTTP_POST_VARS['title']."', ".
"'".$HTTP_POST_VARS['tagline']."', ".
$HTTP_POST_VARS['section'].", ".
"'".$HTTP_POST_VARS['article']."')";

// 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>
<table>
	<form action="newArticle.php" method="post">
	<tr>
		<td>Title
		</td>
		<td><input type="textbox" name="title">
		</td>
	</tr>
	<tr>
		<td>Tagline:
		</td>
		<td><input type="textbox" name="tagline">
		</td>
	</tr>
	<tr>
		<td>Section
		</td>
		<td><input type="textbox" name="section">
		</td>
	</tr>
	<tr>
		<td>Article:
		</td>
		<td><input type="textarea" name="article" rows="20" cols="60"></textarea>
		</td>
	</tr>
	</form>
</table>
</body>
</html>
the directory for newArticle.php is cmsadmin/newArticle.php.

After making these changes I now get this error when trying to access the newArticle.php page

Code:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /data/www/net.athost.vhosts/r/robeysan.athost.net/public_html/includes/DbConnector.php on line 25
I try to access the page by typing the web address with cmsadmin/newArticle.php apended to the end. www.exampl.com/cmsadmin/newArticle.php

What am I doing wrong?
Reply With Quote
  #3 (permalink)  
Old 10-27-2008, 10:01 AM
Kamen Kamen is offline
Registered User
 
Join Date: Apr 2008
Posts: 6
Quote:
Originally Posted by robeysan
What am I doing wrong?
return mysql_query($query, this->link);

should be:
return mysql_query($query, $this->link);


I guess.
Reply With Quote
  #4 (permalink)  
Old 10-30-2008, 02:35 PM
robeysan robeysan is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
I scratched all of the code I had and started over.

Code:
Warning: require_once(SystemComponent.php) [function.require-once]: failed to open stream: No such file or directory in /data/www/net.athost.vhosts/w/www.thelocalsounds.net/public_html/includes/DbConnector.php on line 6

Fatal error: require_once() [function.require]: Failed opening required 'SystemComponent.php' (include_path='.:/usr/local/share/pear') in /data/www/net.athost.vhosts/w/www.thelocalsounds.net/public_html/includes/DbConnector.php on line 6
Above is the error I get when i access newArticle.php

Code:
require_once('../includes/DbConnector.php');
This line of code is from newArticle.php

I can't figure out why it can't find DbConnector.php

Please help
Reply With Quote
  #5 (permalink)  
Old 10-30-2008, 02:56 PM
Kamen Kamen is offline
Registered User
 
Join Date: Apr 2008
Posts: 6
As far as i understand it finds the dbconnector.php.
It cannot find the 'SystemComponent.php' supposed to be part of
.:/usr/local/share/pear'

Are you supposed to install some package like PEAR?


Quote:
Originally Posted by robeysan
Code:
Warning: require_once(SystemComponent.php) [function.require-once]: failed to open stream: No such file or directory in /data/www/net.athost.vhosts/w/www.thelocalsounds.net/public_html/includes/DbConnector.php on line 6

Fatal error: require_once() [function.require]: Failed opening required 'SystemComponent.php' (include_path='.:/usr/local/share/pear') in /data/www/net.athost.vhosts/w/www.thelocalsounds.net/public_html/includes/DbConnector.php on line 6
Above is the error I get when i access newArticle.php

Code:
require_once('../includes/DbConnector.php');
This line of code is from newArticle.php

I can't figure out why it can't find DbConnector.php

Please help
Reply With Quote
  #6 (permalink)  
Old 11-04-2008, 12:12 PM
robeysan robeysan is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
I change my code so the ...

dbConnector and settings all come from the same script. (Any suggestions as to whay this is a bad ideal?) I did this to avoid the earlier stated problems i was having.

Code:
<html>
<head>
<title>New Article</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
$username = "00011";
$password = "quzar12s";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$title = $HTTP_POST_VARS['title'];
$tagline = $HTTP_POST_VARS['tagline'];
$section = $HTTP_POST_VARS['section'];
$thearticle = $HTTP_POST_VARS['thearticle'];

echo $title;
echo $tagline;
echo $section;
echo $thearticle;

$query = "INSERT INTO cmsarticles (title, tagline, section, thearticle) VALUES 
	('$title', '$tagline', '$section', '$thearticle')";
mysql_query($query) or die('Error, insert query failed');

?>



<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>

This is the newArticle.php file I am currently using. When it runs I get an error message that says the insert query fails, why?

The echo command succesfully output the contents of the post btw.

Last edited by robeysan; 11-04-2008 at 12:16 PM.
Reply With Quote
  #7 (permalink)  
Old 11-04-2008, 12:20 PM
Kamen Kamen is offline
Registered User
 
Join Date: Apr 2008
Posts: 6
Umm, there are several possible things that may go wrong:
1. Try not to do:

$query = "INSERT INTO cmsarticles (title, tagline, section, thearticle) VALUES
('$title', '$tagline', '$section', '$thearticle')";

but:
$query = "INSERT INTO cmsarticles (title, tagline, section, thearticle) VALUES
('".$title."', '".$tagline."', '".$section."', '".$thearticle."')";

in other words strings in literals are literals and not variables, so add variables with dots, not enclosed in literals.

2. Check the database table if it has proper columns and types and the table name is correct.



Quote:
Originally Posted by robeysan
dbConnector and settings all come from the same script. (Any suggestions as to whay this is a bad ideal?) I did this to avoid the earlier stated problems i was having.

Code:
<html>
<head>
<title>New Article</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
$username = "00011";
$password = "quzar12s";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$title = $HTTP_POST_VARS['title'];
$tagline = $HTTP_POST_VARS['tagline'];
$section = $HTTP_POST_VARS['section'];
$thearticle = $HTTP_POST_VARS['thearticle'];

echo $title;
echo $tagline;
echo $section;
echo $thearticle;

$query = "INSERT INTO cmsarticles (title, tagline, section, thearticle) VALUES 
	('$title', '$tagline', '$section', '$thearticle')";
mysql_query($query) or die('Error, insert query failed');

?>



<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>

This is the newArticle.php file I am currently using. When it runs I get an error message that says the insert query fails, why?

The echo command succesfully output the contents of the post btw.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 05:05 PM.





Acceptable Use Policy

WebMediaBrands

internet.comMediabistrojusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Shopping | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0