Setting up a database... anyone?

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Okok, I have just started, so i am begging you to be patient.
I have an online form, which I want to submit data from, to a local mySQL database. then, connect to my database with Excel (XLS)

Someone plz help, I am seriously frustrated. PLZ help!!!

I already have a SQL account, and i know how to creat a database, in access, excell, and sql. what i dont know, is how to configure them.
thanks in advance

All the best news here: https://newsbotnet.com

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

Does your hosting account have phpMyAdmin available? That's easiest, although it's good to be able to use the command line too (which I haven't learned myself yet!).

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Megan;225985 wrote: although it's good to be able to use the command line too!.

I know MS DOS if thats what you mean?

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Yes, I have phpMyAdmin, and i sort of know how to use it, but i dont know how to configure it. I dont really need a database, all i need to do, is get my html form to store its data into an online file (csv, mdb, xls. ect.) If you have a solution for that, i would be most grateful. Thanks in advance.

All the best news here: https://newsbotnet.com

He has: 17 posts

Joined: Oct 2007

phpmyadmin and mdb are two different diections.

What hosting/scripting are you on? Linux or windows?

If it is Linux and PHP or Windows and PHP, you can save your form
data in mysql, and use phpmyadmin to export any selected records as csv.

If you are using Windows and ASP, then you can save your form data into mdb, xls, etc.

For more info about php/mysql tutorial, you can refer to
the discussion in this thread.

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

I am using Linux, and I have phpMyAdmin available.
To be honest, i would settle for this:
I have a form, i want to send the results to an "online" CSV.
simple as that.

All the best news here: https://newsbotnet.com

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Yes, you should certainly do this just using PHP -> CSV. Including a database into the proceedings adds needless complexity! Smiling

This looks similar to what you need to do, pretty simplistic but should work: http://www.htmlcodetutorial.com/help/ftopic6106.html

a Padded Cell our articles site!

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

ahh, ok, i will look into this now. the problem I am having, it the advice from the so called experts at this other webmaster forum site. i have given up on them, i just hope i settle in betta here.
Thanks, il tek a luk now.

All the best news here: https://newsbotnet.com

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

I am not this advanced, I am a complete novice. I honestly dont understand a word of this PHP stuff. What I need is a step by step guide, then once i have folloowed it, i need to memorise it for future reference, that how i learn. Never mind, i shall keep searching Sad

All the best news here: https://newsbotnet.com

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

ChildOfEvil wrote: I am not this advanced, I am a complete novice. I honestly dont understand a word of this PHP stuff. What I need is a step by step guide, then once i have folloowed it, i need to memorise it for future reference, that how i learn.

No problem. Smiling

What you need to do is copy this code:

<?php
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<title>Untitled Document</title>
</head>

<body>

if(isset(
$_POST['Submit'])){
  
$name = $_POST['name'];
  
$email = $_POST['email'];
  
$comment = $_POST['comment'];
  
$err = '';
   
   if(trim(
$name)==''){
     
$err .= '-Please enter a name<br>';
   }
   if(empty(
$email)){
     
$err .= '-Please enter an email address';
   }
   if(strlen(
$comment)==0){
     
$err .= '-Please enter a comment<br>';
   }
   
   if(
$err!=''){
      echo
$err;
   }
   else{
     
$filename = 'file.csv';
     
$somecontent = $name . ',' . $email . ',' . $comment . \"\n\";
      
      // Let's make sure the file exists and is writable first.
      if (is_writable(
$filename)) {
      
         // In our example we're opening
$filename in append mode.
         // The file pointer is at the bottom of the file hence
         // that's where
$somecontent will go when we fwrite() it.
         if (!
$handle = fopen($filename, 'a')) {
             echo \"Cannot open file (
$filename)\";
             exit;
         }
      
         // Write
$somecontent to our opened file.
         if (fwrite(
$handle, $somecontent) === FALSE) {
            echo \"Cannot write to file (
$filename)\";
            exit;
         }
         
         echo \"Success, wrote (
$somecontent) to file ($filename)\";
         
         fclose(
$handle);
      
      } else {
         echo \"The file
$filename is not writable\";
      }
   }
}

