Help with insert function.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ludakuca
Forum Newbie
Posts: 7
Joined: Tue Feb 22, 2005 11:35 am

Help with insert function.

Post by ludakuca »

Here is what I try to do, if somebody can write me some kind of code to help me do this.

I have 8 games, people will bid on. There are 48 bidders, and they will bid on the games with win, draw or lose (1,x,2)

I have users table with their information as well as their username and password. So the table should look something like this.

http://www.tipliga.com/tipovi.php?kolo=16

So now, when they select what they want to tip on, they should click submit and the data shuold be stored in the table tips in the database.

My question is, what is the simplest way to implement this. I have visual made but nothing programmed, and it is really urgent for me.


Basically,
I should check the username and password from users table, and if incoredt post the data again, if correct submit the data into the tips table so I can manipulate it. Please if someone can write me some code to help me out with this I would appretiate.

Thanks
ludakuca
Forum Newbie
Posts: 7
Joined: Tue Feb 22, 2005 11:35 am

Post by ludakuca »

By the way this link is on different language, and I will probably use select statements.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can edit your posts here..

Are you sure you want someone to write it for you? If so, this thread will be moved.
ludakuca
Forum Newbie
Posts: 7
Joined: Tue Feb 22, 2005 11:35 am

Post by ludakuca »

well this is what I was working on..

Right now, I have this script that checks the username and password writtem, and then....if true logs into the page where the tips are at and then sends the tips...
So I am fine now:)

Thanks, this is really poor solution so if somebody has something better please write is, so I can change it. Thanks.


OK so what am I doing wrong here??

Code: Select all

<?php
$thispage = 'login2.php'; 
$forwardpage = 'tipovi.php'; //SET THIS TO THE PAGE YOU USER WILL BE FORWARDED AFTER LOGIN/LOGOUT

//CHECK FOR LOGIN STATUS
$myid = $HTTP_COOKIE_VARS&#1111;"id_korisnika"];	
$myusername = $HTTP_COOKIE_VARS&#1111;"korisnicko_ime"];	

//IF LOGGED IN, SHOW USER ID
if ($action=="logout") &#123;
setcookie("id_korisnika",$id_korisnika,time()-1,"/","www.tipliga.com",0);
setcookie("korisnicko_ime",$korisnicko_ime,time()-1,"/","www.tipliga.com",0);

?>
<<? echo "meta"; ?> <? echo"http-equiv";?>="refresh" content="3" Url="http://www.tipliga.com/tipovi.php">
Please wait while we log you out...
<?
&#125; else &#123;
if ($id_korisnika > "") &#123;
/*------------------------------------------------------------
IF USER IS LOGGED IN, THEY SEE THE FOLLOWING

------------------------------------------------------------*/
echo "Your User ID is: $myid";
echo "<BR>Your Username is: $myusername";
?>
<BR><BR><a href="<? echo $thispage; ?>?action=logout&myid=<? echo $myid; ?>">Click Here to Logout</a>
<?
/*------------------------------------------------------------
END OF USER IS LOGGED IN
------------------------------------------------------------*/
&#125; else &#123;

//IF NOT LOGGED IN
if ($login == "") &#123;

if ($myid == "") &#123;
/*------------------------------------------------------------
IF USER IS NOT LOGGED IN, THEY SEE THE FOLLOWING LOGIN FORM
------------------------------------------------------------*/
?>

<FORM METHOD="POST" ACTION="<? echo $thispage ?>">


    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" ALIGN="CENTER">
		<TR>
			<TD ALIGN="CENTER">
			&nbsp;
			</TD>
			<TD ALIGN="LEFT">
			<FONT FACE="ARIAL" SIZE="3">
					<B>&nbsp;&nbsp;&nbsp;Login:</B>
				</FONT>
			
			</TD>		
		</TR>
      <TR>
        <TD><B><FONT SIZE="2" FACE="ARIAL">Username:&nbsp;&nbsp;</FONT></B></TD>
        <TD><INPUT TYPE="TEXT" NAME="username" SIZE="12"></TD>
      </TR>
      <TR>
        <TD><B><FONT SIZE="2" FACE="ARIAL">Password:&nbsp;&nbsp;</FONT></B></TD>
        <TD><INPUT TYPE="password" NAME="password" SIZE="12"></TD>
      </TR>
      <TR>
        <TD></TD>
        <INPUT TYPE="HIDDEN" VALUE="yes" NAME="login">
        <TD ALIGN="center"><INPUT TYPE="submit" VALUE="Login"></TD>
      </TR>
    </TABLE>
    </CENTER>
  </DIV>
