Jump to content

updateing database


Justafriend
Go to solution Solved by Justafriend,

Recommended Posts

Ok i have my php code for inserting and retreiving data and its working nicely and i have seen many examples on the retrieving side of it  for this

i have 2 colums and in colum 1 is players name column 2 is email address what i would like is when they enter the information for lets say playerx the code looks at the database  and if there and entered a different email it will update the record if it is the same in both then responds with  Your name is already on the list  below is my form code

I thank you in advance you guys have been a great help today and hoping this is my last post for today

<html>
<head>
</head>
<body>
<form action="insertform.php" method="post">
SHG Player Name: <input type="text" name="playername">
Email Address: <input type="text" name="email">
<input type="submit" name="submit" />
</form>

<?php
if (isset($_POST['submit'])){
$con=mysql_connect("localhost","dbs_dbs","dbs4evr") or die("Can not connect: " . mysql_error());


mysql_select_db("dbs_forms",$con);

$sql = "INSERT INTO playersemails(`playername`,`email`) values ('{$_POST['playername']}','{$_POST['email']}')";

mysql_query($sql,$con) or die(mysql_error());
echo 'email is now in our list';
mysql_close($con);
}
?>
</body>
</html>
Link to comment
Share on other sites

You probably should re-think this.  I say this because there is nothing stopping me from changing someones email address, if I have their username.  You should PULL the data from the database, and then let them change it by running an update on the data.  You, of course, wouldn't pull the data, until you were sure that person was allowed to edit it.

 

You would then run a simple update query on the data, which will update it if it is different, but will not if it is the same.  Then return that data back to the page, in a form, in case they mis-spelled something, or need to change it again.

Link to comment
Share on other sites

here is the results code

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<?php
$con = mysql_connect("localhost","dbs_dbs","dbs4evr");
if (!$con){
	die("Can not connect: " . mysql_error());
}
mysql_select_db("dbs_forms",$con);
$sql = "SELECT * FROM  playersemails ORDER BY playername ASC ";
$mydata = mysql_query($sql,$con);
echo "<table border=1>
<tr>
<th> Player Name</th>
<th> Emails</th>
</tr>";
while($record = mysql_fetch_array($mydata)){
	echo "<tr>";
	echo "<td>" . $record['playername'] . "</td>";
	echo "<td>" . $record['email'] . "</td>";
	echo "</tr>";
}
echo "</table>";
mysql_close ($con);
?>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.