Hi I have managed to set up a players database log-in with name number e-mail and am trying to get a buton on the players home page that when clicked adds one to thier total,

Do I have to set up a new database for this or a new table in the base i have ?

I am looking to run a sort of mental olympics so there will be numbers coming in from difrent pages with in the site.

I have got this far ,

<HTML><HEAD><TITLE>Player #001</TITLE><META content="text/html; charset=utf-8" http-equiv=Content-Type><META name=GENERATOR content="MSHTML 10.00.8400.0"><STYLE type=text/css>BODY {
    FONT-FAMILY: verdana, arial, sans-serif
}</STYLE></HEAD><BODY>
<FORM style="BORDER-TOP-COLOR: ; BORDER-BOTTOM-COLOR: ; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR: " method=post action=default.cgi>
Welcombe Player: <INPUT value=get_player_base name=player>&nbsp;
<INPUT type=submit value="+1 click" name=click>&nbsp;clicks this visit = 
<INPUT style="HEIGHT: 22px; WIDTH: 61px" size=1 value=0000000 name=clicksnow>&nbsp;total number of clicks to date = 
<INPUT value=get_total_clicks name=totalclicks><BR>
</FORM>
</BODY></HTML>

do I have to connect to the database in the headder and read the numbers or do i conect in the php after </form> ?
thanks.

if I have to make a new database is thata relation database ?

Whether you use your current database or a new one is up to you. If you want to store it, you should change the script where the action attribute of the form points to, or write some javascript code to intercept the submit and do an ajax call first to a new script you write.

Whether you use your current database or a new one is up to you. If you want to store it, you should change the script where the action attribute of the form points to, or write some javascript code to intercept the submit and do an ajax call first to a new script you write.

Hi prita eas,
do you mean something like
"
make a button action
action = click_box_1.php
then make action = openbase.read_box1.add1_box1.then_echo.click_box1 (is it here I code to get action to add + 1 to box_2 ect. ? ie. if box_1== +9 then echo "wot ever is here");
.end_script "

would this "script" go in the head or body of the .html form ?

thanks for helping prita eas.

kniggles.

If you change action="click_box_1.php" then just make sure that script is on the server with that name. The form will be posted to that script, and then you can do whatever you want with the form's data.

 is ths headding in the right direction ?

 have the database set up with a
 table = clicks
 with rows
 id = int = 1  {just one record set in base for now}
click = int 



<HTML><HEAD><META name=GENERATOR content="MSHTML 10.00.8400.0"></HEAD><BODY>




<FORM style="BORDER-TOP-COLOR: ; BORDER-BOTTOM-COLOR: ; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR: " method=post name=frmOne action=try.php>

W2+:clicks_count=: <INPUT style="BACKGROUND-COLOR: #654321" size=5 value=0 name=w>
<P>
Total Z:hello player=: <INPUT size=5 value=1 name=z></P>
<P>
<INPUT onclick=calculate() type=button value="Pluss One" name=b1></P>
</FORM>


<SCRIPT language=javascript type=text/javascript>
function calculate() 
    require("connect.php");
    $query = mysql_query("SELECT click FROM clicks WHERE id='1'") or die(mysql_error())
      $query = document.frmOne.w.value;
{
A = document.frmOne.w.value;
A = Number(A);
C = A+1;
document.frmOne.w.value =  C;

return colourchange();
}</SCRIPT>
<SCRIPT language=javascript type=text/javascript>
function colourchange()
 { 
    var red=Math.floor(Math.random()*256)
     var green=Math.floor(Math.random()*256)
      var blue=Math.floor(Math.random()*256)

    document.frmOne.z.style.backgroundColor = "rgb("+red+","+green+","+blue+")";
}</SCRIPT></BODY></HTML>

have tried this and nothing happens when buton pressed, not even a refresh.

You are trying to execute a PHP script (that runs server-side) in a Javascript script block (which runs client side). That will never work. Your calculate function should be in Javascript, using AJAX, to call the PHP script on the server.

Not realy knowing what AJAX is I would guess you are saying

I need to replace

require("connect.php");

with an AJAX call to the connect.php in the html <head> </head> ?

so when player (1) clicks buton1 the Java runs ,the AJAX calls the php to talk with base then uploads the +1 and echos new number. in click_box1 .

Hows this looking ? not to sure about the mysql line though.

<HTML><HEAD><TITLE></TITLE><META content="text/html; charset=utf-8" http-equiv=Content-Type><META name=GENERATOR content="MSHTML 10.00.8400.0"><STYLE type=text/css>BODY {
    FONT-FAMILY: verdana, arial, sans-serif
}</STYLE>
<SCRIPT type=text/javascript>
function loadXMLDoc()
{
  //.... AJAX script goes here ...


var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","connect.php",true);
//mysql_querry
$query = mysql_query("SELECT click FROM clicks WHERE id='1'") or die(mysql_error())



xmlhttp.send();

}</SCRIPT></HEAD><BODY>

