473,804 Members | 3,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\wamp\w

1 New Member
m from Romania and I bought the book let yourself, bother with a problem to conduct script 14.2 appear:

The file has been uploaded!

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\wamp\www\scr ipts_named\07\a dd_print.php on line 109

Your submission could not be processed due to a system error.
Where wrong?
Send script component:
mysql_connect.p hp:
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3. // This file contains the database access information for the database.
  4. // This file also establishes a connection to MySQL and selects the database.
  5.  
  6. // Set the database access information as constants.
  7. define ('DB_USER', 'root');
  8.  
  9. define ('DB_HOST', 'localhost');
  10. define ('DB_NAME', 'ecommerce');
  11.  
  12. // Make the connnection and then select the database.
  13.  
  14.  
  15.  
  16. $dbc = mysql_connect (DB_HOST, DB_USER) OR die ('Could not connect to MySQL: ' . mysql_error() );
  17. mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
  18.  
  19. // Create a function for escaping the data.
  20. function escape_data ($data) {
  21.  
  22.  
  23.     // Address Magic Quotes.
  24.     if (ini_get('magic_quotes_gpc')) {
  25.         $data = stripslashes($data);
  26.     }
  27.  
  28.  
  29.  
  30.     // Check for mysql_real_escape_string() support.
  31.     if (function_exists('mysql_real_escape_string')) {
  32.         global $dbc; // Need the connection.
  33.         $data = mysql_real_escape_string (trim($data), $dbc);
  34.     } else {
  35.         $data = mysql_escape_string (trim($data));
  36.     }
  37.  
  38.     // Return the escaped value.   
  39.     return $data;
  40.  
  41. } // End of function.
  42. ?>
add_print.php:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5.     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  6.     <title>Add a Print</title>
  7. </head>
  8. <body>
  9. <?php 
  10. // This page allows the administrator to add a print (product).
  11.  
  12. require_once ('mysql_connect.php'); // Connect to the database.
  13.  
  14. if (isset($_POST['submitted'])) { // Check if the form has been submitted.
  15.  
  16.     // Validate the print_name, image, artist (existing or first_name, last_name, middle_name), size, price, and description.
  17.  
  18.     // Check for a print name.
  19.     if (!empty($_POST['print_name'])) {
  20.         $pn = escape_data($_POST['print_name']);
  21.     } else {
  22.         $pn = FALSE;
  23.         echo '<p><font color="red">Please enter the print\'s name!</font></p>';
  24.     }
  25.  
  26.     // Check for an image.
  27.     if (is_uploaded_file ($_FILES['image']['tmp_name'])) {
  28.         if (move_uploaded_file($_FILES['image']['tmp_name'], "move_uploads{$_FILES['image']['name']}")) { // Move the file over.
  29.  
  30.             echo '<p>The file has been uploaded!</p>';
  31.  
  32.         } else { // Couldn't move the file over.
  33.             echo '<p><font color="red">The file could not be moved.</font></p>';
  34.             $i = FALSE;
  35.         }
  36.         $i = $_FILES['image']['name'];
  37.     } else {
  38.         $i = FALSE;
  39.     }
  40.  
  41.     // Check for a size (not required).
  42.     if (!empty($_POST['size'])) {
  43.         $s = escape_data($_POST['size']);
  44.     } else {
  45.         $s = '<i>Size information not available.</i>';
  46.     }
  47.  
  48.     // Check for a price.
  49.     if (is_numeric($_POST['price'])) {
  50.         $p = (float) $_POST['price'];
  51.     } else {
  52.         $p = FALSE;
  53.         echo '<p><font color="red">Please enter the print\'s price!</font></p>';
  54.     }
  55.  
  56.     // Check for a description (not required).
  57.     if (!empty($_POST['description'])) {
  58.         $d = escape_data($_POST['description']);
  59.     } else {
  60.         $d = '<i>No description available.</i>';
  61.     }
  62.  
  63.     // Validate the artist.
  64.     if (!empty($_POST['artist']) == 'new') {
  65.  
  66.         // If it's a new artist, add the artist to the database.
  67.         $query = 'INSERT INTO artists (first_name, middle_name, last_name) VALUES (';       
  68.  
  69.         if (!empty($_POST['first_name'])) {
  70.             $query .= "'" . escape_data($_POST['first_name']) . "', ";
  71.         } else {
  72.             $query .= 'NULL, ';
  73.         }
  74.  
  75.         if (!empty($_POST['middle_name'])) {
  76.             $query .= "'" . escape_data($_POST['middle_name']) . "', ";
  77.         } else {
  78.             $query .= 'NULL, ';
  79.         }
  80.  
  81.         // Check for a last_name.
  82.         if (!empty($_POST['last_name'])) {
  83.             $query .= "'" . escape_data($_POST['last_name']) . "')";
  84.  
  85.  
  86.  
  87.  
  88.  
  89.             $result = mysql_query ($query); // Run the query.
  90.             $a = mysql_insert_id(); // Get the artist ID.
  91.  
  92.  
  93.         } else { // No last name value.
  94.             $a = FALSE;
  95.             echo '<p><font color="red">Please enter the artist\'s name!</font></p>';
  96.         }
  97.  
  98.     } elseif ( (!empty($_POST['artist']) == 'existing') && ($_POST['existing'] > 0)) { // Existing artist.
  99.         $a = (int) $_POST['existing'];
  100.     } else { // No artist selected.
  101.         $a = FALSE;
  102.         echo '<p><font color="red">Please enter or select the print\'s artist!</font></p>';
  103.     }
  104.  
  105.     if ($pn && $p && $a && $i) { // If everything's OK.
  106.  
  107.         // Add the print to the database.
  108.         $query = "INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES ($a, '$pn', $p, '$s', '$d', '$i')";
  109.          if ($result = mysqli_query ($dbc, $query)){ // Worked.
  110.             echo '<p>The print has been added.</p>';
  111.         } else { // If the query did not run OK.
  112.             echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>';
  113.         }
  114.  
  115.     } else { // Failed a test.
  116.             echo '<p><font color="red">Please click "back" and try again.</font></p>';
  117.     }
  118.  
  119. } else { // Display the form.
  120.     ?>
  121.  
  122.     <form enctype="multipart/form-data" action="add_print.php" method="post">
  123.  
  124.         <input type="hidden" name="MAX_FILE_SIZE" value="524288">
  125.  
  126.         <fieldset><legend>Fill out the form to add a print to the catalog:</legend>
  127.  
  128.         <p><b>Print Name:</b> <input type="text" name="print_name" size="30" maxlength="60" /></p>
  129.  
  130.         <p><b>Image:</b> <input type="file" name="image" /> <small>The file name should not include spaces or other invalid characters and should have a file extension.</small></p>
  131.  
  132.         <p><b>Artist:</b>
  133.         <p><input type="radio" name="artist" value="existing" /> Existing =>
  134.         <select name="existing"><option>Select One</option>
  135.         <?php // Retrieve all the artists and add to the pull-down menu.
  136.         $query = "SELECT artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS name FROM artists ORDER BY last_name, first_name ASC";       
  137.         $result = mysqli_query ($dbc, $query);
  138.         while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {
  139.             echo "<option value=\"{$row['artist_id']}\">{$row['name']}</option>\n";
  140.         }
  141.         mysqli_close($dbc); // Close the database connection.
  142.         ?>
  143.         </select></p>
  144.         <p>
  145.         <input type="radio" name="artist" value="new" /> New =>
  146.         First Name: <input type="text" name="first_name" size="10" maxlength="20" />
  147.         Middle Name: <input type="text" name="middle_name" size="10" maxlength="20" />
  148.         Last Name: <input type="text" name="last_name" size="10" maxlength="30" />
  149.         </p>
  150.  
  151.         <p><b>Price:</b> <input type="text" name="price" size="10" maxlength="10" /> <small>Do not include the dollar sign or commas.</small></p>
  152.  
  153.         <p><b>Size:</b> <input type="text" name="size" size="30" maxlength="60" /></p>
  154.  
  155.         <p><b>Description:</b> <textarea name="description" cols="40" rows="5"></textarea></p>
  156.  
  157.         </fieldset>
  158.  
  159.         <div align="center"><input type="submit" name="submit" value="Submit" /></div>
  160.         <input type="hidden" name="submitted" value="TRUE" />
  161.  
  162.     </form>
  163. <?php
  164. } // End of main conditional.
  165. ?>
  166. </body>
  167. </html>
