Re: Am I missing something?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alright, this may be the problem:

Fatal error: Call to undefined function mysql_real_escape_string() in C:\apache2triad\htdocs\gallery.php on line 10

which is refering to :

$picture = mysql_real_escape_string($picture);


/* never again use direct code from an example in a book, there's always an error */

----- Original Message ----- From: "Alexander" <kurokawa@xxxxxxx>
To: "PHP-DB" <php-db@xxxxxxxxxxxxx>
Sent: Saturday, January 27, 2007 8:13 PM
Subject: Re:  Am I missing something?


No change.

I echod my insert statement and got : INSERT INTO domains ( picture, thumbnail ) values( "$picture", "$thumbnail" )

excatly like that. Shouldn't the values echo as what should be inserted into the database?

----- Original Message ----- From: "Stephen Johnson" <maillists@xxxxxxxxxxxxxxxx>
To: "Alexander" <kurokawa@xxxxxxx>; "PHP-DB" <php-db@xxxxxxxxxxxxx>
Sent: Saturday, January 27, 2007 8:01 PM
Subject: Re:  Am I missing something?


My first thought is that your values in your insert statement are not in
quotes..


         $insert = 'INSERT INTO domains ( picture, thumbnail ) values(
$picture, $thumbnail )';

Should be

$insert = 'INSERT INTO domains ( picture, thumbnail ) values( "$picture",
"$thumbnail")';

Hope that helps.

<?php
/*

Stephen Johnson c | eh
The Lone Coder

http://www.ouradoptionblog.com
Join our journey of adoption

http://www.thelonecoder.com
stephen@xxxxxxxxxxxxxxxx

continuing the struggle against bad code

*/
?>


From: Alexander <kurokawa@xxxxxxx>
Date: Sat, 27 Jan 2007 19:55:17 -0600
To: PHP-DB <php-db@xxxxxxxxxxxxx>
Subject:  Am I missing something?

I fixed my code and it shows up fine now. It says it supposedly enters the data when I input the fields but when I check the MySQL database, the info
isn't there.

Here's the fixed code if you wish to test it:

<html>

<body>

<?php

  function add_to_table( $picture, $thumbnail ) {
         $picture = mysql_real_escape_string($picture);
         $thumbnail = mysql_real_escape_string($thumbnail);

         $user = "user";
         $pass = "password";
         $database = "mydata";

   $link = mysql_connect("localhost", $user, $pass);
        if(!$link) {
          echo 'Error in linking';
        }

         $db = mysql_select_db($database, $link);

         $insert = 'INSERT INTO domains ( picture, thumbnail ) values(
$picture, $thumbnail )';
         $indata = mysql_query( $insert, $link );


    }

    function write_form() {
         echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>";

         echo "<p>Enter url of large picture: <input type='text'
name='picture' />";

         echo "<p>Enter url of thumbnail: <input type='text'
name='thumbnail' />";

         echo "<p><input type='submit' value='Add to Database' />";

         echo "</form>";
    }

         if ( !empty( $_REQUEST['picture'] ) && !empty(
$_REQUEST['thumbnail'] ) ) {
           $input = add_to_table( $_REQUEST['picture'],
$_REQUEST['thumbnail'] );
             if(!input) {
               echo 'Error\!';
             }
             else {
      echo 'Data enter successfully\!';
      $idreturn = mysql_insert_id($input);
      echo 'Image inserted to ID ' . $idreturn;
    }
  }
         else {
           write_form();
   }

?>

</body>

</html>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux