SkyRanger Posted April 24, 2008 Share Posted April 24, 2008 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 More sharing options...
SkyRanger Posted April 24, 2008 Author Share Posted April 24, 2008 bump Link to comment https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526392 Share on other sites More sharing options...
Zhadus Posted April 24, 2008 Share Posted April 24, 2008 Instead of if ($Submit) try if isset($Submit) And double check that you are assigning $Submit properly, I don't see it in the code you posted. Make sure you have: if isset($_GET['Submit']) $Submit = $_GET['Submit']; At the top. Link to comment https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526400 Share on other sites More sharing options...
SkyRanger Posted April 24, 2008 Author Share Posted April 24, 2008 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 More sharing options...
Zhadus Posted April 24, 2008 Share Posted April 24, 2008 Sorry: if (isset($_GET['Submit'])) $Submit = $_GET['Submit']); Link to comment https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526417 Share on other sites More sharing options...
SkyRanger Posted April 24, 2008 Author Share Posted April 24, 2008 Not working, I am getting the same error on line 56: if isset($Submit){ When I put in if (isset($Submit)){ The page shows with no error but It still will not update. Link to comment https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526569 Share on other sites More sharing options...
SkyRanger Posted April 25, 2008 Author Share Posted April 25, 2008 Does anybody know where to find a good tutorial for this so I can look it over? I am still fighting with this code, not sure what the problem is. Link to comment https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526715 Share on other sites More sharing options...
allistera Posted April 25, 2008 Share Posted April 25, 2008 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 More sharing options...
SkyRanger Posted April 25, 2008 Author Share Posted April 25, 2008 No that never worked, I lost everything this time. Link to comment https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526736 Share on other sites More sharing options...
SkyRanger Posted April 25, 2008 Author Share Posted April 25, 2008 Figured it out. Link to comment https://forums.phpfreaks.com/topic/102646-solved-multi-update/#findComment-526763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.