Hey there,
I am trying to write a basic script but I am new to PHP. I was wondering whether this should go in Newbie section or coding but I decided on posting here. I apologize for not spotting similar threads but there are so many its hard to tell what it the right stuff.
I am attempting to write a script. This is basically what it needs to do.
User goes to page
Enter name in form and submit
Script adds name to database (column=username) and also adds 1 point to the point columns value (column=points)
If name is already inserted it simply adds a point to the point column rather than making a new column
User then visits output page
So far the script adds a name to the database in the correct column. If you enter it twice it makes another field that is identical.
Here is the code I am using:
Form:
<html>
<body bgcolor="#CCCCCC">
<center>
<form action="insert.php" method="post">
Username: <input type="text" name="username" />
<input type="submit" />
</form>
<a href="ranks.php">Click here to see the rank point table!</a>
</center>
</body>
</html>
Insert.php page
<?php
$con = mysql_connect("[COLOR="Red"]DB CONNECT[/COLOR]","[COLOR="Red"]USERNAME[/COLOR]","[COLOR="Red"]PASS[/COLOR]");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("[COLOR="Red"]DB NAME[/COLOR]", $con);
$sql="INSERT INTO [COLOR="Red"]TABLE NAME[/COLOR] (Username)
VALUES
('$_POST[username]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 Rank Point Added!";
mysql_close($con)
?>
Output Page
<?php
$con = mysql_connect("[COLOR="Red"]DB CONNECT[/COLOR]","[COLOR="Red"]USERNAME[/COLOR]","[COLOR="Red"]PASS[/COLOR]");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("[COLOR="Red"]DB NAME[/COLOR]", $con);
$result = mysql_query("SELECT * FROM [COLOR="Red"]DB TABLE[/COLOR]");
echo "<table border='1' align='center' width='80%'>
<tr>
<th>Username</th>
<th>Rank Points</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['points'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
If you need to know anything else just ask and I'll do my best to communicate with you however I have never done any PHP scripting before now so it may be hard.
Thanks very much,
Clarkie