0

i have a problem in sharing a file to other user

here is my code i get lag when i press the share submit button.

share.php

<form action="sharefile.php" method="post">
        
        <p><strong>Enter Jum/Email ID:</strong></p>
        <textarea name="share" style="width: 400px; height: 60px;"></textarea>
        <p>(Jum ID or Primary Email separated by comma)</p>
        <input type="submit" name="submit" value="Share" />
        <input type="hidden" name="fileid" value"<?php echo $id; ?>"  />
        </form>

sharefile.php

<?php
session_start();
include ('dbconnect.php');

$userid = $_SESSION['id'];
$id = $_POST['fileid'];
$getfile = mysql_query("Select * from try where id ='$id'");
$row = mysql_fetch_array($getfile);
$name = $row['name'];
$mime = $row['mime'];
$size = $row['size'];
$data = $row['data'];
$date = $today = date("F j, Y");
$send = $_POST['share'];
$sendmany = explode(',', $send);

for ($counter=0; $counter<$sendmany; $counter++)
	{
		$sendmany[$counter] = trim($sendmany[$counter]);
		$sql = mysql_query("Select * from user where email='$sendmany' or username='$sendmany'");
		if (mysql_num_rows($sql) > 0)
		{
		$send = mysql_query("Insert into try (name, mime, size, data, userid, date) Values ('$name', '$mime', '$size', '$data', '$userid', '$date'");	
		}
	}
	if ($send)
	{
	echo 'wow';	
	}
?>
2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by diafol
0

i already change my code into this

<?php
session_start();
include ('dbconnect.php');
 
$userid = $_SESSION['id'];
$id = $_POST['fileid'];
$getfile = mysql_query("Select * from try where id ='$id'");
$row = mysql_fetch_array($getfile);
$name = $row['name'];
$mime = $row['mime'];
$size = $row['size'];
$data = $row['data'];
$date = $today = date("F j, Y");
$send = $_POST['share'];
$sendmany = explode(',', $send);
 
for ($counter=0; $counter<count($sendmany); $counter++)
	{
		$sendmany[$counter] = trim($sendmany[$counter]);
		$sql = mysql_query("Select * from user where email='$sendmany' or username='$sendmany'");
		if (mysql_num_rows($sql) > 0)
		{
		$send = mysql_query("Insert into try (name, mime, size, data, userid, date) Values ('$name', '$mime', '$size', '$data', '$userid', '$date'");	
		}
	}
	if ($send)
	{
	echo 'wow';	
	}
?>

but still i can't save the data in my database.

0

Are you getting an error? Try echoing out your SQL to the screen - copy it and paste it into the SQL window of phpmyadmin. You may get some joy.

0

i don't get any error, my problem is i can't see anything to my fileshare table the my query doesn't work

here is my code

<form action="sharefile.php" method="post">
        
        <p><strong>Enter Jum/Email ID:</strong></p>
        <textarea name="share" id="share" style="width: 400px; height: 60px;"></textarea>
        <p>(Jum ID or Primary Email separated by comma)</p>
        <input type="submit" name="submit" value="Share" />
        <input type="hidden" name="fileid" value"<?php echo $id; ?>"  />
        </form>

sharefile.php

<?php
session_start();
include ('dbconnect.php');

$ownid = $_SESSION['id'];
$id = $_POST['fileid'];
$getfile = mysql_query("Select * from try where id ='$id'");
$row = mysql_fetch_array($getfile);
$userid = $row['userid'];
$send = $_POST['share'];
$sendmany = explode(',', $send);

for ($counter=0; $counter<count($sendmany); $counter++)
	{
		$sendmany[$counter] = trim($sendmany[$counter]);
	}
	$sql = mysql_query("Select * from user where email='$sendmany'");
	$row1 = mysql_fetch_array($sql);
	$owners = $row1['id'];
			if (mysql_num_rows($sql) > 0)
		{
		$sending = mysql_query("Insert into fileshare (fileid, userid, shareid) VALUES ('$id', '$userid', '$owners')");	
		if ($sending)
		{
		echo 'mm';	
		}
		}
	
	
?>

Edited by ryan311: n/a

0
$row1 = mysql_fetch_array($sql);
	$owners = $row1['id'];
			if (mysql_num_rows($sql) > 0)

Personally I'd use the num_rows before the fetch_array. How can you give $owners if there are no rows? However, I doubt if that's your problem.

This is how I'd do it (well, a quick think):

session_start();
include ('dbconnect.php');
 
$ownid = $_SESSION['id'];
$id = mysql_real_escape_string($_POST['fileid']);
$r1 = mysql_query("SELECT * FROM try WHERE id ='$id'");
$d1 = mysql_fetch_array($r1);


$userid = $d1['userid'];
$send = mysql_real_escape_string($_POST['share']);
$sendmany = explode(',', $send);
 
foreach($sendmany as $person){
    $person = trim($person);
    $r2 = mysql_query("SELECT * FROM user WHERE email='$person'");
    if(mysql_num_rows($r2) > 0){
	$d2 = mysql_fetch_array($r2);
        $owners = $d2['id'];
	$r3 = mysql_query("INSERT INTO fileshare (fileid, userid, shareid) VALUES ('$id', '$userid', '$owners')");
	if(mysql_affected_rows() == 1){
		echo $owners . "<br/>";
	}
    } 
}

Now I must admit, I think you could get away with making a JOIN clause to combine two SQL calls into one - it depends on your table/data structure. If this doesn't work, how about checking your fieldnames and tablenames against your code. Again, echo out the SQL to see what's actually being passed to the mysql server.

e.g.

echo "INSERT INTO fileshare (fileid, userid, shareid) VALUES ('$id', '$userid', '$owners')";

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.