The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

3 Pages V < 1 2 3  
Reply to this topicStart new topic
> Validating 'required' form page data for save to database, Saving by php code file after succesful validation. Success message on
Freddz
post Jan 21 2019, 06:52 AM
Post #41


Novice
**

Group: Members
Posts: 25
Joined: 7-January 19
Member No.: 26,791



Yes, I know that I have to edit the generated file afterwards to e.g. realise iFrame support. However, it is nerving to do that any time you modify this page.
That's why I am prefering a solution that forces manual modifications as less as possible.
So that's why I am currently concentrating on solution 4.

Unfortunately this doesn't work yet.
What I did:
I added an .htaccess file in the html folder with the line:
"AddType application/x-httpd-php .html .htm" and set in the /etc/apache2/apache2.conf file the AllowOverride option from 'none' to 'all':
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

But my test page of the isset function is still not working.
What I couldn't find yet:
1) A proof command if the above apache config file really is the right one. Cannot find an apache command for asking its config file to be totally sure.
2) Cannot find an apache proof command for asking its current override setting.
Points 1 and 2 for making sure that override is really working...
3) Maybe there is still a mistake at my page file!?... Therefore I copied it below to this message for you.
I would appreciate it if you could have a quick look...

Thank you so much for your continuous help !!!

Here is the isset page code:
++++++++++++++++++++++++++++++++++++++++++++++++
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
</HEAD>

<BODY NOF="(MB=(DefaultMasterBorder, 150, 51, 66, 0), L=(KontaktLayout, 849, 452))">
<DIV ID="LayoutLYR"><LAYER ID="LayoutLYR" TOP=0 LEFT=0 VISIBILITY=INHERIT WIDTH=915 HEIGHT=653 Z-INDEX=1><DIV ID="Text39LYR" CLASS="TextObject"><LAYER ID="Text39LYR" VISIBILITY=INHERIT TOP=190 LEFT=81 WIDTH=801 HEIGHT=38 Z-INDEX=1>
</LAYER></DIV><DIV ID="Tabelle4LYR" STYLE="background-color: rgb(217,217,217);"><LAYER ID="Tabelle4LYR" VISIBILITY=INHERIT TOP=249 LEFT=104 WIDTH=746 HEIGHT=272 Z-INDEX=2 bgcolor="#D9D9D9">
<FORM NAME="Tabelle4FORMULAR" METHOD=POST>

<?php
if(isset($_POST['Absenden']))
{
// put form handler script here
echo "Form was submitted (field data saved successfully)!...";
}
else
{
echo "Form was not submitted.";
}
?>

<TABLE ID="Tabelle4" BORDER=0 BGCOLOR="#D9D9D9" CELLSPACING=3 CELLPADDING=1 WIDTH="100%">
<TR>
<TD>
<P> </P>
</TD>
<TD WIDTH=136>
<P><B>Thema:</B></P>
</TD>
<TD WIDTH=253>
<P>
<SELECT ID="Auswahlfeld1" NAME="Auswahlfeld1" required>
<OPTION VALUE="" SELECTED>/ Thema wählen /</OPTION>
<OPTION VALUE="1">Option 1</OPTION>
<OPTION VALUE="2">Option 2</OPTION>
<OPTION VALUE="3">Option 3</OPTION>
<OPTION VALUE="4">Option 4</OPTION>
<OPTION VALUE="5">Option 5</OPTION>
</SELECT>
</P>
</TD>
<TD WIDTH=299>
</TR>
<TR>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD WIDTH=253>
<P STYLE="text-align: center;"><INPUT TYPE=SUBMIT NAME="Absenden" VALUE="Abschicken" ID="Schaltflaeche1"></P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
</TR>

</TABLE>
</FORM>
</BODY>
</HTML>
+++++++++++++++++++++++++++++++++++++++++++++++

This post has been edited by Freddz: Jan 21 2019, 07:05 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freddz
post Jan 21 2019, 07:13 AM
Post #42


Novice
**

Group: Members
Posts: 25
Joined: 7-January 19
Member No.: 26,791



Afterwards I tested your last suggestion, Christian, to rename the page file from .html to .php for testing. And SURPRISE:
This works!!
So it seems as if the page code is okay but Apache is still not configured correctly (of course I didn't forget to restart it)!...

So we just may have to clarify my points 1 and 2 above!?...

This post has been edited by Freddz: Jan 21 2019, 07:15 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 21 2019, 11:09 AM
Post #43


.
********

Group: WDG Moderators
Posts: 8,238
Joined: 10-August 06
Member No.: 7



QUOTE(Freddz @ Jan 21 2019, 12:52 PM) *

I added an .htaccess file in the html folder with the line:
"AddType application/x-httpd-php .html .htm"

Without the quotes I hope? In any case, the exact directive can be very different depending on how Apache is configured. Asking the web host should be the easiest approach.

QUOTE
and set in the /etc/apache2/apache2.conf file

Are you running your own server? AFAIK you sually don't have access to that file on shared hosts? unsure.gif

QUOTE
Afterwards I tested your last suggestion, Christian, to rename the page file from .html to .php for testing. And SURPRISE:
This works!!
So it seems as if the page code is okay but Apache is still not configured correctly (of course I didn't forget to restart it)!...

Good! happy.gif I wouldn't say it's configured incorrectly though, it's just a matter of preference. If you want you can simply keep using the .php extension, that's what most sites do (including this forum).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freddz
post Jan 21 2019, 05:27 PM
Post #44


Novice
**

Group: Members
Posts: 25
Joined: 7-January 19
Member No.: 26,791



My code is okay, isn't it?...

Yes, I have a root server. However, it was basically installed by the provider and I am not a web specialist. Could you clarify the points 1 and 2 above maybe?...
It is just to see what the current apache configuration is.
Unfortunately it seems as if it is not possible to check apache via command line for its current configs, is it?

I don't like to have a mixture of php and html files. Don't want to run away from that little apache config problem...

What do you mean by "It is just a matter of preference"?
Shouldn't the current code work fine if the internal php code will be interpreted/cared?...
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 22 2019, 05:55 AM
Post #45


.
********

Group: WDG Moderators
Posts: 8,238
Joined: 10-August 06
Member No.: 7



QUOTE(Freddz @ Jan 21 2019, 11:27 PM) *

My code is okay, isn't it?...

The PHP yes, otherwise it wouldn't work with a .php extension either. (It's not valid HTML4 though, but that doesn't affect PHP.)

QUOTE
Could you clarify the points 1 and 2 above maybe?...
It is just to see what the current apache configuration is.
Unfortunately it seems as if it is not possible to check apache via command line for its current configs, is it?

Sorry I don't know. Maybe this could work: https://stackoverflow.com/questions/2715294...d-configuration
You can also get a lot of PHP configs with http://php.net/manual/en/function.phpinfo.php

QUOTE
I don't like to have a mixture of php and html files. Don't want to run away from that little apache config problem...

Again, the easiest is to ask the provider. There are lots of different .htaccess directives used for this, depending on how Apache is used.

QUOTE
What do you mean by "It is just a matter of preference"?
Shouldn't the current code work fine if the internal php code will be interpreted/cared?...

Yes. By default, the PHP engine is only used for files with .php extensions. But you can change this in the preferences to .html, .foo or whatever extension you like.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freddz
post Feb 12 2019, 11:58 AM
Post #46


Novice
**

Group: Members
Posts: 25
Joined: 7-January 19
Member No.: 26,791



QUOTE(CharlesEF @ Jan 15 2019, 09:53 PM) *

I forgot to say that you didn't post enough 'DBinsert' code for me to tell if you will get a response back from the ajax call. Also, in the 'DBinsert.php' file you should check to make sure every value needed is supplied in the $_POST array before doing the database insert.


Hello CharlesEF,

I meanwhile tested your Ajax code (s. #33) in detail. And now I realised that a new recordset is created but the data are NOT inserted into the database.
So it seems as if I still have to modify s.th. at my dbinsert.php file for this Ajax usage although it works fine when used for a usual access via HTML.
However, I am sure that all the $_POST values which are needed for the SQL insert command are appended in the array handed over.
Here is the whole code of dbinsert.php for you:
+++++++++++++++++++++++++++++++++++++++
$servername = "localhost";
$username = "xyz";
$password = "abc";
$dbname = "name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO Interessenten (Name, Email, Telefon, ....)
VALUES ('" . $_POST["Name"] . "', '" . $_POST["Mail"] . "', '" . $_POST["Telefon"] . "', '" . ..... "', '" . date("Y-m-d") . "')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
+++++++++++++++++++++++++++++++++++++++

So do you see the reason why the sql insert command is still not successful?
(Remark: I suppose that the order of data elements in the appended string must not be the same than the one in the sql command...)

This is the append code:
var formData = new FormData();
formData.append(document.getElementsByName("Name").id, document.getElementsByName("Name").value);
formData.append(document.getElementsByName("Mail").id, document.getElementsByName("Mail").value);
formData.append(document.getElementsByName("Telefon").id, document.getElementsByName("Telefon").value);
...

By the way how could I debug this process so that I would get a useful error message of this fault?...
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Feb 13 2019, 01:07 AM
Post #47


Programming Fanatic
********

Group: Members
Posts: 1,672
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



The main problem I see is your use of 'getElementsByName'. That function returns an array and your code isn't written to handle arrays. You should use 'getElementById' instead. Each element in the <form> should have both an 'id' and a 'name' attribute. The 'id' can be used by Javascript and the 'name' can be used by PHP.

As for errors, Javascript errors can be seen using your browsers 'Web Development Tools' or whatever your browser calls it. PHP errors can be found in the php error log, which by default should be in your tmp directory.

If you want to see the errors on the page you are working on then put these 2 lines of code, in a php block, at the top of the web document.
CODE
ini_set('display_errors', 'On');
error_reporting(E_ALL);
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freddz
post Feb 13 2019, 11:13 AM
Post #48


Novice
**

Group: Members
Posts: 25
Joined: 7-January 19
Member No.: 26,791



Oh thank you.
So I changed from ByName to ByID again. IDs of each form element fits to the append commands.

But now a new recordset is not even created when pressing send button.
I also inserted your two lines to get errors but nothing changed.
I also opend Chrome dev tools to get logs (s. http://prntscr.com/mkmtuk) but there are so many functions and I cannot find any logs about my send process.

So I still have no idea what the reason is that data are not saved to db or why formdata is not correctly handed over at 'ajax.send(formData);' to my dbinsert.php sql file.
I am frustrated...

Can you maybe instruct me in some way how I can find that out?
Do you know a good description to quickly learn the usage of Chrome dev tools?...
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Feb 13 2019, 12:01 PM
Post #49


Programming Fanatic
********

Group: Members
Posts: 1,672
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Nothing in 'dbinsert.php' jumps out at me, except the fact that you are open to SQL injection attacks. Since you use mysqli_* you should use parameterized queries. As written 'dbinsert.php' won't send a response when ajax is used. You say no PHP errors are shown? If correct, that means the problem is on the Javascript side. Post the entire ajax function.

I hate google so I can't help you with Chrome (to me Android and Chrome are nothing more than spyware) .
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freddz
post Feb 13 2019, 09:59 PM
Post #50


Novice
**

Group: Members
Posts: 25
Joined: 7-January 19
Member No.: 26,791



QUOTE(CharlesEF @ Feb 13 2019, 06:01 PM) *

Nothing in 'dbinsert.php' jumps out at me, except the fact that you are open to SQL injection attacks. Since you use mysqli_* you should use parameterized queries. As written 'dbinsert.php' won't send a response when ajax is used. You say no PHP errors are shown? If correct, that means the problem is on the Javascript side. Post the entire ajax function.

I hate google so I can't help you with Chrome (to me Android and Chrome are nothing more than spyware) .



My Android phone runs without GAPPS !
But Chrome runs really better and more reliable than Firefox...
I can use Firefox as well here, no problem...

There you are with the Ajax code. But I didn't change anything at your code...


Attached File(s)
Attached File  ajax_post___modified.html ( 1.03k ) Number of downloads: 235
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Feb 14 2019, 10:19 AM
Post #51


Programming Fanatic
********

Group: Members
Posts: 1,672
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I still see the same problem. You did change the command but you didn't use the command I posted. You used 'getElementByID' instead, which is an invalid command. The correct command should be 'getElementById'. Case does matter.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freddz
post Feb 15 2019, 01:34 PM
Post #52


Novice
**

Group: Members
Posts: 25
Joined: 7-January 19
Member No.: 26,791



Ohhh, you are sooo great!!
Now it works !!!!
(didn't know that letter capital is that important!)

Thank you so much, Charles! You made s.o. VERY happy today!!
All the best to you!

PS: What would you suggest to me to learn this stuff asap?
Maybe any good tutorials?...
But best would be a good, almost free WYSIWYG editor for me, maybe.
(I also still have Dreamweaver CS6...)

This post has been edited by Freddz: Feb 15 2019, 01:37 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Feb 15 2019, 03:40 PM
Post #53


Programming Fanatic
********

Group: Members
Posts: 1,672
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Glad to hear you got it working (after shooting yourself in the foot, a couple of times).

The javascript errors will show up in the 'Web Console'. While I can't help you with Chrome debugger tools you should at least see the errors in the console.

As for tutorials, sorry I don't keep up with that. Your best tool is the Internet 'Search' feature. I also don't use any WYSIWYG editors either. I write my code by hand. So, can't help you with that.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

3 Pages V < 1 2 3
Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 16th October 2019 - 09:05 AM