• Announcements

    • boen_robot

      Guidelines and Netiquette   03/28/2017

      Posting Problems:   Having problems posting your topic? Read through this: To join, you agree to our terms and conditions and fill out and submit a registration form. An activation email will be sent to your email adress, so you'll need to verify your account. After that the account has to be validated by one of the moderators. This will mean that it can take up to a day to be activated. A couple of things to remember to ensure approval: Don't use an email address in one of those $2 four character .com domains eg. xyds.com. These will be deleted and the domain added to the banned list. Don't use an email address that is within a domain with a bad reputation for spam. A Google search is run on every email address and email domain. Don't sign up with an email address that doesn't exist, doesn't work or requires the sender to answer a quiz before their email can get to you. Put your country and or state and city in the signup form. Blank forms will go to the botton of the "to do" list. And make sure that your email address and your country match, saying you're from Alabama and using a .ru email address is not going to get you activated. After a membership is activated the first few posts will be monitored. Posting spam or unapproved topics described in the agreement results in an immediate ban. The email provider and the IP addresses associated with the account will be banned and all posts will be deleted. These strict measures have been deemed necessary to hinder spam. Sorry for any inconvenience this causes, but it's not liable to change. If, after reading this, you still can't post and don't understand why, contact one of the Moderators listed here.   Topic Guidelines   Including the following information can expedite an accurate response from board members: Must be a Specific Problem or Question related to web design and development Include Code in Question (wrap with   for small blocks of code and for longer blocks   ) Include Code Author Include Extra Notes/Modifications/Attempts Include web link to page/file when possible Content Guidelines   You may not post, upload, link to, or email any Content that contains, promotes, gives instruction about, or provides prohibited Content. Prohibited Content includes any Content that breaks any local, state, county, national or international law. Prohibited Content also includes: No direct or indirect advertising or websites, forums, products, services No hijacking of posts (do not post your question in someone elses) Content that infringes upon any rights [ex. MP3s and ROMs] (including, but not limited to, copyrights and trademarks) Abusive, threatening, defamatory, racist, or obscene Viruses or any other harmful computer software False Information or libel Spam, chain letters, or Pyramid schemes Gambling or Illicit drugs Terrorism Hacking or cheating for internet/online games Warez, Roms, CD-Keys, Cracks, Passwords, or Serial Numbers Pornography, nudity, or sexual material of any kind Excessive profanity Invasive of privacy or impersonation of any person/entity Hacking materials or information Posting Tips   There are more BBcodes than there are buttons for on the reply menu. To get the full list, click "BB Code Help" underneath the clickable smilie face menu. Use   for small snippets of code Use   for lengthy snippets of code Use   if your snippet is HTML (optional) Use   if your snippet is SQL (optional) Rules of Conduct   Be nice. There's no need for calling someone stupid if they ask an 'easy' question. Keep your avatars and signatures absolutely child friendly. We have a younger audience on this forum. Keep your language appropriate for the same reason above. Do not PM moderators for help on the forum. Post on the topic, or create a new one.   Spam:   Recently, as you have all without doubt noticed, we have had lots of spam and advertisement on the forum. Therefore, we'd like to alert you as to what to do when you have found any of the aforementioned annoying messages: it. Immediately. Give a clear reason, please, if the advertising is not evident. DO NOT POST! Report, let the post stay as is, and we will get to it, meanwhile if you continue to post as normal in the other threads, it won't be on the top so long. Refrain from PMing the member. This won't help at all, as they are most likely spambots anyway. Thank you.       Images in signatures:   After thinking of users on dial-up, we have decided to enforce the following rules regarding signatures. Please pay heed to them. Respecting these rules is respecting the members on this forum with dial-up. Signature rules: No animated images AT ALL. No matter the amount of animation. Maximum image widthxheight: 300x150 Maximum image (file) size: 15kb Use calm colors. Do not use highly contrasting images in your signature, as this can get really annoying when seeing several posts from one member in the same thread. The same prohibited content goes for images as for posts. Lastly, use common sense. No lengthy signatures please. Save us some scrolling. Thank you.       Links in signatures:   Please understand that w3schools.com only exists because of voluntary work and is barely supported by the advertising littered throughout the tutorials and the forum. So, please, stop advertising other sites. DO not post links that drive traffic away from the w3schools domain - especially to a site that offers similar if not identical information. Please help support the site by keeping individuals on it. Thank you. Here are some guidelines as to what you can put in your signature: w3schools links --> allowed w3.org links --> allowed browser links --> allowed html editor links --> allowed personal sites --> allowed tutorial sites competing with w3schools --> NOT allowed sites completely irrelevant to webprogramming and this forum --> NOT allowed   Thanks for understanding, and for taking the time to read this. ~W3Schools Modstaff~