<form name=\"form1\" method=\"post\" action=\"form.php\">
  <p>Name:
    <input name=\"name\" type=\"text\" id=\"name\" value=\"Joe\">
    <br>
    Email:
    <input name=\"email\" type=\"text\" id=\"email\" value=\"joeatemail.com\">
    <br>
  Comment:</p>
  <p>
    <textarea name=\"comment\">This is my comment</textarea>
</p>
  <p>
    <input type=\"submit\" name=\"Submit\" value=\"Submit\">
  </p>
</form>
</body>
</html>
?>

Into a text file in your 'My Documents' (am going to assume you know about filename extensions), something like: 'form.txt', then change the filename extension to '.php'. That'll tell the Web server to execute the

<?php

?>
blocks in the code. The PHP will take the values from the form, when it is submitted, and write them to 'file.csv'. This doesn't do any e-mailing (yet) but we can get this working and add that stuff in later.

This will probably not work straight-off, but upload it to your server and try entering some details into the form. When you've done that, and it comes up with lots of errors, come back and let us know where you've put the form. We'll have a look and suggest ways to fix the errors.

How does that sound? The key thing is not to panic/get frustrated. Smiling

a Padded Cell our articles site!

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Thank you soo much. I shall do this right now. I really apprieciate this, and i like what you guys do on here, you help a lot of people.
Thanks again, i shal let you know what happens.

All the best news here: https://newsbotnet.com

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

ChildOfEvil wrote: Thank you soo much. I shall do this right now. I really apprieciate this, and i like what you guys do on here, you help a lot of people.

No worries. Thanks for the compliment! Laughing out loud

a Padded Cell our articles site!

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

I think there is something wrong with the code
here is the url... http://www.pcgenius.co.nr/test/form.php
the directory holds: file.csv, form.php
i shall go through the code manually, but i can guarantee that i shall only make it worse, lol. i only know html, not php.

All the best news here: https://newsbotnet.com

greg's picture

He has: 1,581 posts

Joined: Nov 2005

Paste the code here if you want
the link goes to a blank page, so either you where working on it when I clicked it or it doesnt work at all
if there is even one error in php code the whole file breaks

do you have error reports on the screen? or an error log on the server? a log will likely be in the directory where the "form.php" file is

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Hmmm, that is what's known as a white screen of death. Smiling

Just tried this myself and the code definitely works. First thing to check are permissions. You're using a FTP program right? There are lots of these and they all behave differently, but you should be able to right-click on form.php and find out what the permissions are set to (or something similar). Ideally they should be: 644/rw-r--r--, or in simpler language: owner: read, write; group: read; others: read. That might sound confusing, don't worry about it, just grab anything that looks like this, from what your FTP client can tell you about the file and let us know what it is. Could you also look at the directory these files are in? The permissions for that should be 755.

I'm 100% certain there isn't a problem with the code. Probably the permissions, or maybe even a problem with your hosting. We'll get to the bottom of it though. Smiling

a Padded Cell our articles site!

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

I know all about permissions and that sort of thing, i currently have them set to 777 all permissions.
hey greg, welcome to the biggest debate in the history of TWF! lol. the code I am using is identical to the one posted by JeevesBond.
I have uploaded the code in .php format, alongside a file.csv, with the 3 vairables indies (name, email, comment) set them both to 777, then run the file from IE7, and received a "HTTP 500 Internal Error"
JB, my hosting is designed epecially for PHP, it is that hyperphp.com server, running on Linux. the hosting is fine, and as far as i know, so are the permissions on both form.php and file.csv (both on 777)
I have followed all instructions from everyone, and stil messed up somewhere, the problem is, i cannot say i am a novice with this stuff, i have been a web-designer for 3 years, but never with php.
i will keep trying, is 777 wrong? i thought for the test run, i aught to give all access, just to make way for a smooth success. are the permissions wrong?
Greg, when you looked, i was probably editing them, i have not uploaded the updates... by the time i have submitted this post, they should be ready.
I may be writing the csv wrong, but that would not cause the php corruption in the form.php, i have written: "name,email,comment" (with the punc marks)
Let me know what you think, I can guarantee one thing, this topic is going down in my website's history, lol. i shall document sand preserve this whole page, but i had better ask contributer's permission for the copyrights to his info, anyways, back to our subject, let me know what you think plz.

dir> form.php - 777
file.php - 777

I have not editted the php script in any way, i saw no need for this test run.

