surreal5335
07-26-2011, 09:01 AM
I need to update all the rows in a table.
Currently I am using a foreach to loop through the various input values and update the database in the appropriate places
Here is the code I am using so far:
function update_admin()
{
// create new record
if(isset($_POST['submit']))
{
$Database = new mysqli('localhost', '#####', '#######', '######');
mysqli_report(MYSQLI_REPORT_ERROR);
$ids_array = get_user_ids();
$num_row = get_user_rows();
$x = 1;
while($x < $num_row)
foreach($ids_array as $id)
{
$user_name = htmlentities($_POST['user_'.$id.'_name'], ENT_QUOTES);
$nick_name = htmlentities($_POST['nick_'.$id.'_name'], ENT_QUOTES);
$update_super = $_POST['update_'.$id.'_super'];
$set_super = 0;
if(isset($update_super))
{
$set_super = 1;
}
if ($stmt = $Database->query("UPDATE views SET view_name='".$user_name."', view_pass='".$nick_name."', view_priv='".$update_super."' WHERE view_id='".$id."'" ))
{
$stmt->execute();
}
else
{
echo 'Error: could not prepare SQL statement.<br />';
}
}
$stmt->close();
header("Location: home.php");
}
}// end submit_form()
Right now I am not getting any results from this, site just takes a long time to reload the page.
Side note: $ids_array = get_user_ids(); does work properly, so no worries there.
I appreciate the help
Currently I am using a foreach to loop through the various input values and update the database in the appropriate places
Here is the code I am using so far:
function update_admin()
{
// create new record
if(isset($_POST['submit']))
{
$Database = new mysqli('localhost', '#####', '#######', '######');
mysqli_report(MYSQLI_REPORT_ERROR);
$ids_array = get_user_ids();
$num_row = get_user_rows();
$x = 1;
while($x < $num_row)
foreach($ids_array as $id)
{
$user_name = htmlentities($_POST['user_'.$id.'_name'], ENT_QUOTES);
$nick_name = htmlentities($_POST['nick_'.$id.'_name'], ENT_QUOTES);
$update_super = $_POST['update_'.$id.'_super'];
$set_super = 0;
if(isset($update_super))
{
$set_super = 1;
}
if ($stmt = $Database->query("UPDATE views SET view_name='".$user_name."', view_pass='".$nick_name."', view_priv='".$update_super."' WHERE view_id='".$id."'" ))
{
$stmt->execute();
}
else
{
echo 'Error: could not prepare SQL statement.<br />';
}
}
$stmt->close();
header("Location: home.php");
}
}// end submit_form()
Right now I am not getting any results from this, site just takes a long time to reload the page.
Side note: $ids_array = get_user_ids(); does work properly, so no worries there.
I appreciate the help