PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
cap2cap10
Forum Contributor
Posts: 158 Joined: Mon Apr 14, 2008 11:06 pm
Post
by cap2cap10 » Wed Feb 10, 2010 1:34 pm
Hello again, php Technorati! Yes, I have another issue that has arisen! I am getting an error for my mysql insert loop.
here is the error:
Parse error: syntax error, unexpected ')'
here is my code:
Code: Select all
if (isset($_POST['uploaded']))
{
$email = $_POST['email'];
foreach($email){
// Connect to server and select databse.
mysql_connect(*******************************) or die(mysql_error());
mysql_select_db(***********) or die(mysql_error());
$insert_email = "INSERT INTO mail_list (email) VALUES ('$email')";
$result = mysql_query($insert_email) or die (mysql_error());
$count1 = '0';
while ($row = mysql_fetch_assoc($result))
{
$count1 ++;
}
}
}
mysql_close();
echo " All ".$count1." Addresses have been uploaded to Database!";
?>
I am trying to insert 30 email addresses into my mail list.
Can someone point me in the right direction?
Thanks in advance
Batoe
Many obstacles are on the path, but so is success! The unknown Optimist
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Wed Feb 10, 2010 2:24 pm
ok change this:
foreach($email)
to this:
foreach($email as $values)
and change all $email occurences with $values
cap2cap10
Forum Contributor
Posts: 158 Joined: Mon Apr 14, 2008 11:06 pm
Post
by cap2cap10 » Wed Feb 10, 2010 2:57 pm
Ok, I am getting another error. Here is the error:
Warning: Invalid argument supplied for foreach()
Here is the code:
Code: Select all
<?php
if (isset($_POST['uploaded']))
{
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
foreach($email as $values){
// Connect to server and select databse.
mysql_connect(**********************************) or die(mysql_error());
mysql_select_db(**************) or die(mysql_error());
$insert_email = "INSERT INTO mail_list (email) VALUES ('$values')";
$result = mysql_query($insert_email) or die (mysql_error());
$count1 = '0';
while ($row = mysql_fetch_assoc($result))
{
$count1 ++;
}
}
echo " The ".$count1." Addresses have been uploaded to Database!";
}
?>
Please enlighten me.
Thanks in advance
Batoe
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Wed Feb 10, 2010 3:10 pm
Paste the html form code
cap2cap10
Forum Contributor
Posts: 158 Joined: Mon Apr 14, 2008 11:06 pm
Post
by cap2cap10 » Wed Feb 10, 2010 3:26 pm
here is the code:
Code: Select all
<tr><form method="POST" action="my_email_contacts.php">
<td>1. <input name="email" type="text" size="35"></td>
<td>2. <input name="email" type="text" size="35"></td>
<td>3. <input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>4. <input name="email" type="text" size="35"></td>
<td>5. <input name="email" type="text" size="35"></td>
<td>6. <input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>7. <input name="email" type="text" size="35"></td>
<td>8. <input name="email" type="text" size="35"></td>
<td>9. <input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>10.<input name="email" type="text" size="35"></td>
<td>11.<input name="email" type="text" size="35"></td>
<td>12.<input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>13.<input name="email" type="text" size="35"></td>
<td>14.<input name="email" type="text" size="35"></td>
<td>15.<input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>16.<input name="email" type="text" size="35"></td>
<td>17.<input name="email" type="text" size="35"></td>
<td>18.<input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>19.<input name="email" type="text" size="35"></td>
<td>20.<input name="email" type="text" size="35"></td>
<td>21.<input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>22.<input name="email" type="text" size="35"></td>
<td>23.<input name="email" type="text" size="35"></td>
<td>24.<input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>25.<input name="email" type="text" size="35"></td>
<td>26.<input name="email" type="text" size="35"></td>
<td>27.<input name="email" type="text" size="35"></td>
</tr>
<tr>
<td>28.<input name="email" type="text" size="35"></td>
<td>29.<input name="email" type="text" size="35"></td>
<td>30.<input name="email" type="text" size="35"></td>
</tr>
<tr><td colspan="3" align="center">
<input type=hidden name=uploaded value=true />
<input type="Submit" value="Submit!" ></form>
</td></tr>
Batoe
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Wed Feb 10, 2010 3:41 pm
try to make the
name="email"
to
name="email[]"
and leave the php code as is
cap2cap10
Forum Contributor
Posts: 158 Joined: Mon Apr 14, 2008 11:06 pm
Post
by cap2cap10 » Wed Feb 10, 2010 3:58 pm
Ok great, but one more error. Data has been added to db but we get this error.
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
Here is php code again:
Code: Select all
<?php
if (isset($_POST['uploaded']))
{
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
$email = $_POST['email'];
foreach($email as $values){
// Connect to server and select databse.
mysql_connect(**************************************) or die(mysql_error());
mysql_select_db(**************) or die(mysql_error());
$insert_email = "INSERT INTO mail_list (email) VALUES ('$values')";
$result = mysql_query($insert_email) or die (mysql_error());
$count1 = '0';
while ($row = mysql_fetch_assoc($result))
{
$count1 ++;
}
}
echo " The ".$count1." Addresses have been uploaded to Database!";
}
?>
Batoe
Eran
DevNet Master
Posts: 3549 Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME
Post
by Eran » Wed Feb 10, 2010 4:07 pm
Why are you assigning $email 20 times... I didn't think such code existed outside of the daily WTF
cap2cap10
Forum Contributor
Posts: 158 Joined: Mon Apr 14, 2008 11:06 pm
Post
by cap2cap10 » Wed Feb 10, 2010 4:20 pm
Gotcha! I thought that since there were 30 input fields that it was necessary. Ok one is enough then?
Sorry, still a novice.
Batoe