avelonz Posted January 1, 2009 Share Posted January 1, 2009 hey guys. I'm pretty new, so dint go hard one me i need some help setting up a script. there's going to be a form where people can type their name into it. when they click "submit" (when they've typed their name into it) it should add the name they typed in the form, into a table called "points" in the column called "name", in addition, it'll add 1 point for the name in the same table, in a column in the same table called "points2". everytime they do this the script will add one point to their name, until it reaches 30. i want the script to check how many points the name got when they press submit, if the name got 30 points it displays a new form, but only if the name they typed in the form got over 30 points. no need for a function on this form. When they've submitted the form with no function (ill add the function FYI) it'll set the "points2" column to 1 (like a start over). if someone can point me in the right direction i would appreciate your help Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted January 1, 2009 Share Posted January 1, 2009 Hey avelonz, This one is quite simple in a way. Basically, you will write the script to add the name and the number 1 (make sure your table field for points is set to be an INT) to the database. Each time the form is submitted it will first check the database. It will do a query on the name gathering the point column for the each entry of the name. It will then (this is why it is important to make sure it is an INT) add the points together. Then check to see if that total is 30. If it is - open the new form. If it isn't it will just show the original form again and add the name and the 1 point to the database. This sounds like a school assignment so I have given you a walk through as to how it should work...you can do the coding Hope this helps you out without giving out too much info. Quote Link to comment Share on other sites More sharing options...
avelonz Posted January 2, 2009 Author Share Posted January 2, 2009 Hey avelonz, This one is quite simple in a way. Basically, you will write the script to add the name and the number 1 (make sure your table field for points is set to be an INT) to the database. Each time the form is submitted it will first check the database. It will do a query on the name gathering the point column for the each entry of the name. It will then (this is why it is important to make sure it is an INT) add the points together. Then check to see if that total is 30. If it is - open the new form. If it isn't it will just show the original form again and add the name and the 1 point to the database. This sounds like a school assignment so I have given you a walk through as to how it should work...you can do the coding Hope this helps you out without giving out too much info. thanks this helps me out a lot! It's not exactly a school assignment, but sort of. I'll probably manage to do the coding :] Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 You can try this NOT TESTED, or it will give you an i dear mate. database. create database point; use point; create table points( id int auto_increment primary key, points1 int(2) not null, points2 int(2) not null ); <?php $db=mysql_connect("localhost","username","password"); $res=mysql_select_db("point",$db); $sql1="select * from points"; $res1=mysql_query($sql1)or die(mysql_error()); while($row=mysql_fetch_assoc($res1)){ if($row['points1'] < 30){ echo "<form method=' ' action='POST'> Please submit (Current points {$row['points1']}) <input type='hidden' name='points1' value='1'> <input type='submit' name='submit1' value='Add a point'>"; if(isset($_POST['submit1'])){ $points1=$_POST['points1']; $sql2="update points set points1=points1+1 where points1 = '0' || points1 > '0' "; $res2=mysql_query($sql2)or die(myslq_error()); } } if($row['points1'] >30){ $sql3="select * from points"; $res3=mysql_query($sql3)or die(mysql_error()); while($row2=mysql_fetch_assoc($res3)){ echo"<form method=' ' action='POST'> Please submit (Current points {$row2['points2']}) <input type='hidden' name='points2' value='1'> <input type='submit' name='submit2' value='Add a point'>"; if(isset($_POST['submit2'])){ $points2=$_POST['points2']; $sql4="update points set points2=points2+1 where points2 = '0' || points2 > '0'"; $res4=mysql_query($sql4)or die($sql4); while($row3=mysql_fetch_assoc($res4)){ if($row3['points2']=="30"){ $result=$row3['points']+30; echo "You Won The Game with $result!"; exit; } } } } } } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 Sorry database was wrong mate. create database point; use point; create table points( id int auto_increment primary key, points1 int(2) default '0' , points2 int(2) default '0' ); Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 smaller but better . should work. create database point; use point; create table points( id int auto_increment primary key, points1 int(2) default '0' , points2 int(2) default '0' ); <?php $db=mysql_connect("localhost","username","password"); $res=mysql_select_db("dabase_name",$db); $sql1="select * from points"; $res1=mysql_query($sql1)or die(mysql_error()); while($row=mysql_fetch_assoc($res1)){ if($row['points1'] < 30){ echo "<form method=' ' action='POST'> Please submit (Current points {$row['points1']}) <input type='hidden' name='points1' value='1'> <input type='submit' name='submit1' value='Add a point'>"; if(isset($_POST['submit1'])){ $points1=$_POST['points1']; $sql2="update points set points1=points1+1 where points1 = '0' || points1 > '0' "; $res2=mysql_query($sql2)or die(myslq_error()); } } if($row['points1'] >30){ echo"<form method=' ' action='POST'> Please submit (Current points {$row['points2']}) <input type='hidden' name='points2' value='1'> <input type='submit' name='submit2' value='Add a point'>"; if(isset($_POST['submit2'])){ $points2=$_POST['points2']; $sql4="update points set points2=points2+1 where points2 = '0' || points2 > '0'"; $res4=mysql_query($sql4)or die($sql4); while($row3=mysql_fetch_assoc($res4)){ if($row3['points2']=="30"){ $result=$row3['points2']+$row['point1']; echo "You Won The Game with $result!"; exit; } } } } } ?> Quote Link to comment Share on other sites More sharing options...
avelonz Posted January 2, 2009 Author Share Posted January 2, 2009 thanks a lot! i appreciate all the contributions in this thread! :] thanks, solved :] 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.