Jump to content

Pulling information from database, putting it in email, and then deleting it


Recommended Posts

My brain is a little fried and I'm trying to figure this out. I'm pretty sure it's possible, but I'm not sure about how to delete the information. The database is two columns: id and the info I want to send in the email. I think I can pull up the information like this:

 

mysql_query("SELECT * FROM specific_prompts ORDER BY id LIMIT 0,3") //for someone who needs 3 prompts

 

How would I go about deleting the three rows I just selected?

<?php

$sql=mysql_query("SELECT * FROM specific_prompts ORDER BY id LIMIT 0,3") or die (mysql_error());

while($del=mysql_fetch_assoc($sql)){


// use sessions to do what ever with above select.

$sql2=mysql_query("delete FROM specific_prompts where id='".$del['id']."'");

$res=mysql_query($sql2)or die (mysql_error());

}
?>

Thank you for your response! Any reason why I would get this error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

 

I've tried to troubleshoot but I'm missing something.

You're trying to run the query twice:

$sql2=mysql_query("delete FROM specific_prompts where id='".$del['id']."'");

$res=mysql_query($sql2)or die (mysql_error());

Change it to:

$sql2="DELETE FROM specific_prompts WHERE id='".$del['id']."'";

$res=mysql_query($sql2)or die (mysql_error());

Sorry for making this unsolved again, but I thought it would be better then starting a new thread. I'm having trouble with the mail feature now. I'm sending out three separate emails instead of one email with three results in it. Any thoughts?

 

				$sql=mysql_query("SELECT * FROM random_prompts ORDER BY id LIMIT 0,3") or die (mysql_error());

while($del=mysql_fetch_assoc($sql)){
$id = $del['id'];
$prompt = $del['prompt'];



mail( "address@gmail.com" , "Test", $prompt, "From:address2@gmail.com" );

I think I have to take the mail function out of the loop, and maybe write an array for the rows. I think that will put the information into one email. But I'm not sure how to write that. Can someone help?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.