php mysql_connect doesn't work for me. Can someone help?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

php mysql_connect doesn't work for me. Can someone help?

Postby Lukas M » 28. July 2019 19:52

Hello,

i have a problem while trying to connect to MySQl using a script below - it simply does nothing. No error, no new data in a db table.. nothing. I simply do not know what else to check: SQL freshly installed, no passwords, windows firewall turned off.

my index.html contains this tiny code for a testing form that was supposed to be entered into a mySQL database "tutorial" within a table "AccountCreationDB"

INDEX.HTML

<html>
<body>

<form action="includes.php" method="post">
<BR>username:
<input name="regUsername" type="text">

<BR><BR>>email address:
<input name="regEmail" type="text">

</form>

<input type="submit" name="submit">

</body>
</html>


-----------------------------

INCLUDES.PHP

<?php

$dbServername = "127.0.0.1";
$dbUsername = "root";
$dbPassword = "";
$dbName = "tutorial";

$con = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

$regUsername = $_POST['regUsername'];
$regEmail = $_POST['regEmail'];

$sql = "INSERT INTO accountcreationdb (regUsername, regEmail) VALUES ('$regUsername','$regEmail');";

mysqli_query($con,$sql);

header("Location: step2.html");

?>

any help appreciated.. to me it does not look like the issue with the code but a communication failure between "browser and SQL".
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: php mysql_connect doesn't work for me. Can someone help

Postby Altrea » 28. July 2019 20:03

Hi,

how exactly do you access your html form? Which address does your browsers address bar show at the time you access the html form?

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9803
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: php mysql_connect doesn't work for me. Can someone help

Postby JJ_Tagy » 28. July 2019 20:06

Not enough info to troubleshoot - as you note you don't think there is anything wrong with the code. Therefore, maybe a couple of recommendations:
- I recommend using the .php extension on these files so you don't accidentally try to use PHP at the browser level in an html file.
- You don't need a semi-colon in your queries to delimit the query.
- Make sure your files are actually saved and don't include a different extension (such as index.html.txt or includes.php.txt).
- Check your access logs in apache to see if the request even comes through.

P.S. I see Altrea already split the post and replied, so I will leave this here to give food for thought.
JJ_Tagy
 
Posts: 763
Joined: 30. January 2012 13:44
Operating System: Windows 10 Pro x64

Re: php mysql_connect doesn't work for me. Can someone help

Postby Lukas M » 28. July 2019 20:40

many thanks for a prompt reply

i can rule out the xtra TXT extension
myPhpAdmin shows 0 accesses to SQL server.. thats what bothers me
when I try to rename "index.html" to "index.php" it does not open in a browser - well it "does" like a text file all over the screen showing the entire code.
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: php mysql_connect doesn't work for me. Can someone help

Postby Lukas M » 28. July 2019 20:49

Altrea wrote:Hi,

how exactly do you access your html form? Which address does your browsers address bar show at the time you access the html form?

best wishes,
Altrea


it shows a local file from a network drive: file:///P: xxxxx xxxxx
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: php mysql_connect doesn't work for me. Can someone help

Postby Altrea » 28. July 2019 22:58

Lukas M wrote:it shows a local file from a network drive: file:///P: xxxxx xxxxx

And that is the problem. You are starting the form for example by double click. That way the file gets accessed by your browser only in local context.
Any relative referenced ressource in that file (e.g. the includes.php file) will also get accessed in local context.
But this failed because your browser cannot process php code. PHP is a server side programming language, so it needs to get interpreted by a server, not the browser.

So, you need to request the form by url (e.g. http://localhost/index.html to request file \xampp\htdocs\index.html)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9803
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: php mysql_connect doesn't work for me. Can someone help

Postby Lukas M » 28. July 2019 23:18

thanks for the tip.. I copied both files into C:\xampp \ htdocs directory (where the default index.php is located).. I can access my "index.html" by typing http:\\localhost:8080\index.html (the page correctly appears).. but its still not working, no entry into SQL database, no error displayed after clicking "submit" button".. no "refresh" (clearing the content of the input fields either).

what am I doing wrong?
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: php mysql_connect doesn't work for me. Can someone help

Postby Altrea » 28. July 2019 23:32

Your submit button is not part of your form.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9803
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: php mysql_connect doesn't work for me. Can someone help

Postby Lukas M » 28. July 2019 23:41

Altrea wrote:Your submit button is not part of your form.



you are a GENIUS! .. that worked! thanks so much! :D :D
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 50 guests