<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Help with code of database Ecommerce!</title>
        <description> Hello everyone, good night.

I&amp;#039;m making a database for ecommerce called &amp;quot;ecommerce&amp;quot;.

But when I was connecting the database (msqli_connect.php) with the add_artist.php file, I get errors.

My question is: How can I fix them?

I greatly appreciate your help.



mysqli_connect.php

&amp;lt;?php # Script 9.2 - mysqli_connect.php

 // This file contains the database access information.
 // This file also establishes a connection to MySQL,
 // selects the database, and sets the encoding.
// Set the database access information as constants:
DEFINE (&amp;#039;DB_USER&amp;#039;, &amp;#039;username&amp;#039;); DEFINE (&amp;#039;DB_PASSWORD&amp;#039;, &amp;#039;Quencyjones79&amp;#039;);
DEFINE (&amp;#039;DB_HOST&amp;#039;, &amp;#039;localhost&amp;#039;);
DEFINE (&amp;#039;DB_NAME&amp;#039;, &amp;#039;ecommerce&amp;#039;);

 // Make the connection:
 $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die (&amp;#039;Could not connect to
MySQL: &amp;#039; . mysqli_connect_error( ) );

 // Set the encoding...
mysqli_set_charset($dbc, &amp;#039;utf8&amp;#039;);


add_artist.php

&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&amp;quot;UTF-8&amp;quot;&amp;gt;
    &amp;lt;title&amp;gt;Add an Artist&amp;lt;/title&amp;gt;
    &amp;lt;meta charset=&amp;quot;UTF-8&amp;quot;&amp;gt;
    &amp;lt;meta name=&amp;quot;description&amp;quot; content=&amp;quot;Home page&amp;quot;&amp;gt;
    &amp;lt;meta name=&amp;quot;keywords&amp;quot; content=&amp;quot;ecommerce&amp;quot;&amp;gt;
    &amp;lt;meta name=&amp;quot;author&amp;quot; content=&amp;quot;José Moreira&amp;quot;&amp;gt;
    &amp;lt;meta name=&amp;quot;viewport&amp;quot; content=&amp;quot;width=device-width, initial-scale=1&amp;quot;&amp;gt;
&amp;lt;/head&amp;gt;

 &amp;lt;body&amp;gt;
 &amp;lt;?php # Script 19.1 - add_artist.php
 // This page allows the administrator to
add an artist.

 if ($_SERVER[&amp;#039;REQUEST_METHOD&amp;#039;] = = &amp;#039;POST&amp;#039;)
{ // Handle the form.

 // Validate the first and middle
names (neither required):
 $fn = (!empty($_POST[&amp;#039;first_name&amp;#039;])) ?
trim($_POST[&amp;#039;first_name&amp;#039;]) : NULL;
 $mn = (!empty($_POST[&amp;#039;middle_name&amp;#039;])) ?
trim($_POST[&amp;#039;middle_name&amp;#039;]) : NULL;

 // Check for a last_name...
 if (!empty($_POST[&amp;#039;last_name&amp;#039;])) {

 $ln = trim($_POST[&amp;#039;last_name&amp;#039;]);

 // Add the artist to the database:
 require (&amp;#039;../../mysqli_connect.
php&amp;#039;);
 $q = &amp;#039;INSERT INTO artists (first_
name, middle_name, last_name)
VALUES (?, ?, ?)&amp;#039;;
 $stmt = mysqli_prepare($dbc, $q);
 mysqli_stmt_bind_param($stmt,
&amp;#039;sss&amp;#039;, $fn, $mn, $ln);
 mysqli_stmt_execute($stmt);

 // Check the results....
 if (mysqli_stmt_affected_
rows($stmt) = = 1) {
 echo &amp;#039;&amp;lt;p&amp;gt;The artist has been
added.&amp;lt;/p&amp;gt;&amp;#039;;
 $_POST = array( );

 } else { // Error!
     $error = &amp;#039;The new artist could not be added to the database!&amp;#039;;
     }
    
     // Close this prepared statement:
     mysqli_stmt_close($stmt);
     mysqli_close($dbc); // Close the database connection.
    
     } else { // No last name value.
    $error = &amp;#039;Please enter the artist\&amp;#039;s name!&amp;#039;;
    }
    
     } // End of the submission IF.
    
     // Check for an error and print it:
     if (isset($error)) {
     echo &amp;#039;&amp;lt;h1&amp;gt;Error!&amp;lt;/h1&amp;gt;
     &amp;lt;p style=&amp;quot;font-weight: bold; color: #C00&amp;quot;&amp;gt;&amp;#039; . $error . &amp;#039; Please try again.&amp;lt;/p&amp;gt;&amp;#039;;
    }
   
     // Display the form...
     ?&amp;gt;
     &amp;lt;h1&amp;gt;Add a Print&amp;lt;/h1&amp;gt;
     &amp;lt;form action=&amp;quot;add_artist.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;
   
     &amp;lt;fieldset&amp;gt;&amp;lt;legend&amp;gt;Fill out the form to add an artist:&amp;lt;/legend&amp;gt;
    
    &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;First Name:&amp;lt;/b&amp;gt; &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;first_name&amp;quot; size=&amp;quot;10&amp;quot; maxlength=&amp;quot;20&amp;quot;
    value=&amp;quot;&amp;lt;?php if (isset($_POST[&amp;#039;first_name&amp;#039;])) echo $_POST[&amp;#039;first_name&amp;#039;]; ?&amp;gt;&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
     &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Middle Name:&amp;lt;/b&amp;gt; &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;middle_name&amp;quot; size=&amp;quot;10&amp;quot; maxlength=&amp;quot;20&amp;quot;
    value=&amp;quot;&amp;lt;?php if (isset($_POST[&amp;#039;middle_name&amp;#039;])) echo $_POST[&amp;#039;middle_name&amp;#039;]; ?&amp;gt;&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Last Name:&amp;lt;/b&amp;gt; &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;last_name&amp;quot; size=&amp;quot;10&amp;quot; maxlength=&amp;quot;40&amp;quot; value=&amp;quot;&amp;lt;?php
    if (isset($_POST[&amp;#039;last_name&amp;#039;])) echo $_POST[&amp;#039;last_name&amp;#039;]; ?&amp;gt;&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
    
    &amp;lt;/fieldset&amp;gt;
   
    &amp;lt;div align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;submit&amp;quot; value=&amp;quot;Submit&amp;quot; /&amp;gt;&amp;lt;/div&amp;gt;
   
    &amp;lt;/form&amp;gt;
   
   &amp;lt;/body&amp;gt;
     &amp;lt;/html&amp;gt;</description>
        <link>https://www.phorum.org/support/read.php?61,162668,162668#msg-162668</link>
        <lastBuildDate>Tue, 10 Nov 2026 05:49:44 -0600</lastBuildDate>
        <generator>Phorum 6.0.4</generator>
        <item>
            <guid>https://www.phorum.org/support/read.php?61,162668,162670#msg-162670</guid>
            <title>Re: Help with code of database Ecommerce!</title>
            <link>https://www.phorum.org/support/read.php?61,162668,162670#msg-162670</link>
            <description><![CDATA[ First: do not show your login credentials!<br />
<br />
According your picture you do not go to your page via your XAMPP webserver? something like localhost/yourpage. Instead I see you are going directly to your file? That way you bypass your PHP engine?]]></description>
            <dc:creator>Terradon</dc:creator>
            <category>Phorum Support</category>
            <pubDate>Tue, 25 Jan 2022 01:00:50 -0600</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?61,162668,162668#msg-162668</guid>
            <title>Help with code of database Ecommerce!</title>
            <link>https://www.phorum.org/support/read.php?61,162668,162668#msg-162668</link>
            <description><![CDATA[ Hello everyone, good night.<br />
<br />
I&#039;m making a database for ecommerce called &quot;ecommerce&quot;.<br />
<br />
But when I was connecting the database (msqli_connect.php) with the add_artist.php file, I get errors.<br />
<br />
My question is: How can I fix them?<br />
<br />
I greatly appreciate your help.<br />
<br />
<br />
<br />
mysqli_connect.php<br />
<br />
&lt;?php # Script 9.2 - mysqli_connect.php<br />
<br />
 // This file contains the database access information.<br />
 // This file also establishes a connection to MySQL,<br />
 // selects the database, and sets the encoding.<br />
// Set the database access information as constants:<br />
DEFINE (&#039;DB_USER&#039;, &#039;username&#039;); DEFINE (&#039;DB_PASSWORD&#039;, &#039;Quencyjones79&#039;);<br />
DEFINE (&#039;DB_HOST&#039;, &#039;localhost&#039;);<br />
DEFINE (&#039;DB_NAME&#039;, &#039;ecommerce&#039;);<br />
<br />
 // Make the connection:<br />
 $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die (&#039;Could not connect to<br />
MySQL: &#039; . mysqli_connect_error( ) );<br />
<br />
 // Set the encoding...<br />
mysqli_set_charset($dbc, &#039;utf8&#039;);<br />
<br />
<br />
add_artist.php<br />
<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;meta charset=&quot;UTF-8&quot;&gt;<br />
    &lt;title&gt;Add an Artist&lt;/title&gt;<br />
    &lt;meta charset=&quot;UTF-8&quot;&gt;<br />
    &lt;meta name=&quot;description&quot; content=&quot;Home page&quot;&gt;<br />
    &lt;meta name=&quot;keywords&quot; content=&quot;ecommerce&quot;&gt;<br />
    &lt;meta name=&quot;author&quot; content=&quot;José Moreira&quot;&gt;<br />
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br />
&lt;/head&gt;<br />
<br />
 &lt;body&gt;<br />
 &lt;?php # Script 19.1 - add_artist.php<br />
 // This page allows the administrator to<br />
add an artist.<br />
<br />
 if ($_SERVER[&#039;REQUEST_METHOD&#039;] = = &#039;POST&#039;)<br />
{ // Handle the form.<br />
<br />
 // Validate the first and middle<br />
names (neither required):<br />
 $fn = (!empty($_POST[&#039;first_name&#039;])) ?<br />
trim($_POST[&#039;first_name&#039;]) : NULL;<br />
 $mn = (!empty($_POST[&#039;middle_name&#039;])) ?<br />
trim($_POST[&#039;middle_name&#039;]) : NULL;<br />
<br />
 // Check for a last_name...<br />
 if (!empty($_POST[&#039;last_name&#039;])) {<br />
<br />
 $ln = trim($_POST[&#039;last_name&#039;]);<br />
<br />
 // Add the artist to the database:<br />
 require (&#039;../../mysqli_connect.<br />
php&#039;);<br />
 $q = &#039;INSERT INTO artists (first_<br />
name, middle_name, last_name)<br />
VALUES (?, ?, ?)&#039;;<br />
 $stmt = mysqli_prepare($dbc, $q);<br />
 mysqli_stmt_bind_param($stmt,<br />
&#039;sss&#039;, $fn, $mn, $ln);<br />
 mysqli_stmt_execute($stmt);<br />
<br />
 // Check the results....<br />
 if (mysqli_stmt_affected_<br />
rows($stmt) = = 1) {<br />
 echo &#039;&lt;p&gt;The artist has been<br />
added.&lt;/p&gt;&#039;;<br />
 $_POST = array( );<br />
<br />
 } else { // Error!<br />
     $error = &#039;The new artist could not be added to the database!&#039;;<br />
     }<br />
    <br />
     // Close this prepared statement:<br />
     mysqli_stmt_close($stmt);<br />
     mysqli_close($dbc); // Close the database connection.<br />
    <br />
     } else { // No last name value.<br />
    $error = &#039;Please enter the artist\&#039;s name!&#039;;<br />
    }<br />
    <br />
     } // End of the submission IF.<br />
    <br />
     // Check for an error and print it:<br />
     if (isset($error)) {<br />
     echo &#039;&lt;h1&gt;Error!&lt;/h1&gt;<br />
     &lt;p style=&quot;font-weight: bold; color: #C00&quot;&gt;&#039; . $error . &#039; Please try again.&lt;/p&gt;&#039;;<br />
    }<br />
   <br />
     // Display the form...<br />
     ?&gt;<br />
     &lt;h1&gt;Add a Print&lt;/h1&gt;<br />
     &lt;form action=&quot;add_artist.php&quot; method=&quot;post&quot;&gt;<br />
   <br />
     &lt;fieldset&gt;&lt;legend&gt;Fill out the form to add an artist:&lt;/legend&gt;<br />
    <br />
    &lt;p&gt;&lt;b&gt;First Name:&lt;/b&gt; &lt;input type=&quot;text&quot; name=&quot;first_name&quot; size=&quot;10&quot; maxlength=&quot;20&quot;<br />
    value=&quot;&lt;?php if (isset($_POST[&#039;first_name&#039;])) echo $_POST[&#039;first_name&#039;]; ?&gt;&quot; /&gt;&lt;/p&gt;<br />
     &lt;p&gt;&lt;b&gt;Middle Name:&lt;/b&gt; &lt;input type=&quot;text&quot; name=&quot;middle_name&quot; size=&quot;10&quot; maxlength=&quot;20&quot;<br />
    value=&quot;&lt;?php if (isset($_POST[&#039;middle_name&#039;])) echo $_POST[&#039;middle_name&#039;]; ?&gt;&quot; /&gt;&lt;/p&gt;<br />
    &lt;p&gt;&lt;b&gt;Last Name:&lt;/b&gt; &lt;input type=&quot;text&quot; name=&quot;last_name&quot; size=&quot;10&quot; maxlength=&quot;40&quot; value=&quot;&lt;?php<br />
    if (isset($_POST[&#039;last_name&#039;])) echo $_POST[&#039;last_name&#039;]; ?&gt;&quot; /&gt;&lt;/p&gt;<br />
    <br />
    &lt;/fieldset&gt;<br />
   <br />
    &lt;div align=&quot;center&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;&lt;/div&gt;<br />
   <br />
    &lt;/form&gt;<br />
   <br />
   &lt;/body&gt;<br />
     &lt;/html&gt;]]></description>
            <dc:creator>Jose_Moreira</dc:creator>
            <category>Phorum Support</category>
            <pubDate>Mon, 24 Jan 2022 15:57:20 -0600</pubDate>
        </item>
    </channel>
</rss>
