Justafriend Posted April 25, 2013 Share Posted April 25, 2013 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> Quote Link to comment Share on other sites More sharing options...
jcbones Posted April 25, 2013 Share Posted April 25, 2013 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. Quote Link to comment Share on other sites More sharing options...
Justafriend Posted April 25, 2013 Author Share Posted April 25, 2013 ok then the only way i can fix it is for the output is to only show the latest entry that will only be done with special priveledges so we dont have to wade through all the email lists i have what is the easiest way of doing it Quote Link to comment Share on other sites More sharing options...
Justafriend Posted April 25, 2013 Author Share Posted April 25, 2013 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> Quote Link to comment Share on other sites More sharing options...
Solution Justafriend Posted April 25, 2013 Author Solution Share Posted April 25, 2013 so in otherwords if playername shows up 2 times in database only use the most recent result Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.