•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 361,916 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,528 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4660 | Replies: 66
![]() |
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
[quote=nav33n;542446]What error exactly ?
here are the errors,
Warning: Invalid argument supplied for foreach() in C:\wamp\www\dynamic\edit.php on line 16
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\dynamic\edit.php on line 25
here are the errors,
Warning: Invalid argument supplied for foreach() in C:\wamp\www\dynamic\edit.php on line 16
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\dynamic\edit.php on line 25
<form id="form1" name="form1" method="post" action="edit.php">
team: <input type="text" name="team" /><br />
<br>
<?php
$sql = 'SELECT * From team';
$con = mysql_connect("localhost","root","talk21") or die;
$result = mysql_db_query(lastr, $sql);
while ($rec = mysql_fetch_array($result))
{
print "\n<input type='checkbox' name=team[]' value='".$rec['id']."'checked> ".$rec['team']." </input>";
}
if(isset($_POST['submit'])){
$q="delete from team"; //delete all the teams
mysql_query($q);
foreach($_POST['team'] as $value){
$q="insert into team (team) values ('$value')";
mysql_query($q); //so by the end, the table will have records which were checked and all the records which were unchecked will be removed.
}
}
//I list these teams in my form.
$q="select id,team from table";
$res=mysql_query($q);
echo "<form method='post' action='check.php'>";
while($row=mysql_fetch_array($res)){
echo "<input type='checkbox' name='team[]' value='$id' checked>".$team."<br />"; //this will list all the teams in the database
}
echo "<input type='submit' name='submit' value='submit'>";
echo "</form>";
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,866
Reputation:
Rep Power: 7
Solved Threads: 206
1st error means, the value passed to foreach is not an array. Check if you are passing array to foreach loop.
2nd error means, the query is returning empty result.
2nd error means, the query is returning empty result.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,866
Reputation:
Rep Power: 7
Solved Threads: 206
As I said, foreach will give this error if you aren't giving an array as input. And there are so many queries. Check out what's on line 25. That query isn't working.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
As I said, foreach will give this error if you aren't giving an array as input. And there are so many queries. Check out what's on line 25. That query isn't working.
I dnt understand team[] is an array on line 11,
foreach($_POST['team'] as $value){ // this is an aray .
Also line 25 i dnt understand there is no syntax error and the table has records.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,866
Reputation:
Rep Power: 7
Solved Threads: 206
print the values of team before foreach.
print_r($_POST['team']); If its an array, it ll print the whole array. else it ll print only 1 value.
print_r($_POST['team']); If its an array, it ll print the whole array. else it ll print only 1 value.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
print the values of team before foreach.
print_r($_POST['team']); If its an array, it ll print the whole array. else it ll print only 1 value.
I have simplified the coding to just delete the selected checkbox.
the flow is to check if checkbox is checked and Delete when submit button is click.
1. if(!isset($_POST['team'])){ // see if checkbox is checked
2. foreach($_POST['team'] as $value){ // loop trough the checkboxes
3. $sql = "DELETE FROM team WHERE id={$_POST['team']}"; //delete selected teams
<form id="form1" name="form1" method="post" action="edit.php">
<?php
$sql = 'SELECT * From team';
$con = mysql_connect("localhost","root","talk21") or die;
$result = mysql_db_query(lastr, $sql);
while ($rec = mysql_fetch_array($result))
{
print "\n<input type='checkbox' name=team[]' value='".$rec['id']."' > ".$rec['team']." </input>";
}
if(!isset($_POST['team'])){
}
foreach($_POST['team'] as $value){
}
if(isset($_POST['submit'])){
}
$sql = "DELETE FROM team WHERE id={$_POST['team']}"; //delete selected teams
mysql_query($q);
echo "<input type='submit' name='submit' value='submit'>";
?>There are no errors in the code above, however it doesn’t do anything.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- Variable passed to each() is not an array (PHP)
- How to delete using checkboxes (PHP)
- Storing dynamic form values in Arrays for display & insert (PHP)
Other Threads in the PHP Forum
- Previous Thread: problem in deleting
- Next Thread: Cookies problem - not working



Linear Mode