php - Comparing data and updating table -


i have 2 tables: voted_sites(usn,url,vote,votefor) , sites(url,status,upvotes,downvotes,id).

for logged-in user have update reputation, stored in repute field, based on valid votes has given, voted_sites has has voted , sites table result of site (either ublocked or blocked).

if user has upvoted unblock , site table status unblock have give increase reputation 5, , should happen (traverse) through tuples , give final reputation score user.

i've tried number of ways, unsuccessful in attempts. didn't know how operations on 2 tables simultaneously when can connect 1 table using mysqli_fetch_assoc($sql).

this tried:

<!doctype html>  <html>  <?php  $c=$_get['param'];// users name  $d=$_get['param1'];// usesrs id  $e=$_get['param2'];//  users repute      // create connection  $con=mysqli_connect("localhost","root","","repute system");      if(mysqli_connect_errno()){          echo "error ".mysqli_connect_error();  }     $qwe = mysqli_query($con,"select * sites");  $sql = mysqli_query($con,"select * v_sites");  if (mysqli_num_rows($sql) > 0) {      // output data of each row      while($row = mysqli_fetch_assoc($sql))       {                    if($d == $row['teacher_id'])          {              while ($raw = mysqli_fetch_assoc($qwe))              {                          $rt = $row['votefor'];                   $qt = $raw['status'];                      if($row == $raw)                      {                          $er = mysqli_query($con,"update teacher set repute = repute + '5'  name == '$c' ");                      }                      else                       {                          $er = mysqli_query($con,"update teacher set repute = repute - '5'  name == '$c' ");                      }              }                               }      }  }     ?>  </html>

you using 2 equal signs in both where clauses instead of one, using string literals around number wish increase by.

update teacher set repute = repute + '5'  name == '$c'                                                      ^^ 

and

update teacher set repute = repute - '5'  name == '$c'                                                      ^^ 

those should read as:

update teacher set repute = repute + 5  name = '$c' 

and

update teacher set repute = repute - 5  name = '$c' 

respectively.

when testing, add or die(mysqli_error($con)) both mysqli_query() in order see syntax errors being made, if during development.

  • sidenote: make sure repute column indeed int , of proper length.

add error reporting top of file(s) find errors.

<?php  error_reporting(e_all); ini_set('display_errors', 1);  // rest of code 

sidenote: error reporting should done in staging, , never production.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -