RE: [PHP-DB] MySQL newbie: inserting new entry to table?

2001-07-30 Thread Howard Picken

I'm a learner too.

But as I understand it, You make a connection to the database (or open it?).
Once it's open or connected to, you can access the different tables within
it.

I think the difference between mysql_db_query  mysql_query is that
later assumes that
you all ready connected to the database where the first connects at the same
time.

Anyway glad you fixed your problem.  It wasn't a holiday in Australia (just
a Sunday night :-))

Cheers
Howard


-Original Message-
From: sg [mailto:[EMAIL PROTECTED]]
Sent: Sunday, 29 July 2001 9:40 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] MySQL newbie: inserting new entry to table?


Thank You Howard!

You sure are quick!

I found a way to make it work. I used to have both scripts (the one that
displays and the one that inserts new entries) on the same page...
Once I separated them I had a link on a third page. I first clicked on the
insert entry link then back to the display page... My new entry was there...

Now for the solution you gave me. I haven't tried it yet but I'd like to
know the difference.
I see you don't provide the database name in the mysql_query call. How does
MySQL know what base to work with?
I've seen both 'mysql_query' and 'mysql_db_query' in several tutorials but
haven't yet figured the difference between them (told you a was a newbie...)

Thanks again for your interest, I thought everybody would be on holidays...

Sébastien



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] MySQL newbie: inserting new entry to table?

2001-07-29 Thread Howard Picken

Have a look at how I would insert data in your case.

Howard

-Original Message-
From: sg [mailto:[EMAIL PROTECTED]]
Sent: Sunday, 29 July 2001 8:57 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] MySQL newbie: inserting new entry to table?


Hi folks!

I'm new to PHP/mysql.

I created a db with one table (using PhpMyAdmin). The table is called
'addressbook' and the base 'mabase'.

I can very well read the table and display it very neatly using the below
code, but I CAN'T write new entries using the code in the second page (end
of mail)

~~  PAGE THAT WORKS


html
head
titleCarnet d'adresses/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
style type=text/css
!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color:
#00; letter-spacing: 0.1em; background:#efefef}
.NomPrenom { font-family: Arial, Helvetica, sans-serif; font-size: 10pt;
color: #00; font-weight:bold; letter-spacing: 0.1em; }
hr {height:1px; color:#BB}
--
/style
/head

body bgcolor=#FF text=#00

?
$host = localhost;
$user = ;
$password = ;
$database = mabase;

//==
=
//  Display addressbook table content
//==
=

mysql_connect($host,$user,$password) or die(Impossible de se connecter à la
base de données .$database);

$result = mysql_db_query($database,select * from addressbook);

while ($row = mysql_fetch_object($result))
{
 if($row-prenom != )
 {
  echo span class=\NomPrenom\.$row-prenom./span;
 }

 if($row-nom != )
 {
  echo span class=\NomPrenom\nbsp;;
  echo $row-nom./span;
 }

 if($row-teldomicile != )
 {
  echo br\n;
  echo img src=\/interface/icons/domicile_phone.gif\
align=\absbottom\nbsp;\n;
  echo $row-teldomicile;
 }

 if($row-telmobile != )
 {
  echo br\n;
  echo img src=\/interface/icons/mobile.gif\
align=\absbottom\nbsp;\n;
  echo $row-telmobile;
 }

 if($row-telbureau != )
 {
  echo br\n;
  echo img src=\/interface/icons/bureau.gif\
align=\absbottom\nbsp;\n;
  echo $row-telbureau;
 }

 if($row-email != )
 {
  echo br\n;
  echo img src=\/interface/icons/email.gif\
align=\absbottom\nbsp;\n;
  echo a href=\mailto:.$row-email.\.$row-email./a;
 }

 if(($row-rue != ) || ($row-codepostal != ) || ($row-ville != ) ||
($row-pays != ))
 {
  echo br\n;
  echo img src=\/interface/icons/adresse.gif\
align=\absbottom\nbsp;\n;
 }

 if($row-rue != )
 {
  echo $row-rue;
  echo nbsp;-nbsp;;
 }

 if($row-codepostal != )
 {
  echo $row-codepostal;
  echo nbsp;;
 }

 if($row-codepostal != )
 {
  echo $row-ville;
  echo ,nbsp;\n;
 }

 if($row-pays != )
 {
  echo $row-pays;
 }

 echo brbrbrhrbrbrbr\n;
}
mysql_free_result($result);
mysql_close();
// END Display addressbook table content

?

/body
/html
~~  PAGE THAT WORKS  - END -






~~  PAGE THAT DOESN'T WORK

html
head
titleUntitled Document/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
/head

body bgcolor=#FF text=#00
?
$host = localhost;
$user = ;
$password = ;
$database = mabase;

mysql_connect($host,$user,$password);

$nom = Dupont;
$prenom = Jean;

$ok = mysql_db_query($database, insert into addressbook (nom,prenom) values
('$nom','$prenom'));



$ok = mysql_query(insert into addressbook (nom,prenom) values
('$nom','$prenom'));


?
/body
/html

~~  PAGE THAT DOESN'T WORK - END -


After that when I look at my page where I display the addressbook table, I
see nothing new, neither does it appear anywhere in PhpMyAdmin.

I don't get it!

But, again, I'm a newbie.

Is there a problem with the fact that I provide an empty user/password? I
don't recall having given any user name and password durng MySQL
installation.

If there is one, where can I find it? Or do I have to re-install???


Hope it's just a newbie syntax mistake though...

Thanks for reading anyway!

Cheers,

Sébastien






--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] MySQL newbie: inserting new entry to table?

2001-07-29 Thread sg

Thank You Howard!

You sure are quick!

I found a way to make it work. I used to have both scripts (the one that
displays and the one that inserts new entries) on the same page...
Once I separated them I had a link on a third page. I first clicked on the
insert entry link then back to the display page... My new entry was there...

Now for the solution you gave me. I haven't tried it yet but I'd like to
know the difference.
I see you don't provide the database name in the mysql_query call. How does
MySQL know what base to work with?
I've seen both 'mysql_query' and 'mysql_db_query' in several tutorials but
haven't yet figured the difference between them (told you a was a newbie...)

Thanks again for your interest, I thought everybody would be on holidays...

Sébastien



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]