Ok call me stupid but I've tried various tutorials online and I keep getting the same problem. It says: Parse error: syntax error, unexpected $end.
What I'm trying to do is make something where you can edit the details of a member, well just the points anyway. There are two columns on the database username and wp (wp is the points). The table name is points. I would like to do this all in one page and have a html form with a box to change the amount of points. This is the code I have so far that does not seem to work.. In the code I've obviously taken out the database name, username and password.
<?
//initilize PHP
if($_POST['submit']) //If submit is hit
{
//then connect as user
//change user and password to your mySQL name and password
mysql_connect("localhost","username","password");
//select which database you want to edit
mysql_select_db("database");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the members
$result = mysql_query("select * from news order by username");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$title=$r["wp"];//take out the wp
$id=$r["username"];//take out the username
//make the username a link
echo "<a href='edit.php?cmd=edit&username=$username'>$username - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$username = $_GET["username"];
$sql = "SELECT * FROM news WHERE username=$username";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit.php" method="post"> <input type=hidden name="username" value="<?php echo $myrow["username"] ?>">
Username:<INPUT TYPE="TEXT" NAME="username" VALUE="<?php echo $myrow["username"] ?>" SIZE=30><br>
Points:<INPUT TYPE="TEXT" NAME="wp" SIZE="30" VALUE="<? echo $myrow["wp"] ?>"><br>
<input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit">
</form><? } ?>
<?
if ($_POST["$submit"])
{
$username = $_POST["username"];
$wp = $_POST["wp"];
$sql = "UPDATE news SET wp='$wp' WHERE username=$username";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}?>
Your code is sloppily written. Usually when you get an "unexpected end" error it is because you made an error closing your brackets. }
Plus you are mixing PHP and HTML in a very sloppy fashion. Your best bet would be to echo out the form.
I'm sorry. I am still a newb when it comes to php. Most of this is from various tutorials. I'll try again using echo's for the form like suggested. Thanks!