only add data 1 time in form

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
TinEastwood
Forum Newbie
Posts: 4
Joined: Tue Apr 13, 2004 3:16 pm

only add data 1 time in form

Post 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>
?>
Last edited by TinEastwood on Tue Apr 20, 2004 3:30 pm, edited 2 times in total.
TinEastwood
Forum Newbie
Posts: 4
Joined: Tue Apr 13, 2004 3:16 pm

Post by TinEastwood »

Sorry had to BUMP it
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
}
TinEastwood
Forum Newbie
Posts: 4
Joined: Tue Apr 13, 2004 3:16 pm

Post by TinEastwood »

thanks - but where do I put it, into the script
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

at the beginning, the comments tell you where to put other stuff
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
TinEastwood
Forum Newbie
Posts: 4
Joined: Tue Apr 13, 2004 3:16 pm

Post by TinEastwood »

Thanks one more time - still new to php so..

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