Html

How do I create a database in phpmyadmin + Php form problem

39 posts in this topic

Posted (edited)

Hello,

I have this code here, I watched a video on how to create a form for php posting. In phpmyadin, the database is called 'page', so, what happens after I post an email and password on my page, it goes to a 404 on the web host I'm using.

Quote

<? php

$con= mysqli_connect('IP for database'.'root','');

if (!$con)

{
echo 'Not connected To Server';
}

if(!mysqli_select_db($con, 'page'))
{
echo 'Database Not selected';
}
$Email = $Post('email'};
$Password = $Post('Password'};

$sql = "INSERT INTO Person(Email, password) ValueS ('$Email', '$password')";

if(!mysqli_query(!$con,sql))
{
echo 'Not inserted';
}
else
{
echo 'Not inserted';
}
header("refresh:1; url=formhtml.html");
?>

Quote

<body>
 <form action="/post.php" method="post">
   name:<br>
  <input type="text" value="username"><br>
  Password:<br>
  <input type="text" name="lastname" value="password"><br><br>
  <input type="submit" value="Submit">
</form> 
</body>

 

So the php file, and the web page above.

Here is screen of the phpmyadmin.

Thank you.

 

 

 

 

 

pagedb.jpg

Edited by Html

Share this post


Link to post
Share on other sites

Is your php file located at the root directory of the webroot?  Try opening the PHP file in a browser, and if it is indeed at the root, you should be able to access it at http://<your-domain>.com/post.php.  Otherwise, you have an incorrect path to post.php in your form.  If the form and the PHP file are in the same directory, you could just use

<form action="post.php" method="post">

 

Share this post


Link to post
Share on other sites

These

Email = $Post('email'};
$Password = $Post('Password'}; 

are supposed to be $_POST['email']; AND $_POST['Password']; and the coloured names are suppose to match the values of name attributes of inputs you are trying to read

 

<input type="text" value="username"><br> Password:<br> <input type="text" name="lastname" value="password"><br><br>

AS you can see, they match neither, and one does not even have a name attribute which is required for ALL inputs, AND name values must match exactly as 'password' is treated differently to 'Password'.

 

1 person likes this

Share this post


