Jump to content

Archived

This topic is now archived and is closed to further replies.

spoot

Trying to add email field to db, getting php error

Recommended Posts

Hi -

 

I'm getting the (remarkably common, I've found) error:

 

Warning: reset(): Passed variable is not an array or object in /home/pearlsea/public_html/test343/includes/functions/database.php on line 55

 

I've found lots of information in these forums about this error, but none of them seem to address the way I've run across it.

 

I've added a new table to the database, called email_list. I'm adding a single field to my site's footer that says "subscribe to our mailing list." A customer puts in their email address & clicks "go," and I want to add their email address to the email_list table.

 

After their address is added to the list, a new page (email_list.php) is displayed, saying "thanks for subscribing" or whatever. If the email address is invalid, it says "that was not an email address."

 

I'm using tep_validate_email to validate the email address, tep_mail to send the user a "you have subscribed..." email, and I'm trying to use tep_db_perform to add the email address to the database. The tiny bit of code I'm using for these last two is:

 

// send them a note...
tep_mail('',$email_address, MAILTO_SUBJECT, MAILTO_TEXT, TITLE, STORE_OWNER_EMAIL_ADDRESS);
  	 
// ...add their email address to the database...	
tep_db_perform('email_list', $email_address);

 

The mail function works fine. The db_perform function, though, gives me a long list of Passed variable is not an array or object in /home/pearlsea/public_html/test343/includes/functions/database.php errors... well, here they are:

 

Warning: reset(): Passed variable is not an array or object in /home/pearlsea/public_html/test343/includes/functions/database.php on line 55

Warning: Variable passed to each() is not an array or object in /home/pearlsea/public_html/test343/includes/functions/database.php on line 59

Warning: reset(): Passed variable is not an array or object in /home/pearlsea/public_html/test343/includes/functions/database.php on line 63

Warning: Variable passed to each() is not an array or object in /home/pearlsea/public_html/test343/includes/functions/database.php on line 64
1064 - 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 ') values)' at line 1

insert into email_list) values)

 

If I add echo $data; to the db_perform function, it shows me a valid email address.

 

Anyone know what I'm doing wrong?

 

Thanks for any assistance -

 

Michael

Share this post


Link to post
Share on other sites

Ah, beautiful! You're absolutely right, just make it an array. Thank you. Here's the fix:

 

// ...add their email address to an array, then to the database...	
$email_address = array('email' => $email_address);
 
tep_db_perform('email_list', $email_address);

 

Here, email_list is the name of the table, email is the name of the row that holds the address.

 

Thank you vasttech -

 

Michael

Share this post


Link to post
Share on other sites

×