Testing PHP files with XAMMP

Hiii good morning…

I’m trying to test my php files …My PC is Windows 10, I installed XAMPP and I’m administrator… I don’t know if I’m putting the files in the right root … this is my root c:\xampp\htdocs\form\deya.php but is taking the other localhost and takes last screenshot with the error in php in this root C:\inetpub\wwwroot\index.html

here my xammp configuration
xammp

here my xammp root
xammp%20root

here the wwwroot
wwwroot

Let me know please what am I doing wrong :frowning:

if you started

c:\xampp\xampp-control.exe

your files should be located at

c:\xampp\htdocs

e.g.

c:\xampp\htdocs\index.php

and as apache is started, you should see a blank page when you go to this URL in any browser

http://localhost:1234

and if you edit the index.php like

<?php phpinfo();

and refresh the page in your browser you should see some configuration output.

(your confusion might come from the fact you configured port 1234 for access instead of the default port 80, so your browser needs this extra info within the URL)

1 Like

inetpub is the Microsoft IIS server equivalent to htdocs. You must have IIS installed and running. I recommend choosing XAMPP (Apache, PHP and MySQL) over IIS. Sure, IIS supports PHP nowadays but it geared toward ASP and other Microsoft technologies. If you leave it installed, then IIS will periodically start automatically. I have tried running both but i got tired of the auto start interrupting my Apache sessions.

To remove IIS, you want to first backup any files that you were working on. Then you need to access the Turn Windows features on or off, find Internet Information Services entries and uncheck all of them. I believe that you need to reboot afterward.

I suggest reinstalling XAMPP, after backing up your files, to have it set at port 80 for normal http traffic.

Hi John, this blog is not letting me post too many messages … that’s why I cannot answer right away I have to wait hours to do it… :frowning: if you can send messages here ::mod removed:: I’d appreciate it.

Question:
where do you recommend me to insert this code for the connection with the dtabase and inserting the info in a new php file or insert inf form.php?

I see also that XAMPP works with MySql, do i have to download it or can I continue to use Postgresql? I already create my DB and table in Postgresql…

Right now I’m just trying 2 things, connect to my database and insert the info in the tables.

And I’m having this error…Here screenshot trying to connect to the database , I’m not sure about the default Postgresql password

i do not wish to communicate with females via email. I am married and i love my Wife very much. We have rules that we do not communicate with members of the opposite sex privately. I don’t mind offering help in this publicly viewable forum. I don’t use Postgre but you will have to alter the username and password to your username and password of the Postgre database. You may also have to alter the query a bit. Perhaps a Postgre user will offer an opinion.

@johnphpnewb you don’t have to explain why you don’t want to send emails. We’re on a forum and it’s perfectly fine to continue here :slight_smile:

2 Likes

Thanks, Jim. I have a habit of feeling guilty if i suspect that i seem rude. I don’t want to offend anyone here. Next time i will just continue. :slight_smile:

That should be fixed now.

Some links to get you started. At this point, you are fighting configuration issues, not code issues.

http://www.7codes.info/post/13/install-postgresql-in-xampp-on-windows-and-integrate-phppgadmin-tool

http://www.postgresqltutorial.com/postgresql-php/

1 Like

No problem John, I’m just new in this blog and I jus needed to asks question and the blog didn’t allowed me to do several question at the same time and I wanted to finish the Form but I haven’t been able so I was just trying to communicate in a faster way but I will never disrespect anybody here in this forum. No problem. Anyways …I am still not able to connect with my Database and I’m not sure if I am doing it right… here what I have for the connection…

Should I put somehting special here in the botton?

Why does your PDO connection use mysql?

I just saw a few examples but I’m not an expert so I am trying to learn how to do the connection…

As PDO can connect to various databases you have a least to specify the correct connection string. There’s a lot of tutorials about it

https://duckduckgo.com/?q=pdo+postgresql

Your connection string may look like

pgsql:host=localhost;port=5432;dbname=pagila;user=postgres;password=postgres

1 Like

Christian has answered your question:

 $dbh = new PDO("pgsql:dbname=$dbname;host=$host", $dbuser, $dbpass);

I assumed that you were using MySQL, which is why i made an example PDO cnnection using MySQL.
You just need to change this code to work with Postgre database. I should’ve asked you which database you are using. My apologies. :slight_smile:

Thanks I will try it …

I have another question … should I put something in the button? where I am gonna catch the info?
here … value=“SUBMIT”

And no problem I have also to be more specific what I am doing and I don’t remember a lot of stuff that I learned in college:woman_facepalming:… just have to remember again sql etc

you allready have this data in the form submission:

<input type="text" name="name"
<input type="email" name="email"
<input type="text" name="job"
<textarea name="message"
<input type="submit" name="submit"

all of this data is sent to the server as an array $_POST[].
Thus all of your input becomes:

$_POST["name"], $_POST["email"], $_POST["text"], $_POST["job"], $_POST["message"], $_POST["submit"]
if ($_POST["name"])
or assigned to a variable: $postName = trim($_POST["name"]);
if ($postName)

so in your form processing script (deya.php in my example code)

if ($_SERVER["REQUEST_METHOD"] == "POST")

then process data. You should trim, then validate input before processing it with the database script
Here you will include the database connectivity script include “path/to/dbconn.inc.php”;

assign output to variables, then display those database ouput variables to the user as htmlentities($databaseOutputName, ENT_QUOTES, "UTF-8"));

actually, you just want to store the info in the database, so you can run your database script after input has been validated. Then you can show the input as htmlentities($_POST[]).

or as POST data

htmlentities($_POST["name"], ENT_QUOTES, "UTF-8"));

to summarize:

<?php

$name = $email = $job = $message = $result = NULL;

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    //validation is time consuming and most people will not code it for you
    //validation is making sure data is correct for the what you expect
    //regex can help limit a name to proper name characters. 1111 is not valid
    //trim all $_POST data to be sure it isn't empty
    //if name is empty: if (empty($_POST["name"]) { $nameError = true; }

    //included files have access to variables declared in this file
    //thus, DeyaDB.php can process $name, $email, $job, $message and $result
    include "DeyaDB.php"; //INSERT posted data into your table

    /* if you want to display this data to the user in thankyou.php, then
       you have to clean it in thankyou.php so code input is not executed. */
    //echo htmlentities($name, ENT_QUOTES, "UTF-8");
    //thus, $_POST["name"]=><script> input becomes &lt;script&gt; output
    //echo htmlentities($email, ENT_QUOTES, "UTF-8");
    //echo htmlentities($job, ENT_QUOTES, "UTF-8");
    //echo htmlentities($message, ENT_QUOTES, "UTF-8");
    // you only have four input values so i don't use an array

    include "thankyou.php"; //display submitted data or not


} else {
    include "form.php";
}

exit;
?>
Sponsor our Newsletter | Privacy Policy | Terms of Service