Jump to content
Html

Table has error

Recommended Posts

Quote

Fatal error: require(): Failed opening required '/connect_db.php' (include_path='.:/usr/share/pear/')

That is after the trying the create_forum page, line 5 it also states.

mysql_set_charset($dbc, 'utf-8');

 

Share this post


Link to post
Share on other sites

Right! you have a error message, you have the line, look and find out why the error exists! its there in plan sight, errors do not fix themselves, and if errors exist nothing will work.

Share this post


Link to post
Share on other sites

Other than the missing i, what else? That isn't the solution.

Quote

Warning: require(/connect_db.php): failed to open stream: No such file or directory in

blah blah directory of free web host.

Share this post


Link to post
Share on other sites

The leading slash is looking for the file at the root of the server. You almost never need to start a path name with a slash. You have to replace that with the actual path to the file. If the file is in the same directory as the current PHP file, then removing the slash will fix the problem. If it is in a sub-directory then you need to put the name of the sub-directory in the path.

Where is connect_db.php in relation to the current PHP file you are writing?

Share this post


Link to post
Share on other sites

The file is supposed to be outside the folder where other php, html files are stored for security reasons, if you have set this up the same and bothered to read and understand, you would see it starts with '../' this indicates the file 'connect.db.php' is not in the same folder but outside.

These are the example files, which include header,footer.html files where they are placed in relation to each other'

http://ineasysteps.com/wp-content/uploads/2016/07/SRC.zip

Share this post


Link to post
Share on other sites

They are all in htdocs, there is an incudes folder with header, and footer html, with a <p> tag each. That is it.

I see, I didn't know about that, I couldn't of guessed.

Now line 3 is the problem, I thought may the ) was the problem as it states, no change.

Ah I see, so there are example files, could it be the spacing of the code? n ) and so on?

Edited by Html
Line 3 problem

Share this post


Link to post
Share on other sites
mysqli_connect('mysqlserverlink','user','pass','db',)

This is for connect_db

Parse error: syntax error, unexpected ')' line 3

Edited by Html

Share this post


Link to post
Share on other sites

The problem is visibly there in plain sight! compare it to the one in the example files, and maybe book an appointment at spec-savers. The character position they indicate ')' usually directly follows the error in question. EYES WIDE OPEN!

Share this post


Link to post
Share on other sites
<?php

$dbc = mysqli_connect( 'localhost' , 'mike' , 'easysteps' , 'website_db' )
OR die( mysqli_connect_error() ) ;

mysqli_set_charset( $dbc , 'utf8' ) ;

This is from the files you linked to,

 

<?php
$dbc=
mysqli_connect( 'server', 'user', 'pass', 'db', )
OR die ( mysqli_connect_error() );
mysqli_set_charset($dbc,'utf-8');

 

Share this post


Link to post
Share on other sites

Get a magnifying glass, or better still Hubble telescope, the error is in plain sight! compare the first line. The top is correct, the other not so, because of one single extra character that should not be there.

Share this post


Link to post
Share on other sites

I tried removing the bracket at the end, only then causes a T_logical error on line 4, and if I do remove another from line 4.

You'll have to point to it, because I haven't a clue.

Share this post


Link to post
Share on other sites

IT'S NOTHING TO DO WITH BRACKET

Count quotes, brackets, and commas between both of them! they should be the same! You have an extra one of these compared to correct example one.

Share this post


Link to post
Share on other sites

Right okay then, I did think that may be there was a comma out of place, now a new error has displayed on line 3, the user has been denied.

Share this post


Link to post
Share on other sites

Any of these host, user, even database must match those from your web host, the password must match what you had provided to access the database, it depends on how much the host controls on setting these up. If these don't match you won't be able to access anything.

Share this post


Link to post
Share on other sites

I am using Infinityfree which is very much the same as Advancedfree, infinityfree is Arizonan based from the information available.

But yes, I typed in the msql server address, and the mysql  username,  password, and database which has the created forum table that I used from the above post. I had trouble with this host using the example files I downloaded, and edited and that didn't work on there service, but did work on Advancedfree and Heartinternet, the latter being paid.

I did inquire on their forum, and an Admin was upset about me complaining, if that rubbish worked on those two hosts why this host so particular, could be that they have very over protective system.

Yes, there is a password which is not the same as the user login, that was same as Heart. It seemed obvious with Heart than with this. Okay so far looks like this is up and running.

Edited by Html
Different password used for db use