Link to post
Share on other sites
<form method="post" action="/post.php"> -> this is wrong.
  <form method="post" action="post.php"> -> this is right ( if the post.php is in the same directory as the page you are calling on.
    <form method="post" action="../post.php"> -> goes with a directory up.

 

Share this post


Link to post
Share on other sites

Posted (edited)

Hello,

Thank you for the responses, tried the following edits. And the files are located in htdocs folder in the online file manager?

And no, form.php just goes to a 404.

Quote

<body>
 <form action="post.php" method="post">
   Email:<br>
  <input type="text" value="Email"><br>
  Password:<br>
  <input type="text" name="Password" value="password"><br><br>
  <input type="submit" value="Submit">
</form>
</body>

 

Quote

<? php

$con= mysqli_connect('service ip'.'root','');

if (!$con)

{
echo 'Not connected To Server';
}

if(!mysqli_select_db($con, 'page'))
{
echo 'Database Not selected';
}
$Email = $POST('email'};
$Password = $POST('Password'};

$sql = "INSERT INTO Person(Email, password) ValueS ('$Email', '$password')";

if(!mysqli_query(!$con,sql))
{
echo 'Not inserted';
}
else
{
echo 'Not inserted';
}
header("refresh:1; url=formhtml.html");
?>

 

Edited by Html

Share this post


Link to post
Share on other sites

I wasn't able to solve this, what could be the problem with this?

Share this post


Link to post
Share on other sites

What's the problem, you submit the form and get a 404?  If that's the case, then make sure the file with the form and the file that you're submitting to are in the same folder.

Share this post


Link to post
Share on other sites

Posted (edited)

Yep they are in htdocs.

 

 

result.jpg

fileuploader2.jpg

Edited by Html
Added new image.

Share this post


Link to post
Share on other sites

What does that link point to?  Your code above says post.php, but the screenshot shows form.php.  Are you pointing to the right file?  And, if so, why would your server claim that a file isn't there if it is?  If that's the case then you probably need to ask your host why it's claiming that files which exist don't.

Share this post


Link to post
Share on other sites

Ah okay, I see. I did change that.

It doesn't redirect back to the login page, as well, there is no record in the mysql database.

Share this post


Link to post
Share on other sites

That custom 404 page doesn't give a lot of information, it doesn't help that it redirects to 404.html.  Maybe the redirection isn't working.  The normal way to redirect though is to send a Location header with the new URL.  But, for testing, I would suggest not redirecting and making sure the PHP code works.  Your PHP code has some errors in it, so maybe the server sees the PHP errors and redirects to 404 for some reason.

Here are some of the issues with your PHP code:

You're trying to call a function called $POST, but $POST isn't defined.  If you want to get submitted values you get them from $_POST, which is an array, not a function.  So, for example, you would use $_POST['name'].

If your database connection fails you don't stop the script, the rest of the code still runs without a database connection.

When you call mysqli_query, you used !$con which is going to send a boolean value instead of the actual connection.

You need to use prepared statements when you're sending data to the database.  The mysqli extension supports prepared statements, you need to use them to make sure your queries run and protect against SQL injection attacks.

You send the same text ('Not inserted') regardless of whether or not the record was inserted in the database.

If you use echo to send any output, sending a header after that will not work.

1 person likes this

Share this post


Link to post
Share on other sites

Hmm, well the example I got of this was from a tutorial on a video site. So I'm not knowledgeable in MySql, or php. I'm also not a computer programmer, so I'm not versed in the subject of web languages. I only ever got as far as html 4.01, that was ten years back. So therefore I returned here to get some answers for my problem. The clips jump from here to there, and so on. Its great, but it is all bit messy.

Okay, now I get a post.php, but no values in the database. So from what you have stated, about !$con is a problem. I doubt I'd have to be concerned about any scramble mysql code or so. I'm not going very far with this yet. Some sort of login page/comment form.

Thank you.

<? php

$con= mysqli_connect('mysql service db ip'.'root','');

if (!$con)

{
echo 'Not connected To Server';
}

if(!mysqli_select_db($con, 'page'))
{
echo 'Database Not selected';
}
$Email = $_POST('email'};
$Password = $_POST('Password'};

$sql = "INSERT INTO Person(Email, password) ValueS ('$Email', '$password')";

if(!mysqli_query(!$con,sql))
{
echo '';
}
else
{
echo '';
}
header("");
?>

 

 

Share this post


Link to post
Share on other sites

What happens when you run that code?  There are several syntax errors, are you seeing those error messages?  If not, they're probably going to an error log somewhere, maybe in the same directory as that file.  The first step is to figure out how to see the error messages, all of those options are configured in php.ini.

Share this post


Link to post
Share on other sites

There is no Php.ini file, where would be if not in the file manager?

Nothing occurs. Blank screen once I tested the email form. The code doesn't go back to the form page, I removed that, but the Mysql db should contain the record, but nothing.

1 person likes this

Share this post


Link to post
Share on other sites

formhtml.html

<!DOCTYPE html>
<html>
    <body>
        <form action="form.php" method="post">
            name:<br>
            <input type="text" name="email" value="Email"> <!-- value of 'name' attribute (which is required) will be used by $_POST['email']; to retrieve 'Email' value--><br>
            Password:<br>
            <input type="text" name="Password" value="password"><!-- value of 'name' attribute (which is required) will be used by $_POST['Password']; to retrieve 'password' value--><br><br>
            <input type="submit" value="Submit">
        </form>
    </body>
</html>

form.php

<?php // NO space between <? and php

$con = mysqli_connect('mysql service db ip' . 'root', '');

if (!$con) {
    echo 'Not connected To Server';
}

if (!mysqli_select_db($con, 'page')) {
    echo 'Database Not selected';
}
$Email = $_POST['email']; // changed to square braces, ['email'] should match same case used in the value of name="email" in form.
$Password = $_POST['Password']; // changed to square braces, ['Password'] should match same case used in the value of name="Password" in form.

$sql = "INSERT INTO Person(Email, password) VALUES ('$Email', '$Password')"; // ValueS (changed to 'VALUES') should all be the same case
lower or upper (preferably UPPERCASE), '$Email' and '$password' should match exactly the variable name that the specific $_POST[] were
assigned to, (NOTICE your code shows all lowercase for '$password' when the $variable name is '$Password' these are treated as different
variables).

if (!mysqli_query(!$con, sql)) {
    echo '';
} else {
    echo '';
}
header("");

 

Share this post


Link to post
Share on other sites
Quote

Not connected To ServerDatabase Not selected

This is now what I get from having typed in some values into the form, I did correct the php file. As I had stated, I had watched a tutorial clip on youtube a few months back now, that would be, and it showed not using brackets or the fact that there was a space between php and the question mark.

Share this post


Link to post
Share on other sites

That is nothing to do with form submitted data, that is to do with database connection, they are the warnings set out by

if (!$con) {
    echo 'Not connected To Server';
}

if (!mysqli_select_db($con, 'page')) {
    echo 'Database Not selected';
}

Share this post


Link to post
Share on other sites

Nothing occurs. Blank screen once I tested the email form.

The page is blank because, like I said, there are syntax errors.  If your file has syntax errors then nothing gets executed at all, PHP can't even figure out the structure of your code to even start running it.  The lack of error messages means that you either have error reporting turned off, or it's going to an error log.

There is no Php.ini file

Yes there is.  If you want to figure out which one your server is using, create a phpinfo page and look for the line that says "loaded configuration file" or something similar.  If PHP somehow got installed on that server with no php.ini file at all then it's going to use default values for every option.

<?php phpinfo();

Share this post


Link to post
Share on other sites

I tried that, the free host I am using has Php 7, dates back to May.

And this is load configuration /etc/php70/php.ini

I did watch a clip on youtube about this file, I was puzzled.:wacko:

Share this post


Link to post
Share on other sites

Check the settings for error reporting and logging to see what they're set to.  Depending on your host, you may be able to make changes to those settings in a .htaccess file or other file.  You should definitely try to understand the error reporting settings on that server so that you can find the actual error messages instead of trying to guess what the problems are, you just can't effectively debug problems if you can't find the error messages.

http://php.net/manual/en/configuration.php

Share this post


Link to post
Share on other sites

Where would I find that? I don't think the free host gives that access, a free host may restrict php edits, may be its for forum use only as there is a phpbb forum available to use therefore the mysql access.

Share this post


Link to post
Share on other sites

You can create a phpinfo page to look at all of the current options, and if you click that link above you'll find information about how and where to set the various options.

http://php.net/manual/en/function.phpinfo.php

Share this post


Link to post
Share on other sites

Right okay that brings up what I viewed before, error logs are on. What am I going to find to get some information on what is going on?

Share this post


Link to post
Share on other sites

The error_log option should tell you where the error log is.  According to this:

http://php.net/manual/en/ini.list.php

The error_log option is settable in any location, so you can create a .htaccess file (assuming your server supports those) to set the error log to a file in your directory.  Make sure that the server has permission to write to the file, and then you can find your error messages there.

Share this post


Link to post
Share on other sites

Hmm, I may be of been correct, you may be onto a fact, that there could be limitations for use with the free web host, perhaps full use of the php/mysql is for paid only.

I read about a htaccess file, It can be created as you stated,

AuthName "Member's Area Name"
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
require valid-user
ErrorDocument 401 /error_pages/401.html
AddHandler server-parsed .html 

 

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