</FORM><?
/*------------------------------------------------------------
END OF THE LOGIN FORM
------------------------------------------------------------*/
&#125; //end if myid == nothing
&#125; //END IF LOGIN == ""


if ($login == "yes") &#123;
//CONNECTION STRING
include "dbconnect.php";


// $_GET VARIABLES
foreach($_GET as $a=>$b)&#123;$$a=$b; echo "<BR>$a: $b";&#125; 

// $_POST VARIABLES
foreach($_POST as $a=>$b)&#123;$$a=$b; echo "<BR>$a: $b";&#125; 

$sqllogin = "SELECT * FROM timovi WHERE korisnicko_ime = '$username' and sifra = '$password'";
$result = mysql_query($sqllogin);

if ($result > 1) &#123;										
if ($myrow = mysql_fetch_array($result)) &#123;
	do
	&#123;
				
		$id_korisnika = $myrow&#1111;"id_korisnika"];
		$korisnicko_ime = $myrow&#1111;"korisnicko_ime"];
							
setcookie("korisnicko_ime",$korisnicko_ime,time()+7200,"/","www.tipliga.com",0);
setcookie("id_korisnika",$id_korisnika,time()+7200,"/","www.tipliga.com",0);

		echo "Welcome $korisnicko_ime! <br>
		<BR>Please wait 2-3 seconds while we process your login...<BR>";
		?>
		<<? echo "meta ";?> <? echo"http-equiv";?>="refresh" content="3" Url="http://www.tipliga.com/tipovi.php">
		<?
	&#125; while ($myrow = mysql_fetch_array($result));
		&#125; else &#123;
		echo "<P>That Username or Password was Not Found<p>";
		?>
		<a href="<? echo $thispage; ?>?">Click Here to Login</a>
		<?
		&#125; //END IF MYROW RESULT
&#125; else &#123;
echo "No Results Returned";
&#125; //END IF RESULT = 1
&#125; //END IF LOGIN == YES
&#125; //END IF NOT LOGGED IN.....
&#125; //END IF NOT LOGGING OUT...
?>
example:

http://www.tipliga.com/login2.php

login with test as username and test as password. But when I try to logout, it does not wanna go to the page I want it to go.

When user logs in and logs out it should hit the page tipovi.php and it does not. WHat am I doing wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the cookie deletion code doesn't look right. Where are $id_korisnika and $korisnicko_ime coming from? The values used for deletion should be empty strings. The time used should be farther back in time, as 1 second ago could easily register as valid to the browser. I often recommend at least 1 week back, potentially more.

Your code seems to mix register_globals being on and not.. can you tell us which it is?

Code: Select all

<?php echo 'Register globals are ' . (ini_get('register_globals') ? 'on' : 'off'); ?>
ludakuca
Forum Newbie
Posts: 7
Joined: Tue Feb 22, 2005 11:35 am

Post by ludakuca »

Globals are ON.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

and what of the answers to the other questions I asked?
ludakuca
Forum Newbie
Posts: 7
Joined: Tue Feb 22, 2005 11:35 am

Post by ludakuca »

Well, maybe because I did not quite understand what you were asking me for... Well I log in perfectly and It logs me out and clears the cookies, but the problem is with the redirect "meta refresh" it does not forward to the page I want, it just sits there saying please wait while we log you out...


What am I doing wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

meta-refresh syntax:

Code: Select all

<meta http-equiv="refresh" content="<seconds>&#1111;; url=<url>]" />
where <seconds> is an integer for the number of seconds delay you wish to have, and <url> is an optional parameter of a URI.

http://webdesign.about.com/cs/metatags/a/aa080300a.htm
ludakuca
Forum Newbie
Posts: 7
Joined: Tue Feb 22, 2005 11:35 am

Post by ludakuca »

well the meta syntax is the same as for login, so redirects when I login, but it does not redirect when I log out..??

I dont get it.

Here is the code..

Code: Select all

<<? echo "meta ";?> <? echo"http-equiv";?>="refresh" content="3" Url="http://www.tipliga.com/tipovi.php">
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your syntax does not match the specification.
ludakuca
Forum Newbie
Posts: 7
Joined: Tue Feb 22, 2005 11:35 am

Post by ludakuca »

I fixed it, I see where it was problem...


Thanks..
Post Reply