I can"t solve the error in the code

I can"t solve the error in the code

am 28.01.2007 01:09:41 von Alexander

------=_NextPart_000_0005_01C7423E.510B0230
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I'm writing a script for uploading into a database urls for a picture =
and its thumbnail, but for some reason when I test it out the page =
doesn't load, and not even the errors appear. Please help, here's the =
code:






$user =3D "userone";
$pass =3D "password";
$database =3D "mydatabase";

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

$db =3D mysql_select_db($database, $link);
if(!$db) {
echo 'Error in DB';
}
else {

if ( !empty( $_REQUEST['picture'] ) && !empty( =
$_REQUEST['thumbnail'] ) ) {
$input =3D add_to_table( $_REQUEST['picture'], =
$_REQUEST['thumbnail'] );
if(!input) {
echo 'Error\!';
}
else {
echo 'Data enter successfully\!';
}
}
else {
write_form();
}

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

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

}

function write_form() {
print <<
form method=3D'post' action=3D'{$_SERVER['PHP_SELF']}'>

Enter url of large picture: name=3D'picture' />

Enter url of thumbnail: name=3D'thumbnail' />

echo '

'

;
FORM;
}
?>




------=_NextPart_000_0005_01C7423E.510B0230--

Re: I can"t solve the error in the code

am 28.01.2007 02:36:28 von Alexander

------=_NextPart_000_001C_01C7424A.703827D0
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable

thank you. That appears to have solved it.
----- Original Message -----=20
From: Santiago Zarate=20
To: Alexander=20
Sent: Saturday, January 27, 2007 7:26 PM
Subject: Re: [PHP-DB] I can't solve the error in the code


if(!input) { // an error here... should be !$input or even =
if(!add_to_table( $_REQUEST['picture'], $_REQUEST['thumbnail'] ))
echo 'Error\!';
}


Also you're calling a function that isn't created yet according with =
your code, also i dont see=20
Also in your function add_to_table, has some errors too... like you're =
NOT calling a db conection from it... and i guess it should... since i =
have to do it with classes... when it comes to functions... you should =
too...=20

for your write_form code... i think youre using your code wrong...

also check here: http://ve.php.net/manual/en/function.print.php


there might be more errors... lñemme do a fast debug here:=20



santiago@469:~$ nano php.php
santiago@469:~$ php -f php.php

Parse error: syntax error, unexpected $end in /home/santiago/php.php =
on line 69


that means there's an missing "}" somewhere... if youre on linux... =
install php cli and use it to debug... (Or use bluefish that is way more =
easy) and quanta to build your code... if you're on windows... well set =
your ini to E_ALL, then choose eitther using console for PHP and load =
the file... or use your browser and run the script until it runs fine =
without errors... if you're using a shared host... create a error =
function that logs everything into a file... might save you lots of =
time...=20


2007/1/27, Alexander :
I'm writing a script for uploading into a database urls for a =
picture and its thumbnail, but for some reason when I test it out the =
page doesn't load, and not even the errors appear. Please help, here's =
the code:=20






$user =3D "userone";
$pass =3D "password";
$database =3D "mydatabase";

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

$db =3D mysql_select_db($database, $link);
if(!$db) {
echo 'Error in DB';
}
else {

if ( !empty( $_REQUEST['picture'] ) && !empty( =
$_REQUEST['thumbnail'] ) ) {
$input =3D add_to_table( $_REQUEST['picture'], =
$_REQUEST['thumbnail'] );
if(!input) {=20
echo 'Error\!';
}
else {
echo 'Data enter successfully\!';
}
}
else {
write_form();
}

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

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

}

function write_form() {
print <<
form method=3D'post' action=3D'{$_SERVER['PHP_SELF']}'>=20

Enter url of large picture: name=3D'picture' />

Enter url of thumbnail: name=3D'thumbnail' />=20

echo '

/>'

;
FORM;
}
?>







