-
any ideas?
hey
im working on a download thingy for my site, and people can submit downloads, and mirrors for that download
this is the code for the submit download, i have 2 tables, i "downloads" which stores the main download stuff, then "mirrors" where the urls are stored. in mirrors theres a column called "did", which holds the download id from "downloads", which that number is autoincrement.
im trying to get that number after i insert it into the DB, and it isn't working..any ideas?
thanks :)
PHP Code:
$db = mysql_connect("localhost", "fragblast", "");
mysql_select_db("fragblast",$db);
$review=str_replace("\n","<br>",$describ);
$sql = "INSERT INTO download (title, auth_id, auth_name, describ, size, cat) VALUES ('$title', '$userid', '$username', '$describ', '$size', '$cat')";
$result = mysql_query($sql);
$sql="SELECT * FROM download WHERE title='$title' AND auth_id='$userid' AND auth_name='$username' AND describ='$describ' AND size='$size' AND cat='$cat')";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result)) { //LINE 49
echo $row['id']; //debug
$id=$row['id'];
$sql = "INSERT INTO mirrors (did,site,name) VALUES ('$id', '$mirrorname', '$url')";
$result = mysql_query($sql);
$sql = "UPDATE stats SET count = count + 1 WHERE name='$cat'";
$result= mysql_query($sql);
}
the error is:
Warning: Supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\downloads\add.php on line 49
-
for one, what is line 49, and 2 you can't str_replace for those. you have to use ereg_replace
-
line 49 is
while ($row = mysql_fetch_array($result)) { //LINE 49
and str_replace works, ive used it before. i can take that line out anyway
-
$sql="SELECT * FROM download WHERE title='$title' AND auth_id='$userid' AND auth_name='$username' AND describ='$describ' AND size='$size' AND cat='$cat')";
Take out that )
-
Try this:
PHP Code:
$db = mysql_connect("localhost", "fragblast", "");
mysql_select_db("fragblast",$db);
$review=str_replace("\n","<br>",$describ);
$sql = "INSERT INTO download (title, auth_id, auth_name, describ, size, cat) VALUES ('$title', '$userid', '$username', '$describ', '$size', '$cat')";
$result = mysql_query($sql);
$selectId = mysql_insert_id($result);
$sql="SELECT * FROM download WHERE id='$selectId')";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result)) { //LINE 49
echo $row['id']; //debug
$id=$row['id'];
$sql = "INSERT INTO mirrors (did,site,name) VALUES ('$id', '$mirrorname', '$url')";
$result = mysql_query($sql);
$sql = "UPDATE stats SET count = count + 1 WHERE name='$cat'";
$result= mysql_query($sql);
}
-
wouldn't it be better to double check your queries:
PHP Code:
$db = mysql_connect("localhost", "fragblast", "");
mysql_select_db("fragblast",$db);
$review=str_replace("\n","<br>",$describ);
$sql = "INSERT INTO download (title, auth_id, auth_name, describ, size, cat) VALUES ('$title', '$userid', '$username', '$describ', '$size', '$cat')";
if(mysql_query($sql))
{
$selectId = mysql_insert_id($result);
$sql="SELECT * FROM download WHERE id='$selectId')";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result)) { //LINE 49
echo $row['id']; //debug
$id=$row['id'];
$sql = "INSERT INTO mirrors (did,site,name) VALUES ('$id', '$mirrorname', '$url')";
$result = mysql_query($sql);
$sql = "UPDATE stats SET count = count + 1 WHERE name='$cat'";
$result= mysql_query($sql);
}
}
-
i had stuff in there for debugging purposes, but i took them out since it works now
cpradio: your idea didn't work, but i got mine working. thanks tho :)