Share this post


Link to post
Share on other sites

My last file to do is process, filled in the details, only a blank page loads, and no data entered into the db.

<?php
$page_title = 'forum'
include('includes/header.html');
function fail($str)
{
echo"<p>Please enter a $str.</p>";
echo '<p><a href="post.php">Post message</a>';
include('includes/header.html');
exit();
}
if( isset( $_POST[ 'message' ] ) )
{
  if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
  { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
  else { fail( 'First Name' ) ; }
  if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
  { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
  else { fail( 'Last Name' ) ; }
  if ( !empty( trim( $_POST[ 'subject' ] ) ) )
  { $subject = addslashes( $_POST[ 'subject' ] ) ; }
  else { fail( 'Subject' ) ; }
  if ( !empty( trim( $_POST[ 'message' ] ) ) )
  { $message = addslashes( $_POST[ 'message' ] ) ; }
  else { fail( 'Message' ) ; }
  require ( '/connect_db.php' ) ;
  $sql = "INSERT INTO forum (first_name,last_name,subject,message,post_date) 
          VALUES ('$first_name', '$last_name','$subject', '$message', NOW() )" ;
  $result = mysqli_query( $dbc, $sql ) ;
  if (mysqli_affected_rows($dbc) != 1) 
  { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
  else 
  { mysqli_close( $dbc ) ; header('Location: forum.php') ;   }
}
?>

 

Share this post


Link to post
Share on other sites

IF you are not going to copy the code exactly as is, thinking that won't make a difference, you are mistaken.

The first echo line in function is WRONG! it won't work.

IF the connect.php is outside the folder containing this file, as instructed by the tutorial, it won't work.

Edited by dsonesuk

Share this post


Link to post
Share on other sites

Okay, I copied the full, and pasted it in, now I get a process error, that is all that loads, the page header is also displayed. So something is working, no db info recorded.

What could it?

All the files are in the same folder, except for the includes folder files.

Yes it was simply the forward slash I forgot about, I noticed that php code must be spaced. I'm a step closer to my goal of a working system with this. Now using what I had downloaded, and trying to change it to work with this code.😩

Thanks for the responses.

Edited by Html
Works!

Share this post


Link to post
Share on other sites

I should concentrate on a small script to read data from table, once that works, you will have everything you need, knowing that it works! The correct username, host, database, table and password.

If these don't work when you add to the tutorial script, you will know it is something else other than database connection code.

Share this post


Link to post
Share on other sites

I tried editing the files to remove the subject, once it gets to process.php no loading.

All I did was remove subject and anything with it from all the files. Including removing the subject from the db. Just that small change which I think I've done correctly, and it doesn't work.😥

I also was able to view example files from leaning php book, I really need the Learn php 7 easy steps kind of books, 😉 even though they aren't as informative, very simple.

<?php
$page_title = 'forum'
include('includes/header.html');
function fail($str)
{
echo"<p>Please enter a $str.</p>";
echo '<p><a href="post.php">Post message</a>';
include('includes/header.html');
exit();
}
if( isset( $_POST[ 'message' ] ) )
{
  if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
  { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
  else { fail( 'First Name' ) ; }
  if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
  { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
  else { fail( 'Last Name' ) ; }
  if ( !empty( trim( $_POST[ 'message' ] ) ) )
  { $message = addslashes( $_POST[ 'message' ] ) ; }
  else { fail( 'Message' ) ; }
  require ( '/connect_db.php' ) ;
  $sql = "INSERT INTO forum (first_name,last_name,message,post_date) 
          VALUES ('$first_name', '$last_name', '$message', NOW() )" ;
  $result = mysqli_query( $dbc, $sql ) ;
  if (mysqli_affected_rows($dbc) != 1) 
  { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
  else 
  { mysqli_close( $dbc ) ; header('Location: forum.php') ;   }
}
?>
<?php 
$page_title = 'PHP Process Error' ;
include ( 'includes/header.html' ) ;
function fail( $str )
{
  echo "<p>Please enter a $str.</p>";
  echo '<p><a href="post.php">Post Message</a>' ;
  include ( 'includes/footer.html' ) ;
  exit(); 
}
if( isset( $_POST[ 'message' ] ) )
{
  if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
  { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
  else { fail( 'First Name' ) ; }
  if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
  { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
  else { fail( 'Last Name' ) ; }
  if ( !empty( trim( $_POST[ 'message' ] ) ) )
  { $message = addslashes( $_POST[ 'message' ] ) ; }
  else { fail( 'Message' ) ; }
  require ( 'connect_db.php' ) ;
  $sql = "INSERT INTO forum (first_name,last_name,message,post_date) 
          VALUES ('$first_name', '$last_name', '$message', NOW() )" ;
  $result = mysqli_query( $dbc, $sql ) ;
  if (mysqli_affected_rows($dbc) != 1) 
  { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
  else 
  { mysqli_close( $dbc ) ; header('Location: forum.php') ;   }
}
?>
<?php
$page_title='php post message';
include('includes/header.html');
echo'<form action="process.php"
method="POST" accept-charset=""uft-8">
First Name:<input name="first_name" type="text">
Last Name:<input name="last_name" type="text">
<p>Message:<br>
<textarea name="message" rows"5" cols="50">
</textarea></p>
<p><input type="submit" value="Submit"></p>
</form>';
echo '<p>
<a href="forum.php">Forum</a></p>';
include('includes/footer.html');
?>

I've removed from forum, post, and process subject named as I stated. The error is column 1

Works okay now. I guess it was just a server side process error.

Edited by Html
That was odd, I guess it was just a temporary error

Share this post


Link to post
Share on other sites

If you had display errors on! IT would have pointed out this

$page_title = 'forum'

and

echo"<p>Please enter a $str.</p>";

and this

echo'<form action="process.php"

Which we have already discussed before, but! you seem to think it will work now! NO it won't!

Share this post


Link to post
Share on other sites

Only that first line is a syntax error, the others aren't.  Not the best programming style, but not an error.

Share this post


Link to post
Share on other sites

The error was solved, the code is from the book as is, but I've edited the three files not to have subject property.

I thought I could use the process.php to replace register.php but that didn't work out.

It is unfortunate the book didn't at least have that as a tutorial, would of been everything I need for now..until I could think what feature would be next for a user system.

It can't be that difficult to get this working up. It is all to do with that PDO setup, unless somehow I can use the tutorial file to replace the register file. It needs work on it to make it work the same way as register, since you stated in the past that it was crap, and thirteen years too old. But it does work on the paid host, but not on the free host, since this example code does work, this is my best bet.

<?php 
$page_title = 'PHP Process' ;
include ( 'includes/header.html' ) ;
function fail( $str )
{
  echo "<p>Please enter a $str.</p>";
  echo '<p><a href="post.php">Post Message</a>' ;
  include ( 'includes/footer.html' ) ;
  exit(); 
}
if( isset( $_POST[ 'message' ] ) )
{
  if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
  { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
  else { fail( 'First Name' ) ; }
  if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
  { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
  else { fail( 'Last Name' ) ; }
  if ( !empty( trim( $_POST[ 'email' ] ) ) )
  { $subject = addslashes( $_POST[ 'email' ] ) ; }
  else { fail( 'email' ) ; }
  if ( !empty( trim( $_POST[ 'password' ] ) ) )
  { $subject = addslashes( $_POST[ 'password' ] ) ; }
  else { fail( 'password' ) ; }
  require ( 'connect_db.php' ) ;
  $sql = "INSERT INTO users (first_name,last_name,email,password) 
          VALUES ('$first_name', '$last_name', '$email', '$password' )" ;
  $result = mysqli_query( $dbc, $sql ) ;
  if (mysqli_affected_rows($dbc) != 1) 
  { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
  else 
  { mysqli_close( $dbc ) ; header('Location: profile.php') ;   }
}

So proces.php this is called.

}
if( isset( $_POST[ 'message' ] ) )
{

I doubt that would be in a file for a replacement for register.

Edited by Html

Share this post


Link to post
Share on other sites
Quote

thirteen years too old.

Unfortunately, after removing PDO and its prepared statements, and using addslashes of all things, you're back to code that is thirteen years out of date.

I don't know what issues you were having with the other code, but I guarantee it wasn't PDO and using prepared statements to protect your database.

It's difficult for me to continue trying to help you.  It seems like things keep regressing, you run into a minor problem like a missing character and throw everything out and come back with something worse with an entirely new set of problems.  The unfortunate thing is that I doubt that you understand this code any better than the code you threw out.  Maybe I'm wrong, but when it's telling you which line the error is on and you can't spot things like a missing semicolon or hanging comma it seems like you're not understanding what you're doing.  Tossing out newer code and trying to go back to something that people stopped using a decade ago isn't helping.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×