José Moreira Posted January 24, 2022 at 10:37 PM Report Share #625284 Posted January 24, 2022 at 10:37 PM Olá a todos. Estou a fazer uma base de dados "ecommerce" contudo quando estava a fazer a ligação do ficheiro mysqli_connect.php com o ficheiro add_artist.php, estou a ter erros no segundo ficheiro. Em baixo envio o código fonte e algumas imagens para me ajudarem. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Add an Artist</title> <meta charset="UTF-8"> <meta name="description" content="Home page"> <meta name="keywords" content="ecommerce"> <meta name="author" content="José Moreira"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <?php # Script 19.1 - add_artist.php // This page allows the administrator to add an artist. if ($_SERVER['REQUEST_METHOD'] = = 'POST') { // Handle the form. // Validate the first and middle names (neither required): $fn = (!empty($_POST['first_name'])) ? trim($_POST['first_name']) : NULL; $mn = (!empty($_POST['middle_name'])) ? trim($_POST['middle_name']) : NULL; // Check for a last_name... if (!empty($_POST['last_name'])) { $ln = trim($_POST['last_name']); // Add the artist to the database: require ('../../mysqli_connect. php'); $q = 'INSERT INTO artists (first_ name, middle_name, last_name) VALUES (?, ?, ?)'; $stmt = mysqli_prepare($dbc, $q); mysqli_stmt_bind_param($stmt, 'sss', $fn, $mn, $ln); mysqli_stmt_execute($stmt); // Check the results.... if (mysqli_stmt_affected_ rows($stmt) = = 1) { echo '<p>The artist has been added.</p>'; $_POST = array( ); } else { // Error! $error = 'The new artist could not be added to the database!'; } // Close this prepared statement: mysqli_stmt_close($stmt); mysqli_close($dbc); // Close the database connection. } else { // No last name value. $error = 'Please enter the artist\'s name!'; } } // End of the submission IF. // Check for an error and print it: if (isset($error)) { echo '<h1>Error!</h1> <p style="font-weight: bold; color: #C00">' . $error . ' Please try again.</p>'; } // Display the form... ?> <h1>Add a Print</h1> <form action="add_artist.php" method="post"> <fieldset><legend>Fill out the form to add an artist:</legend> <p><b>First Name:</b> <input type="text" name="first_name" size="10" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p><b>Middle Name:</b> <input type="text" name="middle_name" size="10" maxlength="20" value="<?php if (isset($_POST['middle_name'])) echo $_POST['middle_name']; ?>" /></p> <p><b>Last Name:</b> <input type="text" name="last_name" size="10" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /></div> </form> </body> </html> mysqli_connect.php <?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 ('DB_USER', 'username'); DEFINE ('DB_PASSWORD', 'Quencyjones79'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'ecommerce'); // Make the connection: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error( ) ); // Set the encoding... mysqli_set_charset($dbc, 'utf8'); Agradeço imenso a sua ajuda. Link to comment Share on other sites More sharing options...
M6 Posted January 25, 2022 at 08:29 AM Report Share #625285 Posted January 25, 2022 at 08:29 AM Se não disseres qual é o erro, ninguém vai conseguir ajudar-te. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
M6 Posted January 25, 2022 at 12:54 PM Report Share #625288 Posted January 25, 2022 at 12:54 PM @José Moreira é mais fácil e simples fazer copy-paste do erro para aqui do que colocar imagens. Basicamente, pelo que consegui perceber (o rar não abriu não sei muito bem porquê), mas pelas imagens (ecommer7.jpg) o teu problema não é com a ligação à base de dados mas sim com o URL. Estás a apontar para ecommerce/add_artist.php e creio que deve ser ecommerce/admin/add_artist.php (isto se o apache estiver a apontar para c:\xampp\htdocs\ecommerce\htdocs, porque se não estiver, o caminho deve ser algo como ecommerce/hrdocs/admin/add_artist.php 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now