Page 1 of 1

only add data 1 time in form

Posted: Tue Apr 13, 2004 3:16 pm
by TinEastwood
I have this form where user can add there steam_id to the database - I need so that if they allready have add it 1 time - they can`t change it - and better if it tjek the database to see if the number is in use.

I need something like this add to the last code:

Code: Select all

if(($steam_check > 0)){
 	echo "Please fix the following errors: <br />";
 	if($steam_check > 0){
 		echo "The steam_id you have selected has already been used by another member in our database. Please choose a different Username!<br />";
}
  	exit();  // exit the script so that we do not create this account!
 }

Code: Select all

<?php
define('IN_PHPBB', true); 
$phpbb_root_path = '../forums/'; 
include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 

// 
// Start session management 
// 
$userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length); 
init_userprefs($userdata); 
// 
// End session management 

$sqls="SELECT user_pass FROM phpbb_users WHERE user_id='$userdata[user_id]'"; 
$sql_resultrrr = mysql_query($sqls) or die ("$text_noquery - 1"); 
$r = mysql_fetch_array($sql_resultrrr); 
$user_pass = $r[user_pass]; 

?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<title>steam id</title> 
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> 
<link rel="stylesheet" type="text/css" href="liste.css"> 
</head> 
<body> 
<h3>Welcome to the steam_id add page <?php echo "$userdata[username]"; ?></h3> 

<form method="POST" action="<?php echo "$PHP_SELF"; ?>"> 
<table> 
<tr><td>Steam id:</td><td><input type="text" name="user_pass2" size="30" value="<?php echo "$user_pass"; ?>"></td></tr> 
</table> 
<input type="submit" value="submit" name="submit" /> 
<input type="hidden" name="page" value="ter" /> 
</form> 
<div> 
<?php 
  
if ($page == ter) { 
$sqladd = "UPDATE phpbb_users SET user_pass='$user_pass2' WHERE user_id='$userdata[user_id]'"; 
$sql_result22 = mysql_query($sqladd) or die ("$text_noquery - ter"); 
  if (!$sql_result22) { 
  echo "there was an error while submitting the info"; 
  } else { 
  echo "Info inserted successfully! Click <a href='$PHP_SELF'>here</a> to return to the main page"; 
  } 
} 
?> 
</div> 
</body> 
</html>
?>

Posted: Tue Apr 20, 2004 11:04 am
by TinEastwood
Sorry had to BUMP it

Posted: Tue Apr 20, 2004 11:09 am
by malcolmboston

Code: Select all

$query = "SELECT * FROM table WHERE STEAMID = '$_POST[steam_id]'";
$result = mysql_query($query) or die (mysql_error());
$check = mysql_num_rows($result);
if ($check >= 1)
{
// this guy is already in the database
// do nothing
}
else
{
// this guy isnt in the database
// run an insert command
}

Posted: Tue Apr 20, 2004 2:32 pm
by TinEastwood
thanks - but where do I put it, into the script

Posted: Tue Apr 20, 2004 2:36 pm
by malcolmboston
at the beginning, the comments tell you where to put other stuff

Posted: Tue Apr 20, 2004 2:39 pm
by John Cartwright

Code: Select all

$query = "SELECT * FROM table WHERE STEAMID = '$_POST[steam_id]'";
$result = mysql_query($query) or die (mysql_error());
$check = mysql_num_rows($result);
if ($check >= 1)
{
echo "Please fix the following errors: <br />
The steam_id you have selected has already been used by another member in our database. Please choose a different Username!<br />"; 
}// this guy isnt in the database
else
{

// run an insert command
}
Change your script to this is what malcolmboston means.

and PLZ use the php button not code for php syntax

Posted: Tue Apr 20, 2004 2:40 pm
by malcolmboston
i didnt feel i needed to explain its self explanatory

i even commented the script so he would know
if yuo bother to read the script its procedural and therefore obvious (to me anyway) whats happening

Posted: Tue Apr 20, 2004 3:26 pm
by TinEastwood
Thanks one more time - still new to php so..

And did not see the PhP button :oops: - not all forums has it