All the best news here: https://newsbotnet.com

greg's picture

He has: 1,581 posts

Joined: Nov 2005

I'm still getting a white screen

did you have any error logs?

I copied and pasted the code from Jeeves' post, saved as php file and ran it on one of my servers
it worked fine, well it displayed the form, but that means all the other php syntax is ok

when I said to paste the code I meant as you seem to have added things yourself
maybe you made an error with the code you added?

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

the code is identical to the one from Jeeves,
Yes, when i run it, i get a HTTP 500 Error, internal server error.

greg's picture

He has: 1,581 posts

Joined: Nov 2005

one thing i don't see as required is the first .= (dot equals) on the $err variable for $name

It's not likely that will be the error, maybe worth trying... perhaps some apache settings/servers might not like trying to add a value like that when it is null
I am still learning, but cannot see anything else at all, so thought it best to mention (just in case)

I'll keep looking, if I see anything else I will let you know

another thing to consider is the fopen and fwrite, some hosts have security settings that might affect that
might be something to ask your host about
do you have a .htaccess file in that directory?
/test/

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

ChildOfEvil wrote: i will keep trying, is 777 wrong? i thought for the test run, i aught to give all access, just to make way for a smooth success. are the permissions wrong?

Nope, in fact that might be a little too permissive (but good for testing purposes, you can lock it down later). Just have to ask this to make sure: what are the permissions on the 'test' directory?

