<?php


include 'config.php';

$intrebare = $_POST['intrebare'];
$nume = $_POST['nume'];
$oponent1 = $_POST['oponent1'];
$oponent2 = $_POST['oponent2'];
$img1 = $_POST['img1'];
$img2 = $_POST['img2'];
$com1 = $_POST['com1'];
$com2 = $_POST['com2'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$vote1 = $_POST['vote1'];
$vote2 = $_POST['vote2'];
$id = $_GET['id'];

    $link = mysql_connect($baza['host'], $baza['user'], $baza['pass'])
        or die("Could not connect : " . mysql_error());
    mysql_select_db($baza['nume']) or die("Eroare!, nume baza de date incoreta");
$table = $baza['table'];


if ($_POST['send'] == "") {
    $a = mysql_fetch_assoc(mysql_query("SELECT * FROM $table  WHERE id = '$id'"));
$intrebare = $a['intrebare'];
$nume = $a['nume'];
$oponent1 = $a['oponent1'];
$oponent2 = $a['oponent2'];
$img1 = $a['img1'];
$img2 = $a['img2'];
$com1 = $a['com1'];
$com2 = $a['com2'];
$email = $a['email'];
$pass = $a['pass'];
$vote1 = $a['votes1'];
$vote2 = $a['votes2'];
$id = $a['id'];
$date = $a['date'];
echo <<<HTML
<br /><br /><br />
<center>
<form action="admin.php?p=edit&id=$id" method="post">
  <table border="0">
<tr>
 <td><h3>Editare sondaj $id:</h3></td>
 <td> </td>
</tr>
<tr>
 <td><b>Denumirea sondajului:</b></td>
 <td><input name="nume" value="$nume" size="25"></td>
</tr>
<tr>
 <td><b>Intrebare:</b></td>
 <td><input name="intrebare" value="$intrebare" size="25"></td>
</tr>
<tr>
 <td><b>Numele Oponent 1: </b></td>
 <td><input name="oponent1" value="$oponent1" size="25"></td>
</tr>
<tr>
 <td><b>Imagine Oponent 1: </b></td>
 <td><textarea name="img1" >$img1</textarea></td>
</tr>
<tr>
 <td><b>Comentariu Oponent 1: </b></td>
 <td><input name="com1" value="$com1" size="25"></td>
</tr>
<tr>
 <td><b>Vuturi Oponent 1: </b></td>
 <td><input name="vote1" value="$vote1" size="25"></td>
</tr>
<tr>
 <td><b>Numele Oponent 2: </b></td>
 <td><input name="oponent2" value="$oponent2" size="25"></td>
</tr>
<tr>
 <td><b>Imagine Oponent 2: </b></td>
 <td><textarea name="img2" >$img2</textarea></td>
</tr>
<tr>
 <td><b>Comentariu Oponent 2: </b></td>
 <td><input name="com2" value="$com2" size="25"></td>
</tr>
<tr>
 <td><b>Vuturi Oponent 2: </b></td>
 <td><input name="vote2" value="$vote2" size="25"></td>
</tr>

<tr>
 <td><b>&nbsp;</b></td>
 <td>&nbsp;</td>
</tr>

<tr>
 <td><b>E-Mail: </b></td>
 <td><input name="email" value="$email" size="25"></td>
</tr>
<tr>
 <td><b>Password: </b></td>
 <td> <input name="pass" value="$pass" size="25"></td>
</tr>

<tr>
 <td><b>&nbsp;</b></td>
 <td>&nbsp;</td>
</tr>
<tr>
 <td><b></b></td>
 <td><input type="submit" name="send" value="Salveaza"></td>
</tr>
 </table>
 </form>
 </center>
 <hr />
HTML;
} else {

mysql_query("UPDATE $table SET
 nume = '$nume', email = '$email' , intrebare = '$intrebare', oponent1 = '$oponent1',
  oponent2 = '$oponent2', img1 = '$img1', img2 = '$img2', com1 = '$com1', com2 = '$com2', pass = '$pass', votes1 = '$vote1', votes2 = '$vote2'  
 WHERE id = '$id'");
 echo 'Salvat cu succes!';
}
?>