Re: [PHP] Problem with inserting values into database through php

2002-09-07 Thread timo stamm

Hi Olli,


I think the query string is missing an ";"


Timo


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




RE: [PHP] Problem with inserting values into database through php

2002-09-06 Thread bbonkosk

Just and FYI update, in case someone else has this problem...

The problem was the example was using $PHP_SELF as the form action variable,

of course it has been discussed on this list that in the newer versions
of PHP, register_globals is turned off in php.ini, so $PHP_SELF had no real 
meaning, so no data was actually being passed.  So, just an update to change it 
to:


-Brad

> [snip]
> 
> I´m quite a newbie in making php, but I managed to run the test you
> suggested,
> but nothin happened. This time it was propably the code I did:
> first I added the "or die("Invalid query: $sql");" part and ran the form,
> but everything happened just like when refreshing a page.
> 
> Then I did this:
>   $result = mysql_query($sql)
> or die("Invalid query: $sql");
> 
>   echo $sql;
> 
> but the database was silentit just refreshed the page and cleared out
> the form.
> [/snip]
> 
> 1. Here is a different method of error checking for queries;
> 
> if the query is
> 
> $query = "SELECT foo FROM BAR ";
> if(!($result = mysql_query($query, $database_connection))){
>print("MySQL reports the following error: " . mysql_error() . "\n");
>exit();
> }
> 
> 2. Check your web access and error logs for clues.
> 3. Does the user have permission to INSERT and/or UPDATE? If you set
thos> e
> on the database did you flush the grant tables?
> 
> HTH!
> 
> Jay
> 
> In clinical trials for diabetes medications do they give sugar pills as
> placebos?
> 
> *
> * Texas PHP Developers Conf  Spring 2003*
> * T Bar M Resort & Conference Center*
> * New Braunfels, Texas  *
> * Contact [EMAIL PROTECTED]   *
> *   *
> * Want to present a paper or workshop? Contact now! *
> *
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 






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




RE: [PHP] Problem with inserting values into database through php

2002-09-06 Thread Jay Blanchard

[snip]

I´m quite a newbie in making php, but I managed to run the test you
suggested,
but nothin happened. This time it was propably the code I did:
first I added the "or die("Invalid query: $sql");" part and ran the form,
but everything happened just like when refreshing a page.

Then I did this:
  $result = mysql_query($sql)
or die("Invalid query: $sql");

  echo $sql;

but the database was silentit just refreshed the page and cleared out
the form.
[/snip]

1. Here is a different method of error checking for queries;

if the query is

$query = "SELECT foo FROM BAR ";
if(!($result = mysql_query($query, $database_connection))){
   print("MySQL reports the following error: " . mysql_error() . "\n");
   exit();
}

2. Check your web access and error logs for clues.
3. Does the user have permission to INSERT and/or UPDATE? If you set those
on the database did you flush the grant tables?

HTH!

Jay

In clinical trials for diabetes medications do they give sugar pills as
placebos?

*
* Texas PHP Developers Conf  Spring 2003*
* T Bar M Resort & Conference Center*
* New Braunfels, Texas  *
* Contact [EMAIL PROTECTED]   *
*   *
* Want to present a paper or workshop? Contact now! *
*



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




Re: [PHP] Problem with inserting values into database through php

2002-09-05 Thread Olli Sinerma


I´m quite a newbie in making php, but I managed to run the test you
suggested,
but nothin happened. This time it was propably the code I did:
first I added the "or die("Invalid query: $sql");" part and ran the form,
but everything happened just like when refreshing a page.

Then I did this:
  $result = mysql_query($sql)
or die("Invalid query: $sql");

  echo $sql;

but the database was silentit just refreshed the page and cleared out
the form.

-Olli



"Brad Bonkoski" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> The best way IMHO, to debug problems like this is to echo out your
> insert query to the screen and not actually run the query, or run it and
> make sure you use:
> $sql = "INSERT INTO employees (first,last,address,position) VALUES
> ('$first','$last','$address','$position')";
> $result = mysql_query($sql)
> or die("Invalid query: $sql");
>
> (This is always good practice anyways, especially if the page depends
> upon that query's execution)
>
> Anyhow, echo out the query: $sql to the screen and then run it against
> your actual MySQL database and see how it responds?  Chances are there
> is some error there, and you'll get more meaningful feedback from the
> database backend.
>
> HTH
> -Brad
>
> Olli Sinerma wrote:
> > Hi,
> > I´m having a weird problem with getting my forms work within
> > php. I have a running MySQL server, php installed on a apache server
> > and I can make SQL queries through php, but I´m unable to insert
> > any data into it through forms.
> >
> > This is an example file that I´m using
> > (it´s from
> >
http://hotwired.lycos.com/webmonkey/99/21/index3a_page4.html?tw=programming
> > )
> >
> > __
> >
> > 
> >
> > 
> >
> >
> >
> >  >
> >
> >
> > if ($submit) {
> >
> >   // process form
> >
> >   $db = mysql_connect("localhost", "root", "mypassword");
> >
> >   mysql_select_db("mydb",$db);
> >
> >   $sql = "INSERT INTO employees (first,last,address,position) VALUES
> > ('$first','$last','$address','$position')";
> >
> >   $result = mysql_query($sql);
> >
> >   echo "Thank you! Information entered.\n";
> >
> > } else{
> >
> >
> >
> >   // display form
> >
> >
> >
> >   ?>
> >
> >
> >
> >   
> >
> >   First name:
> >
> >   Last name:
> >
> >   Address:
> >
> >   Position:
> >
> >   
> >
> >   
> >
> >
> >
> >>
> >
> >
> > } // end if
> >
> >
> >
> > ?>
> >
> >
> >
> > 
> > 
> > 
> >
> > I have set the database in working order according to the manual, but
after
> > I enter some writing into the
> > text fields and press submit: It refreshes the page and doesn't add any
> > information into the db.
> >
> > I recon that the problem might be within the $php_self command, for I
got
> > all the previous php/mySQL tutorials
> > working, but when this command appeared...problems started...or more
> > accurate word would be: nothing
> > happened.
> >
> > I have phpMyAdmin 2.3.0 running on my apache server and it can
send/receive
> > data from the db normally, so the problem shouldn't
> > be in the db server or in the php, so it´s in me or in the code :) I
have
> > read through all the FAQ:s and manuals that I have found and I still
> > can´t understand what is the problem in this one!
> >
> > -Olli
> >
> >
> >
> >
> >
>
>



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