------=_NextPart_000_001C_01C7424A.703827D0--

Am I missing something?

am 28.01.2007 02:55:17 von Alexander

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:






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 "

";

echo "

Enter url of large picture: name='picture' />";

echo "

Enter url of thumbnail: name='thumbnail' />";

echo "

";

echo "

";
}

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();
}

?>





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

Re: Am I missing something?

am 28.01.2007 03:01:52 von Stephen Johnson

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.

/*

Stephen Johnson c | eh
The Lone Coder

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

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

continuing the struggle against bad code

*/
?>


> From: Alexander
> Date: Sat, 27 Jan 2007 19:55:17 -0600
> To: PHP-DB
> Subject: [PHP-DB] 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:
>
>
>
>
>
> >
> 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 "

";
>
> echo "

Enter url of large picture: > name='picture' />";
>
> echo "

Enter url of thumbnail: > name='thumbnail' />";
>
> echo "

";
>
> echo "

";
> }
>
> 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();
> }
>
> ?>
>
>
>
>
>
> --
> 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

Re: Am I missing something?

am 28.01.2007 03:13:37 von Alexander

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"
To: "Alexander" ; "PHP-DB"
Sent: Saturday, January 27, 2007 8:01 PM
Subject: Re: [PHP-DB] 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.
>
> > /*
>
> Stephen Johnson c | eh
> The Lone Coder
>
> http://www.ouradoptionblog.com
> Join our journey of adoption
>
> http://www.thelonecoder.com
> stephen@thelonecoder.com
>
> continuing the struggle against bad code
>
> */
> ?>
>
>
>> From: Alexander
>> Date: Sat, 27 Jan 2007 19:55:17 -0600
>> To: PHP-DB
>> Subject: [PHP-DB] 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:
>>
>>
>>
>>
>>
>> >>
>> 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 "

";
>>
>> echo "

Enter url of large picture: >> name='picture' />";
>>
>> echo "

Enter url of thumbnail: >> name='thumbnail' />";
>>
>> echo "

";
>>
>> echo "

";
>> }
>>
>> 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();
>> }
>>
>> ?>
>>
>>
>>
>>
>>
>> --
>> 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

Re: Am I missing something?

am 28.01.2007 03:17:54 von Alexander

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"
To: "PHP-DB"
Sent: Saturday, January 27, 2007 8:13 PM
Subject: Re: [PHP-DB] 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"
> To: "Alexander" ; "PHP-DB"
> Sent: Saturday, January 27, 2007 8:01 PM
> Subject: Re: [PHP-DB] 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.
>>
>> >> /*
>>
>> Stephen Johnson c | eh
>> The Lone Coder
>>
>> http://www.ouradoptionblog.com
>> Join our journey of adoption
>>
>> http://www.thelonecoder.com
>> stephen@thelonecoder.com
>>
>> continuing the struggle against bad code
>>
>> */
>> ?>
>>
>>
>>> From: Alexander
>>> Date: Sat, 27 Jan 2007 19:55:17 -0600
>>> To: PHP-DB
>>> Subject: [PHP-DB] 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:
>>>
>>>
>>>
>>>
>>>
>>> >>>
>>> 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 "

";
>>>
>>> echo "

Enter url of large picture: >>> name='picture' />";
>>>
>>> echo "

Enter url of thumbnail: >>> name='thumbnail' />";
>>>
>>> echo "

";
>>>
>>> echo "

";
>>> }
>>>
>>> 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();
>>> }
>>>
>>> ?>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> 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

Re: Am I missing something?

am 28.01.2007 03:24:08 von Stephen Johnson

What version of php are using? It is odd that mysql_real_escape_string is
undefined..

Alternately you could addslashes...
Hope this helps

/*

Stephen Johnson c | eh
The Lone Coder

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

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

continuing the struggle against bad code

*/
?>


