Jump to content

MySql and PHP


cheechm

Recommended Posts

Hi,

I am new to MySQL so bare with me a bit please.

 

I am trying to create a "house points system" for our school. Literally, people are awarded house points for events they do. At 6 points they get a house tie.

 

I want a teacher to be able to create people in the database (which I think I have done correctly:


<form action="housepoints.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Tutor: <input type="text" name="tutor" />
<input type="submit" />
</form>

<?php
$con = mysql_connect("private");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("LPS", $con);

$sql="INSERT INTO points (FirstName, LastName, Tutor)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[tutor]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "New person added";

mysql_close($con)

?>

) and then be able to select the person, and add a house point, and define what event they have done.

 

Lastly, I want there to be an automatic message when the amount of points comes to 6, which can then be acknowledged and stopped.

 

 

Thank you for the help.

 

 

Link to comment
Share on other sites

How would I go about:

Being able to select a person from the database, and then add a house point and which event they did to their name?

EG. There is the database LPS with the table points inside it. The columns in points are FirstName, LastName, Tutor, Events, Points. I want to be able to click on a name and add: a house point and event.

 

Hope this helps.

Link to comment
Share on other sites

I have actually solved this far, but for some reason when I do this:

 


<form action="addpoints.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Points: <input type="text" name="points" />
<input type="submit" />
</form>

addpoints.php:

<?php
$con = mysql_connect("private");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("LPS", $con);

mysql_query("UPDATE points SET Points = '$_POST[points]'
WHERE FirstName = '$_POST[firstname]' AND LastName = '$_POST[lastname]'");

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 point added";

mysql_close($con)
?>

 

I get "Error: Query was empty"

 

How can I stop this?

 

 

Thanks

 

Link to comment
Share on other sites

Nice one thanks. Is there any way of when a name is added, there is the word "add points" next to their name, and when clicked it goes to a page address which is something like addpoints.php?firstname=xyz&lastname=xyz&addpoints=1 . Because there is going to be about 100 entries in this table.

 

 

Thanks

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.