<DIV id=myDiv><H2><FORM style="BORDER-TOP-COLOR: ; BORDER-BOTTOM-COLOR: ; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR: " method=post>
Welcombe Player: <INPUT value=$id name=player>&nbsp;
<INPUT value=$clicks name=totalclicks><BR>
</H2></DIV>
<BUTTON onclick=loadXMLDoc()>Pluss 1 click</BUTTON>
</FORM>
</BODY></HTML>

connect.php =

<?php

mysql_connect ("localhost" ,"localuser", "abc123doerayme");
mysql_select_db("db_clicks")
 $query = mysql_query("SELECT click FROM table_clicks WHERE id='$row'") or die(mysql_error())
       echo "<table border='1'>
<tr>
<th>player</th>
<th>Clicks</th>
</tr>";

while($row = mysql_fetch_array($query))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['clicks'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

 mysql_close();


?>
<HTML><HEAD>
<META name=GENERATOR content="MSHTML 10.00.8400.0"></HEAD>
<BODY></BODY></HTML>
index
<HTML><HEAD><TITLE></TITLE><META content="text/html; charset=utf-8" http-equiv=Content-Type><META name=GENERATOR content="MSHTML 10.00.8400.0"><STYLE type=text/css>BODY {
    FONT-FAMILY: verdana, arial, sans-serif
}</STYLE>
<SCRIPT type=text/javascript>
    function loadXMLDoc()
    {
    //.... AJAX script goes here ...
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","connect.php",true);
    //mysql_querry
    //$query = mysql_query("SELECT click FROM clicks WHERE id='1'") or die(mysql_error())
    xmlhttp.send();
    }</SCRIPT></HEAD><BODY>
    <DIV id=myDiv><H2><FORM style="BORDER-TOP-COLOR: ; BORDER-BOTTOM-COLOR: ; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR: " method=post>
    Welcombe Player: <INPUT value=$id name=player>&nbsp;
    <INPUT value=$clicks name=totalclicks><BR>
    </H2></DIV>
    <BUTTON onclick=loadXMLDoc()>Pluss 1 click</BUTTON>
    </FORM>
    </BODY></HTML>

cant see where the clicks get updated to include the new click count ?

  1. There are syntax errors in your script.
  2. There is no ID passed from the HTML to your script.
  3. A SELECT query does not update the number of clicks in your table.
commented: Very helpfull, player should allready be logged in ,there4 the id should allready be on the page. {not select, gona try-update echo new} +2

I need to use [connect.php] to "echo" players "id"# into the id box to get onto page; =myquerry_1_=player$id Q1
I need to use [connect.php] to update and "echo" new number of "clicks"; =mybutton_+1 = mysql_update Q2
``thinking about another .php page "updateclicks.php" this is for when buton_addclick pressed connect.php is run inside b4 mysql_update to pluss 1;

Ah, right. Well:
- in the Js open you could add the id you need, e.g. xmlhttp.open("GET","connect.php?id=1",true);
- In the PHP script you can use $_GET['id']

Have been playing about and have got

<?php 


$con = mysql_connect("localhost","localuser","123abcdoerayme");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db91m", $con);

mysql_query("UPDATE users SET clickcount = clickcount+1 WHERE user_name=user_name");


mysql_close($con);

//return to - myaccount.php()

?>

To update and +1 to the clickcount, however have not got it to post back to { myaccount.php} and cant get clickcount to echo into myaccount.php yet either. when button pressed to +1 it gos to account1.php and stays on a white page.

myaccount.php reads

<?php 
include 'dbc.php';
page_protect();


?>
<html>
<head>
<title>My Account</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
  <tr> 
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr> 
    <td width="160" valign="top">
<?php 

if (isset($_SESSION['user_id'])) {?>
<div class="myaccount">
  <p><strong>My Account</strong></p>
  <a href="myaccount.php">My Account</a><br>
  <a href="mysettings.php">Settings</a><br>
    <a href="logout.php">Logout </a>


<?php }
if (checkAdmin()) {

?>
      <p> <a href="admin.php">Admin CP </a></p>
      <?php } ?>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <td width="732" valign="top"><p>&nbsp;</p>
      <h3 class="titlehdr">Welcome <?php echo $_SESSION['user_name'];?>  </h3>
      <form name="form1" method="post" action="myaccount1.php">
        <input name="clicks" type="text" id="clicks" value="00009<?php echo $_SESSION['clickcount'];?>" readonly="readonly">



        **
        //if I make that read <input name="clicks" type="text" id="clicks" value="00009<?php echo $_SESSION['user_name'];?>" readonly="readonly"> it puts the user_name into the textbox where i want the clcikcount, why wont the clickcount number work when i change it  ?**



        <input type="submit" name="button1" id="button1" value="+1 click">
      </form>  
      <?php  
      if (isset($_GET['msg'])) {
      echo "<div class=\"error\">$_GET[msg]</div>";
      }

      ?>
      <p>This is the my account page</p>


      </td>
    <td width="196" valign="top">&nbsp;</td>
  </tr>
  <tr> 
    <td colspan="3">&nbsp;</td>
  </tr>
</table>

</body>
</html>

not to sure about AJAX though do i still need to use it ?

You can choose. You can redirect the update script back to your page, or you can use AJAX so you never leave your page. In the last case you will need to do some extra processing to update the clicks.

been trying to work out the code to redirect it back to the page , however do like the AJAX method, , also found out that the +1 script will update just the player name clicks on one log in , however when i log in under another players number and try the +1 the whole coloum adds 1 to every player.

with the AJAX way would I put it in the <head> so

> <form name="form1" method="post" action="myaccount1.php">
would become <form name="form1" method="post" action="loadXMLDoc()">

Well kind of, not sure if that works, but you can also but an onclick="" in the submit button.

> <BUTTON onclick=loadXMLDoc()>Pluss 1 click</BUTTON>

``this calls fuction "loadXMLDoc() " when clicked ,

loadXMLDoc calls the the "connect.php" so the mysql query should be in that file with a return to "form1" ?

it should work like a personal "LIKE" like button, only the player is the only one that can click it and everyone has thier own .

` > <input type="submit" name="button1" id="button1" value="+1 click">
the other way would look something like

` > <input type="submit" name="button1" id="button1" value="+1 click" onclick="loadXMLDoc()" >

?

thanks for helping priteas ,

If you call your +1 update script via AJAX, then that script does not need to do a redirect. You will stay on the page you are on. To this update script you need to pass the id or name from the user you want to update. So your AJAX call will look something like this: xmlhttp.open("GET","update.php?userid=1",true); Your update script can then access $_GET['userid']

Hi Pritaes, Have got it down to this ,

<html>
<head>
<title>sofar...</title>
<script language="javascript" type="text/javascript">
function calculate() 
{
A = document.frmOne.w.value;
A = Number(A);
C = A+1;
document.frmOne.w.value =  C;

}
</script>

<script language="javascript" type="text/javascript">
function nigel2() 
{
A = document.frmOne.w.value;
A = Number(A);
C = A+1;
document.frmOne.w.value =  C;

}
</script>



</head>
<body>
<form name="frmOne">
  <table cellspacing=2 cellpadding=1 width="100%" border=1>
  <tbody>
    <tr>
      <td width="300" height=21 valign=top>&nbsp;</td>
      <td height=21 align="center" valign=top><p><span style="font-size: xx-large;">Q Concept Garages</span></p></td>
      <td width="300" height=21 valign=top><p>&nbsp;</p></td>
      <td width="21" height=21 valign=top><p>&nbsp;</p></td>
    </tr>
    <tr>
      <td width="300" height=21 valign=top><p>
        <?php

 $con = mysql_connect("locakhost", "me", "abc123doeray");
 if (!$con)
{
 die('Could not connect: ' . mysql_error());
  }
mysql_select_db("table1", $con);
//----------------------------------------------

//----------------------------------------------


$result = mysql_query("SELECT * FROM `xpic` ORDER BY RAND() LIMIT 0,1;");

echo "<table border='9'><tr>
<th>xxxx</th></tr>";

while($row = mysql_fetch_array($result))

  {
  echo "<tr>";

    echo '<td><img width="300" hight="300" src="',$row['pic'],'"/></a></td>';

 echo "</tr>";
  }
echo "</table>";


mysql_close($con);
?>
      </p></td>
      <td height=21 align="center" valign=top><p>
        <input type="text" name="w" style="background-color: #000080; color: #CF0;" size="5" value="0" />
      </p>
        <p>
          <input type = Button name = "b3" value = "Change A" onclick = nigel2() />
          <input type = Button name = b1 value = "Pluss One" onclick = calculate() />
          <input type = Button name = "b2" value = "Change B" onclick = "calculate()" />
      &nbsp;</p></td>
      <td width="300" height=21 align="right" valign=top><p>
        <?php

 $con = mysql_connect("locakhost", "me", "abc123doeray");
 if (!$con)
{
 die('Could not connect: ' . mysql_error());
  }
mysql_select_db("table1", $con);
//----------------------------------------------

//----------------------------------------------


$result = mysql_query("SELECT * FROM `xpic` ORDER BY RAND() LIMIT 0,1;");

echo "<table border='9'><tr>
<th>xxxx</th></tr>";

while($row = mysql_fetch_array($result))

  {
  echo "<tr>";

    echo '<td><img width="300" hight="300" src="',$row['pic'],'"/></a></td>';

 echo "</tr>";
  }
echo "</table>";


mysql_close($con);
?>

</form> 
</body>
</html>

Now have the numbers adding +1 , and know that I need to make one of the mysql = boxA and the other boxB ,so when button change A is pressed just boxA changes. ,am looking at changing the echo line i think, also is this the same button where the AJAX will be placed ?
also is there a way to just use one lot of data base conection ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.