I have a table 'users' with columns 'Id' and 'Name'
I have another table 'pra' with columns 'User_Id', 'Pra_Id' & 'Name'
When the script below is runs, it suppose to query the column 'Name' from the table 'users' and insert it into the column 'Name' of table 'pra'. Other data will also be inserted into 'User_Id', 'Pra_Id'.
Please help. Thanks!
Code: Select all
<?php
$visitingfiledirectly = false;
if($visitingfiledirectly)
{
?>
<link rel="stylesheet" type="text/css" media="screen" href="../stylus.css">
<?php
}
?>
<?php
$id = 0;
$b = 0;
$user_pra_id = -1;
$printpra = true;
if(isset($_GET["id"]) && is_numeric($_GET["id"]))
{
$id = $_GET["id"];
}
if(isset($_GET["b"]) && is_numeric($_GET["b"]))
{
$b = $_GET["b"];
}
if(isset($_GET["id"]) && is_numeric($_GET["id"]) && isset($_GET["delete"]) && is_numeric($_GET["delete"]) && isset($_SESSION["username"]) && isset($_SESSION["password"]))
{
$admin = getMyAdminLevel();
$checkpra = mysql_query("SELECT Owner FROM pra WHERE Id='".$id."'"); // FIND IF THERE IS A VALIDATION ENTRY WITH THE CODE RECEIVED
$pra = mysql_fetch_array($checkpra);
if(($admin >= 1 || $pra["Owner"] == $_SESSION["username"]) && $_GET["delete"] == 7)
{
mysql_query("DELETE FROM pra WHERE Id='".$_GET["id"]."'")
or die(mysql_error());
?><div class="warning">blablabla!</div><?php
$printpra = false;
}
}
if($printpra)
{
?>
<table border="0" width="100%">
<?php
$checkpra = mysql_query("SELECT Id, Owner, Title, Short, Description, Date FROM pra WHERE Id='".$id."'"); // FIND IF THERE IS A VALIDATION ENTRY WITH THE CODE RECEIVED
$pra = mysql_fetch_array($checkpra);
$checkuser = mysql_query("SELECT Id, Avatar FROM users WHERE Username='".$pra["Owner"]."'"); // FIND IF THERE IS A VALIDATION ENTRY WITH THE CODE RECEIVED
$user = mysql_fetch_array($checkuser);
$user_pra_id = $user["Id"];
$admin = getMyAdminLevel();
//------------------------
$result = mysql_query("SELECT Name from users WHERE Username='".$_SESSION["username"]."'");
$row = mysql_fetch_array($result);
$name = $row["Name"];
$query = 'INSERT INTO pra (User_Id, Pra_Id, Name)
VALUES (\''.$user_pra_id.'\',\''.$pra_id.'\',\''.$name.'\')';
mysql_query($query) or die(mysql_error());
if($pra > 0)
{
?><div class="praentry"><?php
if($admin >= 1 || (isset($_SESSION["username"]) && $_SESSION["username"] == $pra["Owner"]))
{
?>
<div class="admin">
<div class="previous"><a href="index.php?section=editpra&id=<?php echo $_GET["id"];?>"><b>Edit this petition</b></a></div>
<div class="next"><a href="index.php?section=readpra&id=<?php echo $_GET["id"];?>&delete=7"><font color="#FF0000"><b>Delete this</b></font></a></div>
</div>
<?php
}
if($b == 1)
{
setPra($id);
}
?>
<tr><td><div class="miniavatar">
<?php useLightbox($user["Avatar"],$pra["Owner"],50,50);?>
</div>
<div class="pramini">
<h1><a href="index.php?section=readpra&id=<?php echo $pra["Id"];?>"><?php echo $pra["Title"];?></a></h1><br>
<?php echo $pra["Short"];?><br>
submitted by <a href="index.php?section=profile&uid=<?php echo $user["Id"];?>"><?php echo $pra["Owner"];?></a> <?php echo referencialHour($pra["Date"]);?>
</div>
</div></td></tr>
<tr><td><div class="pradescription">
<?php echo $pra["Description"];?><br>
<div style="text-align:right; width:100%; border:0px;">submitted by <a href="index.php?section=profile&uid=<?php echo $user["Id"];?>"><?php echo $pra["Owner"];?></a> <?php echo referencialHour($pra["Date"]);?></div>
</div></td></tr>
<?php
if($admin >= 0)
{
?>
<tr><td><?php
$pra = ifPra($id);
if(($pra == -1 || $pra == 0) && $pra["Owner"] != $_SESSION["username"])
{
?>
<div class="pfor">
You haven't.<br>
please <a href="index.php?section=readpra&id=<?php echo $id;?>&b=1">click here</a>
<?php
if($admin >= 1)
{
?><br>People who has:<br><?php
printWhoHasPra($id);
}
?></div><?php
}
if($pra == 1 && $pra["Owner"] != $_SESSION["username"])
{
?><div class="pra"><font color="#4CC417"><b>You have:</b><br></font><img src="ic/state1.png"><br>
People who has:<br>
<?php
printWhoHasPra($id);
?>
</div>
<?php
}
if($pra["Owner"] == $_SESSION["username"])
{
?><div class="pra">
Who has:<br>
<?php
printWhoHasPra($id);
?></div><?php
}
?></td></tr><?php
}
?>
</table>
<?php
if(isset($_SESSION["username"]) && isset($_SESSION["password"]))
{
$myid = getUserId($_SESSION["username"]);
if($myid != $user_pra_id && isNotAdminId($user_pra_id))
{
include_once('SECTIONS/reportbutton.php'); // SET THE USER LOGIN AT THE LEFT
}
}
}
else
{
?><div class="warning">Whoops! You must have arrived here by error!<br>.</div>
<meta HTTP-EQUIV="REFRESH" content="0; url=index.php"><?php
}
}
?>