jeudi 21 janvier 2016

How to insert user_from SESSION along with multiple checkboxes [duplicate]

This question already has an answer here:

I am new to php, I need help with a project I am working on. I am aware that mysql functions are deprecated, but I will be using them for the purpose of this project. I have multiple checkboxes that I wish to insert the values of in my database table (enisatanswer), although I also wish to store the user_id (primary key of my users table) from the user logged on using sessions.

I did have the checkboxes inserting without the user_id although this is essential for me to be able to display content on my next page after I get this part working.

I have a separate column for each of my checkboxes in my table (Log, Worktray, Visual) etc, and a column for user_id. I have tried adding a WHERE statement to the end of my INSERT statement although I am getting an error:

Parse error: syntax error, unexpected ')' in C:\wamp\www\Login\eNISATExec.php on line 31.

Before that I was getting an error: column count does not match at row 1. There is obviously an issue with my $query in eNISATExec.php, although I cannot resolve it.

Any help would be greatly appreciated. Here are my files:

dbconnect.php

<?php
if(!@mysql_connect("localhost","root","#########"))
{
     die('There was connection problem ! --> '.mysql_error());
}
if(!mysql_select_db("dbtest"))
{
     die('There was database selection problem ! --> '.mysql_error());
}
?>

index.php

<?php
session_start();
include_once 'dbconnect.php';

if(isset($_SESSION['user'])!="")
{
 header("Location: home.php");
}
if(isset($_POST['btn-login']))
{
 $username = mysql_real_escape_string($_POST['username']);
 $upass = mysql_real_escape_string($_POST['pass']);
 $res=mysql_query("SELECT * FROM users WHERE username='$username'");
 $row=mysql_fetch_array($res);
 if($row['password']==md5($upass))
 {
  $_SESSION['user'] = $row['user_id'];
  header("Location: home.php");
 }
 else
 {
  ?>
        <script>alert('User name taken or in the wrong format');</script>
        <?php
 }

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NHSCT E-Learning Portal</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="login-form">
<form method="post">
<table align="center" width="30%" border="0">
<tr>
<td><input type="text" name="username" placeholder="Your User Name" required /></td>
</tr>
<tr>
<td><input type="password" name="pass" placeholder="Your Password" required /></td>
</tr>
<tr>
<td><button type="submit" name="btn-login">Sign In</button></td>
</tr>
<tr>
<td><a href="register.php">Sign Up Here</a></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>

home.php

<?php
session_start();
include_once 'dbconnect.php';

if(!isset($_SESSION['user']))
{
 header("Location: index.php");
}
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - <?php echo $userRow['username']; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
 <div id="left">
    <label>NHSCT E-Learning Portal</label>
    </div>
    <div id="right">
     <div id="content">
         Welcome <?php echo $userRow['forename']; ?>&nbsp;<a href="logout.php?logout">Sign Out</a>
        </div>
    </div>
</div>
<br>
<center>
<h1> Select an E-Learning Module<h1>
<br>
<table align="center" height="200" width="30%" border="0">
<tr>
<td><button name="eNISAT" onclick="window.location.href='eNISATExec.php'">eNISAT Tutorials</button></td>
</tr>
<td><button name="Email" "window.location.href='email.php'">Email Tutorials</button></td>

<tr>
</tr>
</table>
</body>
</html>

eNISATExec.php

<?php  
session_start();
include_once 'dbconnect.php';

if(!isset($_SESSION['user']))
{
 header("Location: index.php");
}
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);