Re: [PHP] Problem with inserting values into database through php

2002-09-05 Thread Brad Bonkoski

The best way IMHO, to debug problems like this is to echo out your 
insert query to the screen and not actually run the query, or run it and 
make sure you use:
$sql = "INSERT INTO employees (first,last,address,position) VALUES
('$first','$last','$address','$position')";
$result = mysql_query($sql)
or die("Invalid query: $sql");

(This is always good practice anyways, especially if the page depends 
upon that query's execution)

Anyhow, echo out the query: $sql to the screen and then run it against 
your actual MySQL database and see how it responds?  Chances are there 
is some error there, and you'll get more meaningful feedback from the 
database backend.

HTH
-Brad

Olli Sinerma wrote:
> Hi,
> I´m having a weird problem with getting my forms work within
> php. I have a running MySQL server, php installed on a apache server
> and I can make SQL queries through php, but I´m unable to insert
> any data into it through forms.
> 
> This is an example file that I´m using
> (it´s from
> http://hotwired.lycos.com/webmonkey/99/21/index3a_page4.html?tw=programming 
> )
> 
> __
> 
> 
> 
> 
> 
> 
> 
>  
> 
> 
> if ($submit) {
> 
>   // process form
> 
>   $db = mysql_connect("localhost", "root", "mypassword");
> 
>   mysql_select_db("mydb",$db);
> 
>   $sql = "INSERT INTO employees (first,last,address,position) VALUES
> ('$first','$last','$address','$position')";
> 
>   $result = mysql_query($sql);
> 
>   echo "Thank you! Information entered.\n";
> 
> } else{
> 
> 
> 
>   // display form
> 
> 
> 
>   ?>
> 
> 
> 
>   
> 
>   First name:
> 
>   Last name:
> 
>   Address:
> 
>   Position:
> 
>   
> 
>   
> 
> 
> 
>
> 
> 
> } // end if
> 
> 
> 
> ?>
> 
> 
> 
> 
> 
> 
> 
> I have set the database in working order according to the manual, but after
> I enter some writing into the
> text fields and press submit: It refreshes the page and doesn't add any
> information into the db.
> 
> I recon that the problem might be within the $php_self command, for I got
> all the previous php/mySQL tutorials
> working, but when this command appeared...problems started...or more
> accurate word would be: nothing
> happened.
> 
> I have phpMyAdmin 2.3.0 running on my apache server and it can send/receive
> data from the db normally, so the problem shouldn't
> be in the db server or in the php, so it´s in me or in the code :) I have
> read through all the FAQ:s and manuals that I have found and I still
> can´t understand what is the problem in this one!
> 
> -Olli
> 
> 
> 
> 
> 



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




[PHP] Problem with inserting values into database through php

2002-09-05 Thread Olli Sinerma

Hi,
I´m having a weird problem with getting my forms work within
php. I have a running MySQL server, php installed on a apache server
and I can make SQL queries through php, but I´m unable to insert
any data into it through forms.

This is an example file that I´m using
(it´s from
http://hotwired.lycos.com/webmonkey/99/21/index3a_page4.html?tw=programming 
)

__











  

  First name:

  Last name:

  Address:

  Position:

  

  



  







I have set the database in working order according to the manual, but after
I enter some writing into the
text fields and press submit: It refreshes the page and doesn't add any
information into the db.

I recon that the problem might be within the $php_self command, for I got
all the previous php/mySQL tutorials
working, but when this command appeared...problems started...or more
accurate word would be: nothing
happened.

I have phpMyAdmin 2.3.0 running on my apache server and it can send/receive
data from the db normally, so the problem shouldn't
be in the db server or in the php, so it´s in me or in the code :) I have
read through all the FAQ:s and manuals that I have found and I still
can´t understand what is the problem in this one!

-Olli





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