You are viewing our Forum Archives. To view or take place in current topics click here.
PHP Help - When user click generate, the text is removed.
Posted:
PHP Help - When user click generate, the text is removed.Posted:
Status: Offline
Joined: Aug 04, 201212Year Member
Posts: 89
Reputation Power: 3
Status: Offline
Joined: Aug 04, 201212Year Member
Posts: 89
Reputation Power: 3
Hello guys, I'm working on my website and Im having trouble on this one part. I want it so When a user clicks on the generate button the Account/Text that is generated is removed from the database. Thanks and all help is much appreciated
<?php
$pos = strpos($_SERVER['HTTP_REFERER'],getenv('HTTP_HOST'));
if($pos===false){
die('No Access');
}
include 'inc/database.php';
$date = date("Y-m-d");
$account = strip_tags($_GET['account']);
$username = strip_tags($_GET['username']);
$result = mysqli_query($con, "SELECT * FROM `subscriptions` WHERE `username` = '$username' AND `active` = '1' AND `expires` >= '$date'") or die(mysqli_error($con));
while($row = mysqli_fetch_array($result)){
$package = $row['package'];
}
$result = mysqli_query($con, "SELECT * FROM `packages` WHERE `id` = '$package'") or die(mysqli_error($con));
while($row = mysqli_fetch_array($result)){
$accounts = $row['accounts'];
}
if($accounts != "0" && $accounts != ""){
$result = mysqli_query($con, "SELECT * FROM `statistics` WHERE `username` = '$username' AND `date` = '$date'") or die(mysqli_error($con));
while($row = mysqli_fetch_assoc($result)){
if($row['generated'] >= $accounts){
exit("Generated max per day");
}
}
}
$result = mysqli_query($con, "SELECT * FROM `$account` ORDER BY RAND() LIMIT 1") or die(mysqli_error($con));
while($row = mysqli_fetch_array($result)){ //This block generates a random account from the DB
echo $row['alt'];
}
$result = mysqli_query($con, "SELECT * FROM `settings`") or die(mysqli_error($con));
while($row = mysqli_fetch_array($result)){
$generated = $row['generated'] + "1";
mysqli_query($con, "UPDATE `settings` SET `generated` = '$generated'") or die(mysqli_error($con));
}
if (isset($_GET['generated'])){
if ($_GET['generated']){
$id = strip_tags($_GET['generated']);
mysqli_query($con, "DELETE FROM `$account` WHERE `id`='$id'") or die(mysqli_error($con)); //This whole block is what I have to delete the account thats generated but it doesnt work
}
}
$date = date("Y-m-d");
$result = mysqli_query($con, "SELECT * FROM `statistics` WHERE `username` = '$username' AND `date` = '$date'") or die(mysqli_error($con));
if(mysqli_num_rows($result) == "0"){
mysqli_query($con, "INSERT INTO `statistics` (`username`, `generated`, `date`) VALUES ('$username', '1', DATE('$date'))") or die(mysqli_error($con));
}else{
while($row = mysqli_fetch_array($result)){
$generated = $row['generated'] + "1";
mysqli_query($con, "UPDATE `statistics` SET `generated` = '$generated' WHERE `username` = '$username' AND `date` = '$date'") or die(mysqli_error($con));
}
}
?>
#2. Posted:
Status: Offline
Joined: Sep 21, 201410Year Member
Posts: 1,181
Reputation Power: 480
I believe it should be like this.
<div id="pick_style">
<?php for ($i = 1; $i < 5; $i++) { ?>
<?php $key = 'pick_up_location_' + $i; ?>
<?php if (isset($_POST[$key])) { ?>
<label for="pick_up_location">Pick Up Location(s)</label>
<input type="text" name="<?php echo $key; ?>"
value="<?php if (isset($_POST[$key])) { echo $_POST[$key]; } ?>" list="<?php echo $key; ?>" />
<datalist name="<?php echo $key; ?>" id="<?php echo $key; ?>">
<?php while ($row = mysqli_fetch_array($pickup_location_initial)) { ?>
<option value="<?php echo $row['store_city'] . ',' . ' ' . $row['store_state'] . ' ' . $row['store_num']; ?>">
<?php } ?>
</datalist>
<input type="button" onClick="removePick(this)" value="-" />
<?php } /* if */ ?>
<?php } /* for */ ?>
<input type="button" id="add_pickup()" onClick="add_pickup()" value="+" />
</div>
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: May 02, 201212Year Member
Posts: 1,129
Reputation Power: 34
Status: Offline
Joined: May 02, 201212Year Member
Posts: 1,129
Reputation Power: 34
So based on your code, you want to delete an account that you randomly generated. However, you are never storing that random generated account. This block:
should actually be:
Now this is the part that I am confused about. What is $_GET['generated']? Is this suppose to be that account id that you want to delete or is this suppose to be the random account id? You have zero comments and $row['alt'] doesn't tell me anything.
If it's suppose to be the random account id then the correct query should be:
This will delete the random account you generated. Currently, you are generating a random account, not storing it then deleting an account on the $_GET['generated'] variable.
I may be confused idk.
$result = mysqli_query($con, "SELECT * FROM `$account` ORDER BY RAND() LIMIT 1") or die(mysqli_error($con));
while($row = mysqli_fetch_array($result)){ //This block generates a random account from the DB
echo $row['alt'];
}
should actually be:
$result = mysqli_query($con, "SELECT * FROM `$account` ORDER BY RAND() LIMIT 1") or die(mysqli_error($con));
while($row = mysqli_fetch_array($result)){ //This block generates a random account from the DB
$randomAccount = $row['alt'];
}
Now this is the part that I am confused about. What is $_GET['generated']? Is this suppose to be that account id that you want to delete or is this suppose to be the random account id? You have zero comments and $row['alt'] doesn't tell me anything.
If it's suppose to be the random account id then the correct query should be:
mysqli_query($con, "DELETE FROM `$account` WHERE `id`='$randomAccount'") or die(mysqli_error($con));
This will delete the random account you generated. Currently, you are generating a random account, not storing it then deleting an account on the $_GET['generated'] variable.
I may be confused idk.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.