It has to be happy if you give an answer
May 31 '10 #1
1 9944
Dormilich
8,658 Recognized Expert Moderator Expert
mysql_* and mysqli_* functions are not interchangeable . if you connect via mysql_connect() you have to query via mysql_query() (resp. mysqli_connect( ) & mysqli_query())
May 31 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
12864
by: Mini Mouse | last post by:
Hiya folks, I'm getting the following error(s) below and I'm at a bit of a loss as to how to correct it. When I give it a parameter it then complains it needs two parameters and the second one being an integer or something like that. Warning: domdocument() expects at least 1 parameter, 0 given in orders.php on line 157
2
9130
by: JÿGius³ vs ::NRG::ius | last post by:
Hi all. I have this script ----------------------------------------------------------- <?php $doc = new DOMDocument(); $doc->load('books.xml'); echo $doc->saveXML(); ?>
1
6110
by: malayappa | last post by:
Hi All here is the error what i m getting Warning: domdocument::domdocument() expects parameter 2 to be long, string given in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sample\mssql.php on line 47 Here is My code <?php /*session_start(); set_time_limit(0); error_reporting(E_ALL);*/
3
15548
by: ghjk | last post by:
I want to expire user account in my php application. Below is my code . But i got "mktime() expects parameter 6 to be long, string given in ". Could anyone tell me what is wrong? Please.. list($year, $month, $day) = split('', $Valid_From); $daystoadd="$Validity_Period"; $hours=$daystoadd * 24; $newdate=date("Y-m-d", mktime($hours, 0, 0, $month, $day, $year)); $today = date("Y-m-d"); if($newdate>$today)...
7
5166
by: roseple | last post by:
Hi, can anyone please help me why I got this error every I uploaded files. Error: Here is the code on the said warning message: # Gather all required data $name = mysql_real_escape_string($dbLink, $_FILES); $mime = mysql_real_escape_string($dbLink, $_FILES); $size = $_FILES;
1
7932
Paul NIcolai Sunga
by: Paul NIcolai Sunga | last post by:
what is wrong with my code? $Link = mysqli_connect("localhost","root","tupi"); if (!$Link) { die("Could not connect: " . mysql_error()); } mysql_select_db("registration_form", $Link);
12
1922
by: Rana Chakra | last post by:
<?php $username="root"; $password=""; $database="lko_phone"; $host="localhost"; $msg=""; mysql_connect($host,$username,$password); @mysql_select_db($database); if($_SERVER == "POST")
3
3293
by: mocha | last post by:
I have this error message --> Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\script.php on line 24 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'date']; ?>','3:00am')' at line 1 The one that i bold and underline is Line 24 <?php session_start();
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.