> From: Alexander
> Date: Sat, 27 Jan 2007 20:17:54 -0600
> To: PHP-DB
> Subject: Re: [PHP-DB] Am I missing something?
>
> 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"
> To: "PHP-DB"
> Sent: Saturday, January 27, 2007 8:13 PM
> Subject: Re: [PHP-DB] 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"
>> To: "Alexander" ; "PHP-DB"
>> Sent: Saturday, January 27, 2007 8:01 PM
>> Subject: Re: [PHP-DB] 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.
>>>
>>> >>> /*
>>>
>>> Stephen Johnson c | eh
>>> The Lone Coder
>>>
>>> http://www.ouradoptionblog.com
>>> Join our journey of adoption
>>>
>>> http://www.thelonecoder.com
>>> stephen@thelonecoder.com
>>>
>>> continuing the struggle against bad code
>>>
>>> */
>>> ?>
>>>
>>>
>>>> From: Alexander
>>>> Date: Sat, 27 Jan 2007 19:55:17 -0600
>>>> To: PHP-DB
>>>> Subject: [PHP-DB] 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:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> >>>>
>>>> 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 "

";
>>>>
>>>> echo "

Enter url of large picture: >>>> name='picture' />";
>>>>
>>>> echo "

Enter url of thumbnail: >>>> name='thumbnail' />";
>>>>
>>>> echo "

";
>>>>
>>>> echo "

";
>>>> }
>>>>
>>>> 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();
>>>> }
>>>>
>>>> ?>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> 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
>

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

Re: Am I missing something?

am 28.01.2007 03:29:26 von Niel Archer

Hi

you need to change this:

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

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

variables are only interpreted inside double quoted strings. Within
single quotes, everything is taken exactly as it appears.


Niel

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

Re: Am I missing something?

am 28.01.2007 03:31:25 von Alexander

I'm using PHP 5, I'm running this off of my personal laptop so I downloaded
ApacheTriad2
----- Original Message -----
From: "Stephen Johnson"
To: "Alexander" ; "PHP-DB"
Sent: Saturday, January 27, 2007 8:24 PM
Subject: Re: [PHP-DB] Am I missing something?


> What version of php are using? It is odd that mysql_real_escape_string is
> undefined..
>
> Alternately you could addslashes...
> Hope this helps
>
> > /*
>
> Stephen Johnson c | eh
> The Lone Coder
>
> http://www.ouradoptionblog.com
> Join our journey of adoption
>
> http://www.thelonecoder.com
> stephen@thelonecoder.com
>
> continuing the struggle against bad code
>
> */
> ?>
>
>
>> From: Alexander
>> Date: Sat, 27 Jan 2007 20:17:54 -0600
>> To: PHP-DB
>> Subject: Re: [PHP-DB] Am I missing something?
>>
>> 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"
>> To: "PHP-DB"
>> Sent: Saturday, January 27, 2007 8:13 PM
>> Subject: Re: [PHP-DB] 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"
>>> To: "Alexander" ; "PHP-DB"
>>> Sent: Saturday, January 27, 2007 8:01 PM
>>> Subject: Re: [PHP-DB] 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.
>>>>
>>>> >>>> /*
>>>>
>>>> Stephen Johnson c | eh
>>>> The Lone Coder
>>>>
>>>> http://www.ouradoptionblog.com
>>>> Join our journey of adoption
>>>>
>>>> http://www.thelonecoder.com
>>>> stephen@thelonecoder.com
>>>>
>>>> continuing the struggle against bad code
>>>>
>>>> */
>>>> ?>
>>>>
>>>>
>>>>> From: Alexander
>>>>> Date: Sat, 27 Jan 2007 19:55:17 -0600
>>>>> To: PHP-DB
>>>>> Subject: [PHP-DB] 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:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> >>>>>
>>>>> 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 "

";
>>>>>
>>>>> echo "

Enter url of large picture: >>>>> name='picture' />";
>>>>>
>>>>> echo "

