Click here to Skip to main content
15,893,790 members
Home / Discussions / Web Development
   

Web Development

 
SuggestionSuggestion Pin
thatraja20-Nov-13 2:25
professionalthatraja20-Nov-13 2:25 
QuestionRe: using session variable with window.location Pin
Richard MacCutchan20-Nov-13 2:38
mveRichard MacCutchan20-Nov-13 2:38 
AnswerRe: using session variable with window.location Pin
Jenno Richi26-Nov-13 20:31
Jenno Richi26-Nov-13 20:31 
Question(An error occurred) with facebook share Pin
Jassim Rahma20-Nov-13 1:26
Jassim Rahma20-Nov-13 1:26 
AnswerRe: (An error occurred) with facebook share Pin
Jenno Richi26-Nov-13 20:22
Jenno Richi26-Nov-13 20:22 
AnswerRe: (An error occurred) with facebook share Pin
Blikkies26-Nov-13 20:40
professionalBlikkies26-Nov-13 20:40 
Questionhelp with dropdown button Pin
Jassim Rahma19-Nov-13 22:34
Jassim Rahma19-Nov-13 22:34 
QuestionPROBLEM WITH CHECKBOX Pin
faizalizy19-Nov-13 16:53
faizalizy19-Nov-13 16:53 
HELLO

I am new to PHP and web based environment (noob), previously i was facing a problem with my code which is i cannot update the mysql table row when checkbox is checked... the idea is when checkbox is checked, then the value is +1. This is somehow likely to update the row on the table..

here is the code: (sorry if the code are messy because i also find the code in internet and edit it)

PHP code:

XML
<html><body>
 <?php
$con = mysql_connect("localhost","faiz","faiz");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }
mysql_select_db('log');

$sql = array('candidate1', 'candidate2', 'candidate3', 'candidate4','candidate5','candidate6','candidate7','candidate8','candidate9','candidate10');

if(isset($_POST['Submit']))
{   $candidate = $_POST['candidate'];
   $values = array();
    foreach($sql as $selection )
    {     if(in_array($selection, $candidate))
            { $values[ $selection ] = 1;  }
        else
            { $values[ $selection ] = 0;  }
         } // end of foreach.

$sql = "UPDATE admin SET candidate1=candidate1 +1 WHERE candidate = candidate1.
mysql_query($sql,$con) or die('<br/>Error reading database: '.mysql_error($con));

header("location:  ");

mysql_close($con);
}  // End of, if statement from the button check
?>
</body></html>



AND HERE IS THE INDEX:
VotePage.php

XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>VOTING PAGE</title>

<script language="JavaScript" type="text/javascript">

function checkTheBox() {
var flag = 0;
for (var i = 0; i< 4; i++) {
if(document.form1["candidate[]"][i].checked){
flag ++;
}
}
if (flag != 5) {
alert ("PLEASE SELECT 5 CANDIDATE ONLY");
return false;
}
return true;
}


</script>

</head>

<body>
<center>
        <div class="checkbox" data-toggle="false" data-min="2">
        <table width="800" height="600" bgcolor="#28b6ee" border="0"  align="center">
        <h1>LIST OF CANDIDATE</h1>
            <form name="form1" method="Post" action="CheckCandidate.php">
                    <tr width="800" height="600" >
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 1" align="top">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 2">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 3">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 4">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 5">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td></tr>
                    <tr>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 6">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 7">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 8">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 9">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                        <td width="160" height="50">
                            <img src="Voter.jpg" alt="Vote 10">
                            <input type="checkbox" name="candidate[]" value="1" />
                        </td>
                    </tr>

            </table>
      </div>
      <div>
        <table align="center">
                <tr >
                    <td align="center" width="800" height="50">
                        <input type="Submit" name="Submit" value="Submit" onclick="checkTheBox();" />
                    </td>

                </tr>
        </table>
       </div>


          </table>


        </div>
</form>
</center>
</body>
</html>




I'll BE GLAD IF THERE IS SOME ONE CAN SPEND SOMETIME TO LOOK AT THIS PROBLEM..THANK YOU

modified 20-Nov-13 0:45am.

GeneralRe: PROBLEM WITH CHECKBOX Pin
Peter Leow20-Nov-13 6:17
professionalPeter Leow20-Nov-13 6:17 
AnswerRe: PROBLEM WITH CHECKBOX Pin
Amir Hamza Md. Kayes1-Dec-13 21:27
professionalAmir Hamza Md. Kayes1-Dec-13 21:27 
Questionwhy getting: Uncaught ReferenceError: jQuery is not defined Pin
Jassim Rahma19-Nov-13 2:05
Jassim Rahma19-Nov-13 2:05 
QuestionProblem with dropdown button Pin
Jassim Rahma19-Nov-13 0:47
Jassim Rahma19-Nov-13 0:47 
SuggestionRe: Problem with dropdown button Pin
Richard Deeming19-Nov-13 2:21
mveRichard Deeming19-Nov-13 2:21 
Questionhow to open Profile manager on Windows Pin
TheSniper10518-Nov-13 2:43
professionalTheSniper10518-Nov-13 2:43 
AnswerRe: how to open Profile manager on Windows Pin
Richard Deeming18-Nov-13 2:50
mveRichard Deeming18-Nov-13 2:50 
GeneralRe: how to open Profile manager on Windows Pin
TheSniper10518-Nov-13 3:01
professionalTheSniper10518-Nov-13 3:01 
QuestionProblem with RewriteRule Pin
Jassim Rahma18-Nov-13 2:00
Jassim Rahma18-Nov-13 2:00 
Questionis that time to enable GZIP Compression? Pin
TheSniper10518-Nov-13 0:11
professionalTheSniper10518-Nov-13 0:11 
AnswerRe: is that time to enable GZIP Compression? Pin
Richard MacCutchan18-Nov-13 0:59
mveRichard MacCutchan18-Nov-13 0:59 
GeneralRe: is that time to enable GZIP Compression? Pin
TheSniper10518-Nov-13 2:11
professionalTheSniper10518-Nov-13 2:11 
GeneralRe: is that time to enable GZIP Compression? Pin
Richard MacCutchan18-Nov-13 2:20
mveRichard MacCutchan18-Nov-13 2:20 
GeneralRe: is that time to enable GZIP Compression? Pin
TheSniper10518-Nov-13 2:27
professionalTheSniper10518-Nov-13 2:27 
GeneralRe: is that time to enable GZIP Compression? Pin
Richard MacCutchan18-Nov-13 2:55
mveRichard MacCutchan18-Nov-13 2:55 
GeneralRe: is that time to enable GZIP Compression? Pin
TheSniper10518-Nov-13 2:57
professionalTheSniper10518-Nov-13 2:57 
AnswerRe: is that time to enable GZIP Compression? Pin
thatraja18-Nov-13 2:36
professionalthatraja18-Nov-13 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.