Difference between revisions of "PHP 6"

From Ilianko
Line 13: Line 13:
  
 
<code><pre>
 
<code><pre>
<?php
+
<?php  
 +
  //conection:
 
   $link = mysqli_connect("localhost","student","3405","student");  
 
   $link = mysqli_connect("localhost","student","3405","student");  
 
   mysqli_query($link, "SET NAMES utf8");
 
   mysqli_query($link, "SET NAMES utf8");
Line 27: Line 28:
 
  <form action="check.php" method="POST">
 
  <form action="check.php" method="POST">
 
  <?php
 
  <?php
  //conection:
 
  
 
//consultation:
 
//consultation:

Revision as of 13:23, 24 October 2013

Връзки с MySQL

Основни функции

  • mysqli_connect();
  • mysqli_query();
  • mysqli_fetch_assoc();
  • mysqli_real_escape_string();


Извличане на информация от база данни

<?php 
  //conection:
  $link = mysqli_connect("localhost","student","3405","student"); 
  mysqli_query($link, "SET NAMES utf8");
  mb_internal_encoding('utf-8');
  
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8"  />
  </head>
<body>
 <form action="check.php" method="POST">
 <?php

//consultation:
$query = "SELECT * FROM  `Questions`";

//execute the query.
$result = mysqli_query($link, $query);


//display information:
$x = 0;
while($row = mysqli_fetch_array($result)) {
  
  $x++;	
  echo $x.'  -  '.$row['question'].'<br>';
 
  $query = 'SELECT * FROM  `Answers` WHERE  `id_question` = '.$row['id'];
  $otgovori =  mysqli_query($link, $query);
  
  $i = 97; 
  while($otgovor = mysqli_fetch_array($otgovori)) {	
    echo  chr($i++).'<input type="radio" name="question['.$row['id'].']" value="'.$otgovor['id'].'">'.$otgovor['answer']."<br /> \n"; 
  }
}
 

?>
  <input type="submit" name='submit' value="Submit">
  </form>
</body>
</html>