PHP MYSQL HELP

Status
Not open for further replies.

Zoot

New Member
Dec 23, 2012
18
2
Basicly here my code
Code:
<?php
if ($_GET['get'] == "upload")
{
$id = mt_rand(0,961680);
 
    $query = "SELECT * FROM catalogue_items";
 
    $result = mysql_query($query) or die(mysql_error());
 
    while($account = mysql_fetch_array($result)){
 
        if ($id == $account['tid']){
 
    $id = mt_rand(0,961680);
 
    } else {
$sql="INSERT INTO catalogue_items (tid, catalogue_name, typeid, name_cct) VALUES ('$id', '$_POST[catalogue_name]','$_POST[typeid]','$_POST[name_cct]')"; 
 
 
    sql1="INSERT INTO furniture (tid, ownerid) VALUES ('$id', ".$user->user("id").")"; 
mysql_query("$sql"); 
mysql_query("$sql1");
        }
}


i know it messy but im not a every good php coder

basicly what the code does it makes a random number and checks it with catalogue_items "tid" and then that number with the other uploading data is uploaded and it only upload once this all works correct when it comes to inserting it in to the furniture it upload it multiple times like 4000+ times does anyone one now why?
 

Zoot

New Member
Dec 23, 2012
18
2
You are defining the $id variables 2 times, the second time it gives it another ID.
i have to define it twice so when it check the database for that number and finds that number i need it to repeat again untill it finds another number thats not in the database.
A guess, you're not directing it anywhere after the code executes, so it just repeats itself.
anyidea how to fix?
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
i have to define it twice so when it check the database for that number and finds that number i need it to repeat again untill it finds another number thats not in the database.


You know that everytime a function calls the mt_rand(0,961680); function it gives it another number? For example:
PHP:
<?php
$id = mt_rand(0,961680);
 
echo "<pre>";
echo "$id <br />";
echo "$id <br />";
echo "$id <br />";
echo "</pre>";
?>

You will see all three $id's will have different numbers.
 

Zoot

New Member
Dec 23, 2012
18
2
You must be registered for see images attach

As you can see here it uploaded the same number that it is calling for it just uploading in to the catalogue once and in to the furni 4000+ with the right number
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
PHP:
<?php
if ($_GET['get'] == "upload")
{
$id = mt_rand(0,961680);
 
    $query = "SELECT * FROM catalogue_items";
 
    $result = mysql_query($query) or die(mysql_error());
 
    while($account = mysql_fetch_array($result)){
 
        if ($id != $account['tid']){
 
    header("Location: 0; #");
 
    } else {
$sql="INSERT INTO catalogue_items (tid, catalogue_name, typeid, name_cct) VALUES ('$id', '$_POST[catalogue_name]','$_POST[typeid]','$_POST[name_cct]')";
$sql1="INSERT INTO furniture (tid, ownerid) VALUES ('$id', ".$user->user("id").")";
 
mysql_query("$sql");
mysql_query("$sql1");
        }
}
?>
 

Zoot

New Member
Dec 23, 2012
18
2
PHP:
<?php
if ($_GET['get'] == "upload")
{
$id = mt_rand(0,961680);
 
    $query = "SELECT * FROM catalogue_items";
 
    $result = mysql_query($query) or die(mysql_error());
 
    while($account = mysql_fetch_array($result)){
 
        if ($id != $account['tid']){
 
    header("Location: 0; #");
 
    } else {
$sql="INSERT INTO catalogue_items (tid, catalogue_name, typeid, name_cct) VALUES ('$id', '$_POST[catalogue_name]','$_POST[typeid]','$_POST[name_cct]')";
$sql1="INSERT INTO furniture (tid, ownerid) VALUES ('$id', ".$user->user("id").")";
 
mysql_query("$sql");
mysql_query("$sql1");
        }
}
?>
Warning: Cannot modify header information - headers already sent by (output started at /home/zoothote/public_html/habblet/minimail_loadMessages.php:161) in /home/zoothote/public_html/me.php on line 738
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
/home/zoothote/public_html/me.php on line 738


Check line 738 in the file me.php
What? No, that isn't it.

Warning: Cannot modify header information - headers already sent by (output started at /home/zoothote/public_html/habblet/minimail_loadMessages.php:161) in /home/zoothote/public_html/me.php on line 738
Change
PHP:
header("Location: 0; #");
to
PHP:
echo "<META HTTP-EQUIV=/"refresh/" CONTENT=/"1/">";
 

Zoot

New Member
Dec 23, 2012
18
2
What? No, that isn't it.


Change
PHP:
header("Location: 0; #");
to
PHP:
echo "<META HTTP-EQUIV=/"refresh/" CONTENT=/"1/">";
Thanks for the help but i Tried and it uploaded multiple times ive coded it so it pick the random number then is posted in the form (that way it the number is in a variable and wont change) thanks for the help anyway
 
Status
Not open for further replies.

Users who are viewing this thread

Top