Okay.. I've searched for a clearer way to do this all over Google and just can't seem to find something that makes sense to me... that I can incorporate into what I've done so far...
I'm just learning PHP so I'm sure my coding looks pretty scary to those of more experience. The tutorial I've been following is here: http://www.tizag.com/mysqlTutorial/mysqldatabase.php and so far it has worked well enough.
I've set up a form for guests to fill out here: http://gwynevere.110mb.com/hatchform.php
using this:
<?php
mysql_connect("localhost", "mylogin", "blah") or die(mysql_error());
mysql_select_db("gwynevere_hatch") or die(mysql_error());
$result = mysql_query("SELECT * FROM hatchery") or die(mysql_error());
while($row = mysql_fetch_array( $result )){
echo "Scroll: " . "<a href=http://dragcave.net/user/" . $row['username'] . " target=_blank>" . $row['username'] . "</a><br /><br />";
echo "<a href=http://dragcave.net/viewdragon/" . $row['egg1'] . " target=_blank>" . "<img src=http://dragcave.net/image/" . $row['egg1'] . " border=0></a>" . "<a href=http://dragcave.net/viewdragon/" . $row['egg2'] . " target=_blank>" . "<img src=http://dragcave.net/image/" . $row['egg2'] . " border=0></a>" . "<a href=http://dragcave.net/viewdragon/" . $row['egg3'] . " target=_blank>" . "<img src=http://dragcave.net/image/" . $row['egg3'] . " border=0></a>" . "<a href=http://dragcave.net/viewdragon/" . $row['egg4'] . " target=_blank>" . "<img src=http://dragcave.net/image/" . $row['egg4'] . " border=0></a>" . "<a href=http://dragcave.net/viewdragon/" . $row['egg5'] . " target=_blank>" . "<img src=http://dragcave.net/image/" . $row['egg5'] . " border=0></a>";
echo "<br /><br />";
}
?></div>
<br />
<br />
<form action="./hatch.php" method="post" align="center">
<strong>Username:</strong><br />
<input maxlength="15" size="15" name="username" type="text" /><br />
<br />
<strong>Egg codes (ONLY!):</strong><br />
<input maxlength="4" size="4" name="egg1" type="text" /> <input maxlength="4" size="4" name="egg2" type="text" /> <input maxlength="4" size="4" name="egg3" type="text" /> <input maxlength="4" size="4" name="egg4" type="text" /> <input maxlength="4" size="4" name="egg5" type="text" /><br />
<br />
<input type="submit" value="Add eggs!" />
</form>
The form uses "hatch.php" which the code for that is:
<?php
mysql_connect("localhost", "mylogin", "blah") or die(mysql_error());
mysql_select_db("gwynevere_hatch") or die(mysql_error());
mysql_query("INSERT INTO hatchery
(username, egg1, egg2, egg3, egg4, egg5) VALUES('$_POST[username]', '$_POST[egg1]', '$_POST[egg2]', '$_POST[egg3]', '$_POST[egg4]', '$_POST[egg5]' ) ")
or die(mysql_error());
?>
It's very simple and plain, and works surprisingly for beginner work... but I want it to go a bit further... but I can't seem to figure out how to do it... here's my problem:
I want to prevent duplicate entries from being submitted.. I've read things on setting your database columns to "UNIQUE" but it didn't prevent it from showing duplicate entries... all it did on the 110mb manager was tell me "There is a duplicate entry."
Instead, if someone submits form data with the SAME username, I would like it to UPDATE the previous entry in the database... I'm guessing I'll need some sort of IF statement to say... "If this username exists, replace the old data with this one; if not, insert it into the database."---am I close? hehe 🙂
My second problem is that not every guest has 5 eggs... is there a way for it to just display the eggs that people inputed? Right now when you leave the field blank... it views a broken image.. (which I'm assuming it's because of what I did on my form page...) so how do you add an image depending on how many fields you fill out?? Help! lol.
Thanks!