Jump to content

[SOLVED] Multi Update


SkyRanger

Recommended Posts

Not sure what in the heck the problem is, but it will not update for me.

 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name order by mid ASC";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">


<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>MID</strong></td>
<td align="center"><strong>Title</strong></td>
<td align="center"><strong>URL/IMG</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input size="3" name="mid[]" type="text" id="mid" value="<? echo $rows['mid']; ?>"></td>
<td align="center"><? echo $rows['mtialt']; ?></td>
<td align="center"><? echo $rows['mpgim']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET mid='$mid[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if($result1){
header("location:update_menu.php");
}
mysql_close();

 

Can anybody see the problem I might be having.  I looked at this a dozen times which could also be the problem of me not seeing it.

Link to comment
https://forums.phpfreaks.com/topic/102646-solved-multi-update/
Share on other sites

K, I changed the code but now I am getting an error:

 

if isset($_GET['Submit'])
$Submit = $_GET['Submit'];

$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="database"; // Database name
$tbl_name="menu"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name order by mid ASC";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>MID</strong></td>
<td align="center"><strong>Title</strong></td>
<td align="center"><strong>URL/IMG</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input size="3" name="mid[]" type="text" id="mid" value="<? echo $rows['mid']; ?>"></td>
<td align="center"><? echo $rows['mtialt']; ?></td>
<td align="center"><? echo $rows['mpgim']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php

// Check if button name "Submit" is active, do this
if isset($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET mid='$mid[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if($result1){
header("location:update_menu.php");
}
mysql_close();
?>

 

And the error I am getting is:

 

Parse error: syntax error, unexpected T_ISSET, expecting '(' in /home/psars/public_html/admin/update_menu.php on line 3

Line 3 is : if isset($_GET['Submit'])

 

 

Link to comment
https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526411
Share on other sites

If statement look like this:

 

if (condition) {
    // code 
}

You do not have the "()" around the condition or the open brackets "{"

 

Try this:

<?php
if (isset($_GET['Submit'])) {
$Submit = $_GET['Submit'];

$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="database"; // Database name
$tbl_name="menu"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name order by mid ASC";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>MID</strong></td>
<td align="center"><strong>Title</strong></td>
<td align="center"><strong>URL/IMG</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input size="3" name="mid[]" type="text" id="mid" value="<? echo $rows['mid']; ?>"></td>
<td align="center"><? echo $rows['mtialt']; ?></td>
<td align="center"><? echo $rows['mpgim']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php

// Check if button name "Submit" is active, do this
if (isset($Submit)){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET mid='$mid[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if(isset($result1)){
header("location:update_menu.php");
}
mysql_close();
}
?>

Link to comment
https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526719
Share on other sites

Archived

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

×
×
  • 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.