php - Have I written the INSERT query correctly? -


this question exact duplicate of:

here code:

        <?php        include('admin/class.php'); 

here db connection:

       $link = mysqli_connect("localhost", "root", "", "timesheet1234"); 

here action save button:

        if(isset($_post['save']))         {           $user=$_session['user'];         $sel =$_post["selpro"];         $mon =$_post["mon"];         $tue =$_post["tue"];         $wed =$_post["wed"];         $thu =$_post["thu"];         $fri =$_post["fri"];         $sat =$_post["sat"];         $sun =$_post["sun"];     

checking whether $user in db not:

        $sql=mysqli_query($link,"select * emp                           username='".$_session['user']."'");         $res=mysqli_num_rows($sql); 

here checks whether insert not:

        if($res==0)         {           $sql1 = mysqli_query($link,"insert  emp set username='$user',          project code='$sel',mon=$mon,tue=$tue,wed=$wed,                   thu=$thu,fri=$fri,sat=$sat,sun=$sun"); 

here problem comes:

         if($sql1){          echo "<script type='text/javascript'>";          echo "alert('timesheet saved..!')";          echo "</script>";          echo "<script type='text/javascript'>";          echo "window.location='my_tm.php'";          echo "</script>";          }           else           {          echo "<script type='text/javascript'>";          echo "alert('some error occured ! retry..!')";          echo "</script>";          echo "<script type='text/javascript'>";          echo "window.location='my_tm.php'";          echo "</script>";          }          }          }          ?> 

isnt problem if($res==0)? because check if session user in database , store number of rows in $res. guess want insert query when $res==1 (one user) , not when there no user.

also have complete control on session variables. once store user in there, can trust there. unless ofcourse made mistakes on authentication process.

also in javascript code want use window.location.href='my_tm.php change url , not window.location


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -