473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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\scripts_named\07\add_print.php on line 109

Your submission could not be processed due to a system error.
Where wrong?
Send script component:
mysql_connect.php:
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 9881
Dormilich
8,658 Expert Mod 8TB
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
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...
2
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
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...
3
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.. ...
7
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 =...
1
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()); }...
12
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
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.