Enter url of thumbnail: >>>>> name='thumbnail' />";
>>>>>
>>>>> echo "

";
>>>>>
>>>>> echo "

";
>>>>> }
>>>>>
>>>>> 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();
>>>>> }
>>>>>
>>>>> ?>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> 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
>>
>
> --
> 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

Re: Am I missing something?

am 28.01.2007 03:34:51 von Alexander

Alright, I did that. I now get :
INSERT INTO domains ( picture, thumbnail ) values( '', '')

and no data entered.

/* never take a hiatus from programming for a year */

----- Original Message -----
From: "Niel Archer"
To:
Sent: Saturday, January 27, 2007 8:29 PM
Subject: Re: [PHP-DB] Am I missing something?


> Hi
>
> you need to change this:
>
>> $insert = 'INSERT INTO domains ( picture, thumbnail ) values( "$picture",
>> "$thumbnail")';
>
> to be:
> $insert = "INSERT INTO domains ( picture, thumbnail ) values( '$picture',
> '$thumbnail')";
>
> variables are only interpreted inside double quoted strings. Within
> single quotes, everything is taken exactly as it appears.
>
>
> Niel
>
> --
> 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

Re: Am I missing something?

am 28.01.2007 04:07:24 von Niel Archer

Hi

> Alright, I did that. I now get :
> INSERT INTO domains ( picture, thumbnail ) values( '', '')
>
> and no data entered.

Then for some reason your variables are empty. Make sure they have data
on entry to the function. If they don't keep backtracking until you
find where it's lost.

Niel

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

Re: Am I missing something?

am 28.01.2007 04:16:16 von Alexander

They should have data. here's the form code:

function write_form() {
echo "

";

echo "

Enter url of large picture: name='picture' />";

echo "

Enter url of thumbnail: name='thumbnail' />";

echo "

";

echo "

";
}

I've done everything excatly how my PHP book says to /* i now officially
hate all code examples in books, they never work */
----- Original Message -----
From: "Niel Archer"
To:
Sent: Saturday, January 27, 2007 9:07 PM
Subject: Re: [PHP-DB] Am I missing something?


> Hi
>
>> Alright, I did that. I now get :
>> INSERT INTO domains ( picture, thumbnail ) values( '', '')
>>
>> and no data entered.
>
> Then for some reason your variables are empty. Make sure they have data
> on entry to the function. If they don't keep backtracking until you
> find where it's lost.
>
> Niel
>
> --
> 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

Re: Am I missing something?

am 28.01.2007 10:37:21 von Mario

Hi,

I use somethin as

$sql = 'INSERT INTO `text` (`Field`) VALUES (''aaa'')';

Also, check things with var_dump, use mysql_error, echo $sql/$insert and
check whether the query is well formed.

my best
mario


On Sat, 2007-01-27 at 19:55 -0600, Alexander wrote:
> 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:
>
>
>
>
>
> >
> 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 "

";
>
> echo "

Enter url of large picture: > name='picture' />";
>
> echo "

Enter url of thumbnail: > name='thumbnail' />";
>
> echo "

";
>
> echo "

";
> }
>
> 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();
> }
>
> ?>
>
>
>
>
>
--
mario

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

Re: Am I missing something?

am 28.01.2007 15:52:58 von Stut

Alexander wrote:
> They should have data. here's the form code:
>
> function write_form() {
> echo "

";
>
> echo "

Enter url of large picture: > name='picture' />";
>
> echo "

Enter url of thumbnail: > name='thumbnail' />";
>
> echo "

";
>
> echo "

";
> }
>
> I've done everything excatly how my PHP book says to /* i now officially
> hate all code examples in books, they never work */

The book is probably expecting you to have register_globals enabled. DO
NOT ENABLE IT! Instead, read the following and adapt what the book is
giving you to work without it. Reasons for not enabling register_globals
are also given on this page...

http://php.net/register_globals

-Stut

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