Wrox Programmer Forums
|
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2010, 05:09 PM
Authorized User
 
Join Date: Jan 2010
Posts: 13
Thanks: 2
Thanked 1 Time in 1 Post
Default Beg PHP6-Ch7, pg 180-181

Code is posted below but here is/are the problem(s):

This is the error message I get when I run check_image.php

Fatal error: Call to undefined function mysql_insert_is() in C:\wamp\www\htdocs\check_image.php on line 72


When I view source on the error page this is what I get.

<br />
<b>Notice</b>: Undefined index: uploadfile in <b>C:\wamp\www\htdocs\check_image.php</b> on line <b>10</b><br />
<br />
<b>Notice</b>: Undefined index: caption in <b>C:\wamp\www\htdocs\check_image.php</b> on line <b>37</b><br />
<br />
<b>Notice</b>: Undefined index: username in <b>C:\wamp\www\htdocs\check_image.php</b> on line <b>38</b><br />
<br />
<b>Fatal error</b>: Function name must be a string in <b>C:\wamp\www\htdocs\check_image.php</b> on line <b>39</b><br />

My thanks to anyone who can assist.....

Code:
<?php
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or
    die ('Unable to connect. Check your connection parameters.');
  mysql_select_db('moviesite', $db) or die(mysql_error($db));

//this path is for the image directory
$dir ='C:/wamp/www/htdocs/images';

//ensure uploaded file transfer was successful - line 9
if ($_FILES['uploadfile']['error'] !=UPLOAD_ERR_OK) {
    switch ($_FILES['uploadfile']['error']) {
    case UPLOAD_ERR_INI_SIZE:
        die('The uploaded file exceeds the upload_max_filesize directive ' . 'in php.ini.');
      break;
    case UPLOAD_ERR_FORM_SIZE:
        die('The uploaded file exceeds the MAX_FILE_SIZE directive that ' . 'was specified in the HTML            form');
      break;
    case UPLOAD_ERR_PARTIAL_SIZE:
        die('The uploaded file was only partially uploaded.');
      break;
    case UPLOAD_ERR_NO_FILE:
        die('No file was uploaded.');
      break;
    case UPLOAD_ERR_NO_TMP_DIR:
        die('The server is missing a temporary file.');
      break;
    case UPLOAD_ERR_CANT_WRITE:
        die('The server failed to write the uploaded file to disk.');
      break;
    case UPLOAD_ERR_EXTENSION:
        die('File upload stopped by extension.');
      break;
    }
  }

//get info about the image being uploaded - line 36
$image_caption = $_POST['caption'];
$image_username = $_POST['username'];
$image_date = date('Y-m-d');
list($width, $height, $type, $attr) = 
    getimagesize($_FILES['uploadfile']['tmp_name']);

//make sure the uploaded file is really a supported image - line 42
switch ($type) {
case IMAGETYPE_GIF:
    $image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or
        die('The file you uploaded was not a supported filetype.');
    $ext = '.gif';
    break;
case IMAGETYPE_JPEG:
    $image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or
        die('The file you uploaded was not a supported filetype.');
    $ext = '.jpg';
    break;
case IMAGETYPE_PNG:
    $image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or
        die('The file you uploaded was not a supported filetype.');
    $ext = '.png';
    break;
default:
     die('The file you uploaded was not a supported filetype.');
}

//insert information into image table - line 62
$query = 'INSERT INTO images
    (image_caption, image_username, image_date)
VALUES
    ("' . $image_caption . '", "' . $image_username . '", "' . $image_date . '")';
$result = mysql_query($query, $db) or die (mysql_error($db));

//retrieve the image_id that MYSQL generated automatically when we inserted the new record
$last_id = mysql_insert_is();

//because the id is unique, we can use it as the image name too and to make sure we don't 
//overwrite another image that already exists - line 72
$imagename = $last_id . $ext;

//update the image table now that the final filename is known
$query = 'UPDATE images
    SET image_filename = "' . $imagename .'"
    WHERE image_id = ' . $last_id;
$result = mysql_query($query, $db) or die (mysql_error($db));

//save the image to its final destination - line 81
switch ($type) {
case IMAGETYPE_GIF:
    imagegif($image, $dir . '/' . $imagename);
    break;
case IMAGETYPE_JPEG:
    imagejpeg($image, $dir . '/' . $imagename, 100);
    break;
case IMAGETYPE_PNG:
    imagepng($image, $dir . '/' . $imagename);
    break;
}
imagedestroy($image);
?>
<html>
 <head>
  <title>Here is your picture!</title>
 </head>
 <body>
  <h1>So how does it feel to be famous?</h1>
  <p>Here is the picture upi just uploaded:</p>
   <img src="images/<?php echo $imagename; ?>" style="float:left;">
  <table>
   <tr><td>Image saved as: </td><td><?php echo $imagename; ?></td></tr>
   <tr><td>Image type: </td><td><?php echo $ext; ?></td></tr>
   <tr><td>Image height: </td><td><?php echo $height; ?></td></tr>
   <tr><td>Image width: </td><td><?php echo $width; ?></td></tr>
   <tr><td>Image upload date: </td><td><?php echo $image_date; ?></td></tr>
  </table>
 </body>
</html>
 
Old March 23rd, 2010, 09:10 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

mysql_insert_id(), not mysql_insert_is().
The Following User Says Thank You to PeterPeiGuo For This Useful Post:
drgnhiker (March 23rd, 2010)
 
Old March 23rd, 2010, 09:43 PM
Authorized User
 
Join Date: Jan 2010
Posts: 13
Thanks: 2
Thanked 1 Time in 1 Post
Default Thanks

and thanks again.....i had given up on this and went on to the next set of lessons......i'm going to fix it right now.....Thanks again





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 Beg PHP6 etc..error statement drgnhiker BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 4 February 1st, 2010 03:50 PM
navigation (ch7 of Beg.ASP.NET3.5) wingri ASP.NET 3.5 Basics 3 April 7th, 2008 12:46 AM
Beg DWMX 2004 CH12 progrm crashing pg 434 Roo Dreamweaver (all versions) 7 October 3rd, 2006 01:42 PM
CH7: RegExp Object PG 194 and 195 xZanU BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 5 January 12th, 2006 04:31 PM
Beg Access 2000 VBA - Ch 5 - pg 136 - Library? dmrey73 Access VBA 1 January 18th, 2005 05:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.