if(isset($_POST['submit']))
{      
@$checkbox1=$_POST['Log'];
@$checkbox2=$_POST['Worktray'];
@$checkbox3=$_POST['Visual'];
@$checkbox4=$_POST['ChangePd']; 
@$checkbox5=$_POST['Logout'];
@$checkbox6=$_POST['ClientSearch'];
@$checkbox7=$_POST['StartAssessment'];
@$checkbox8=$_POST['Finalise'];
@$checkbox9=$_POST['Print'];
@$checkbox10=$_POST['Hcn'];
@$checkbox11=$_POST['Lcid'];
@$checkbox12=$_POST['Soscare'];
@$checkbox13=$_POST['Reassign'];
@$checkbox14=$_POST['Close'];

    $query="INSERT INTO enisatanswer (user_id,Log,Worktray,Visual,ChangePd,Logout,ClientSearch,StartAssessment,Finalise,Print,Hcn,Lcid,Soscare,Reassign,Close) VALUES 
    ('$checkbox1', '$checkbox2','$checkbox3', '$checkbox4', '$checkbox5', '$checkbox6','$checkbox7', 
    '$checkbox8','$checkbox9', '$checkbox10','$checkbox11', '$checkbox12', '$checkbox13', '$checkbox14'") WHERE user_id=".$_SESSION['user']";  
    mysql_query($query) or die (mysql_error() );
if($query==1)
   {  
      echo'<script>alert("Inserted Successfully")</script>';  
   }  
else  
   {  
      echo'<script>alert("Failed To Insert")</script>';  
   }  
}  
?>

<html> 
<center>
<br>
<h1>Select the eNISAT tasks that you require assistance with</h3>
<br>
<center>
<h3>Tick each desired task before clicking SUBMIT, then click "Display eNISAT Tutorials" to view your content </h3>
<body bgcolor="sky blue">
<center> 
   <form  action="" method="post" enctype="multipart/form-data">  
   <div style="width:550px;border-radius:6px;margin:50px auto">  
<table border="1" bgcolor = "white">  
   <tr> 
      <td colspan="2">Tick each relevant box:</td>  
   </tr>  
   <tr>  
      <td>How to login</td>  
      <td><input type="checkbox" name="enisat" value="Log"></td>  
   </tr>  
   <tr>  
      <td>How to manage your worktray</td>  
      <td><input type="checkbox" name="enisat" value="Worktray"></td> 
   </tr>  
   <tr>  
      <td>How to change your visual settings (Colours and text size)</td>  
      <td><input type="checkbox" name="enisat" value="Visual"></td> 
   </tr>  
   <tr>  
      <td>How to change your own password on the system</td>  
      <td><input type="checkbox" name="enisat" value="ChangePd"></td>  
   </tr>  
   <tr>  
      <td>How to logout of the system</td>  
      <td><input type="checkbox" name="enisat" value="Logout"></td> 
   </tr>  
   <tr>  
      <td>How to search for a client on the system</td>  
      <td><input type="checkbox" name="enisat" value="ClientSearch"></td> 
   </tr>  
   <tr> 
      <td>How to start an assessment</td>  
      <td><input type="checkbox" name="enisat" value="StartAssessment"></td> 
   </tr>  
   <tr>
      <td>How to finalise an assessment</td>  
      <td><input type="checkbox" name="enisat" value="Finalise"></td>  
   <tr>  
      <td>How to print an assessment</td>  
      <td><input type="checkbox" name="enisat" value="Print"></td>  
   </tr>  
   <tr>  
      <td>How to create a client and referral manually through Find on H+C</td>  
      <td><input type="checkbox" name="enisat" value="Hcn"></td>  
   </tr>  
   <tr>  
      <td>How to submit a referral from LCID (LCID Users only)</td>  
      <td><input type="checkbox" name="enisat" value="Lcid"></td> 
   </tr>  
   <tr>  
      <td>How to submit a referral from Soscare (Soscare Users only)</td>  
      <td><input type="checkbox" name="enisat" value="Soscare"></td> 
   </tr>  
   <tr>  
      <td>How to reassign a referral on eNISAT</td>  
      <td><input type="checkbox" name="enisat" value="Reassign"></td> 
   </tr>  
   <tr>  
      <td>How to close a referral on eNISAT</td>  
      <td><input type="checkbox" name="enisat" value="Close"></td>
   </tr> 
   <tr>  
      <td colspan="2" align="center"><input type="submit" value="SUBMIT" name="submit"></td>  
   </tr>  
</table>  

<br><a href="displayeNISATVideo.php">Display eNISAT Tutorials</a>
</div>  
</form>  
</body>  
</html>  




Aucun commentaire:

Enregistrer un commentaire