a Padded Cell our articles site!

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Just have to ask this to make sure: what are the permissions on the 'test' directory?[/QUOTE wrote:

I did not know i had to put on on the directory... i will do that right away, it will be 777 by the time you read this.
(Thanks Greg, I apprieciate it Smiling )

All the best news here: https://newsbotnet.com

greg's picture

He has: 1,581 posts

Joined: Nov 2005

ChildOfEvil;226129 wrote: I did not know i had to put on on the directory... i will do that right away, it will be 777 by the time you read this.
(Thanks Greg, I apprieciate it Smiling )

It was Jeeves that suggested that
but thanks anyway Laughing out loud

ChildOfEvil;226129 wrote: This is what i currently have uploaded...
(....)

so what is the current state of play?
still 500 server error?

As far as I can see the code itself is fine, it works on my server, Jeeves tested it and I submited it to coders in my company and they say they see no problems with it.
So it means if you still have problems there is something at your end causing a problem with the code, like a server setting
For that you will have to contact your host

greg;226121 wrote:
another thing to consider is the fopen and fwrite, some hosts have security settings that might affect that
might be something to ask your host about

do you have a .htaccess file in that directory?
/test/

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

PS: Greg= "I took the "Dot" off those hyroglyphic thingys. and it still did not work, so they now back on"

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

This is what i currently have uploaded...

Quote: Untitled Document

<?php


if(isset($_POST['Submit'])){     $name = $_POST['name'];     $email = $_POST['email'];     $comment = $_POST['comment'];    

$err .= '';          if(trim($name)==''){        $err .= '-Please enter a name<br>';     }     if(empty($email)){        $err

.= '-Please enter an email address';     }     if(strlen($comment)==0){        $err .= '-Please enter a comment<br>';     }  

       if(
$err!=''){        echo $err;     }     else{        $filename = 'file.csv';        $somecontent = $name . ',' .

$email . ',' . $comment . "\n";                // Let's make sure the file exists and is writable first.        if

(is_writable($filename)) {                   // In our example we're opening $filename in append mode.           // The file

pointer is at the bottom of the file hence           // that's where $somecontent will go when we fwrite() it.           if

(!$handle = fopen($filename, 'a')) {               echo "Cannot open file ($filename)";               exit;           }      

           
// Write $somecontent to our opened file.           if (fwrite($handle, $somecontent) === FALSE) {             

echo "Cannot write to file ($filename)";              exit;           }                      echo "Success, wrote

(
$somecontent) to file ($filename)";                      fclose($handle);                } else {           echo "The file

$filename is not writable";        }     }  } 
?>
Name:

Email: Comment: This is my comment

All the best news here: https://newsbotnet.com

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Hey, about the thanks, that was a second message, to you, i know Jeeves said to chmod it, but i sed thanks to you too, for helping.. lol Smiling
I can create .htaccess files in notepad, they are simple, what do i need to type?

All the best news here: https://newsbotnet.com

greg's picture

He has: 1,581 posts

Joined: Nov 2005

No problem. I will help as much as I can mate!

I was asking if you had any .htaccess already in that DIR
simply because .htaccess files are a common cause of 500 server errors

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

acc, i see, well, no i dont, i only have one in the system root, serving my errors, like page cannot be found, the basic error pages.

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Next thing to try: create a new PHP file called 'test.php' in that same directory. Put the following into it:

<?php
  phpinfo
();
?>

Now if that doesn't work, get hold of your hosts. That's about as basic as a PHP command gets. It should print a load of information about the PHP environment, a blank screen indicates that there must be some sort of setup issue.

If it works, I'll be very confused. We'll have to try some more tests if that's the case.

a Padded Cell our articles site!

greg's picture

He has: 1,581 posts

Joined: Nov 2005

Chilfofevil, what is the hosting company you use?

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Call me Reece, and I use Hyperphp.
I will try this Jeeves. 2 mins...

greg's picture

He has: 1,581 posts

Joined: Nov 2005

ChildOfEvil;226182 wrote: Call me Reece, and I use Hyperphp.

that doesn't look like the best of hosting company
I click help links and it goes off to either a weird other domain, or page not found

I guess they have safe mode on PHP
which means your fopen and fwrite might have problems

When safe mode is enabled, PHP checks whether the directory in which you are about to operate has the same UID (owner) as the script that is being executed.

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Never Mind... I just learned how to use a fancy new thingy called SQL, its better than CSV, you can make queries, and all sorts. I will use this, its more secure anyway... I Tink...
Greg, thank you for your support, and interests to help, you certainly deserve your Name. Why not become a Moderator?
and to JeevesBond, thank you soo much for your suggestions, But I really dont think CSV was the best Idea. (Yes Greg, My host does have that safe PHP thing, but i thought that would be ok?)
I have written a small php program, (HTML Form, submits to Processing php file, then gets written to the database.)
Thanks to everyone (dont forget Megan, you started me off at the beginning)
Sorry to cause all this hassle, but I reli think it payed off, as If you guys did never tell me it was PHP that write, and not html, i would still be trying to write with an empty pen. Cheers to everyone,
Keep up the good work, I reli apprieciate your interests to help.
Thanks Again, Reece.

All the best news here: https://newsbotnet.com

greg's picture

He has: 1,581 posts

Joined: Nov 2005

ChildOfEvil;226198 wrote: Greg, thank you for your support, and interests to help, you certainly deserve your Name.
....Why not become a Moderator?

Thanks!
...because we the little people don't make that decision Laughing out loud

ChildOfEvil;226198 wrote: Sorry to cause all this hassle

this is a forum to ask for and give help (among other things) so there was no hassle
I have learned a great deal on this forum (and other forums and websites) and don't mind sharing my (still limited) knowldge wherever I can help

Maybe soon you will be helping others Sticking out tongue

Glad you're sorted. If you get any other problems just post. I'm sure you will have many questions now you have decided to use SQL.
And of course the learning of PHP never ends!

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

ChildOfEvil wrote: Never Mind... I just learned how to use a fancy new thingy called SQL, its better than CSV, you can make queries, and all sorts. I will use this, its more secure anyway... I Tink...

Cool. SQL is easier and is usually more secure (as long as you run the input through mysql_real_escape_string() before mysql_query()). Smiling

Nice investigating Greg, that certainly sounds like the problem. It's good you've found a way around it though Reece, using a database is probably the best way, and you'll learn some good stuff. Smiling

That safe mode might cause problems in the future though. But you might not want to bother worrying about it unless files need to be uploaded.

a Padded Cell our articles site!

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

To be honest and transparent: we just don't have any space for more mods at the moment. If too many people are made up to mods normal members start to feel like outsiders, we really don't want that. This site is meant to be for the normal members, not an inner clique! Laughing out loud

Naturally being really helpful will be taken into account if/when we need mods in future. Smiling

a Padded Cell our articles site!

greg's picture

He has: 1,581 posts

Joined: Nov 2005

I understand that with mods. the current traffic in the forum is more than catered for

But I was aiming for admin though Laughing out loud

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

greg wrote: But I was aiming for admin though

LOL, well you never know! Aim high and all that. Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.