You are here: Re: INSERT into mysql alway make two entries « PHP Programming Language « IT news, forums, messages
Re: INSERT into mysql alway make two entries

Posted by Sandman on 09/14/05 15:09

In article <b309c$4327457a$d9091b38$18577@nf1.news-service.com>,
"Johannes A. Brunner" <johannesabrunner@t-link.de> wrote:

> Got a simple problem.
> I code some site and because Im a freak I made my own session-handling.

Why?

> When a user open up my site it will check if there is a ssid in the url
> if not generate one. this will be done by a function generate_ssid() and
> works fine.
> next step is to register the ssid in the table session
> this will be done by the following code:
> *************************************************************************
> function ssid_register($ssid,$login,$uid,$admin){
>
> $connect = mysql_connect( $GLOBALS["db_host"],
> $GLOBALS["db_user"],
> $GLOBALS["db_password"])
> or die($GLOBALS["db_error"]);

I recommend doing a persistent connection to MySQL outside this function. This
way, you're making one new MySQL connection for every time the function is run.
If this is the only function that ever use MySQL, it's no big deal, but if it
isn't.

Lookup mysql_pconnect

> mysql_select_db($GLOBALS["db_name"],$connect) or
> die($GLOBALS["db_error"].'<br>ErrorCode s.001-con');

You actually don't need to select a database if you know it exists. You can use
"insert into database.sessions" below to insert into the correct database/table

> $result = mysql_query("INSERT INTO session SET
> ssid='$season',ip='$rip'",$connect);
> echo ($rs);
> return;
> }
> ****************************************************
> I redesigned the INSERT INTO part into all possible syntax but everytime I
> look into the db
> there are two entries with two DIFFERENT ssids.

Why are you using insert into...set?

insert into database.sessions (ssid, ip) values ('$season', '$rip')

($season and $rip isn't even declared in the above function, so I'm guessing
you snipped some of the function.

> The only way it works correct is to dont use a variable on the first place.
> Means if I use ssid='godhelpmetofindaworkingsolution' it works great but is
> not realy what I want.

How does the declaration of table 'session' look? Maybe you've got an
auto_increment playing up.

> As told above a "INSERT INTO session (ssid) VALUES ($ssid)" also has the
> effect of two new db-entries.

The only way to explain that is that the function is run twice.

> Hope you understand and pray to god you know what I do wrong

You're not using session_start(), that's the problem. :-D




--
Sandman[.net]

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация