Jump to content

Recommended Posts

hey guys here is just a piece of the code because I think this is where the problem is... The database displays fine but when I click to update it does not update the database?

 


<?php
// Check if button name "Submit" is active, do this 
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET company='$company[$i]', address='$address[$i]', city='$city[$i]', state='$state[$i]', phone='$phone[$i]', asian='$asian[$i]', american='$american[$i]', coffee='$coffee[$i]', fun='$fun[$i]', italian='$italian[$i]', mexican='$mexican[$i]', seafood='$seafood[$i]', upscale='$upscale[$i]', recommend='$recommend[$i]', email='$email[$i]', website='$website[$i]', photo='$photo[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

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

Link to comment
https://forums.phpfreaks.com/topic/153015-php-update-to-database/
Share on other sites

here is the complete file..its long thats why I didnt send it all first...

 


<?php 
require_once('settings.php');
checkLogin('1 2');

?>

<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
color: #0000FF;
}
-->
</style>
<br /><br />

<link href="css/styles.css" rel="stylesheet" type="text/css" />
<div id="container" style="text-align:center;width:230px;">

<?php
echo 'Hello <em><b><u>' . get_username ( $_SESSION['user_id'] ) . '</u></b></em>!<br />You are now logged in.<br /><br /><a href="update_profile.php" title="update your profile">Click here</a> to update your profile.';

/* we show the manage users link only if the logged in member has admin rights */
if ( isadmin ( $_SESSION['user_id'] ) ):
?>
<br /><br />
It seems that you're an admin. You may <a href="manage_users.php" title="manage users">manage users</a> or <a href="admin_settings.php" title="edit site settings">edit site settings</a>.
<?php
endif;
?>
<br /><br />

<a href="logout.php">logout</a>

</div><br /><br />
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="50%" align="center" valign="top"><a href="insert.php">Insert Customer</a></td>
    <td width="50%" align="center" valign="top"><a href="update.php">Update/Edit Customer</a></td>
  </tr>
</table>


    <hr />

  
  <?php
$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // 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 company ASC";
$result=mysql_query($sql);

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


<tr>
<td colspan="5" align="left" valign="top"><img src="../images/smalllogo.png" width="500" height="79" /><br />
  <br /></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
  <td width="25%" align="left" valign="top">Company</td>
  <td width="34%" align="left" valign="top"><input name="company[]" type="text" id="company" value="<? echo $rows['company']; ?>"></td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td align="left" valign="top">Address</td>
  <td align="left" valign="top"><input name="address[]" type="text" id="address" value="<? echo $rows['address']; ?>"></td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td align="left" valign="top">City</td>
  <td align="left" valign="top"><input name="city[]" type="text" id="city" value="<? echo $rows['city']; ?>"></td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td align="left" valign="top">State</td>
  <td align="left" valign="top"><input name="state[]" type="text" id="state2" value="<? echo $rows['state']; ?>"></td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td align="left" valign="top">Phone</td>
  <td align="left" valign="top"><input name="phone[]" type="text" id="state" value="<? echo $rows['phone']; ?>"></td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td align="left" valign="top">Asian</td>
  <td align="left" valign="top"><input name="asian" type="text" id="asian" value="<? echo $rows['asian']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td>American:</td>
  <td align="left" valign="top"><input name="american" type="text" id="american" value="<? echo $rows['american']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td>Coffee:</td>
  <td align="left" valign="top"><input name="coffee" type="text" id="coffee" value="<? echo $rows['coffee']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td>Fun Food:</td>
  <td align="left" valign="top"><input name="fun" type="text" id="fun" value="<? echo $rows['fun']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td>Italian:</td>
  <td align="left" valign="top"><input name="italian" type="text" id="italian" value="<? echo $rows['italian']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td>Mexican:</td>
  <td align="left" valign="top"><input name="mexican" type="text" id="mexican" value="<? echo $rows['mexican']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td>Seafood</td>
  <td align="left" valign="top"><input name="seafood" type="text" id="seafood" value="<? echo $rows['seafood']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td>Upscale</td>
  <td align="left" valign="top"><input name="upscale" type="text" id="upscale" value="<? echo $rows['upscale']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td> </td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
</tr>
<tr>
  <td>Recommend</td>
  <td align="left" valign="top"><input name="recommend" type="text" id="recommend" value="<? echo $rows['recommend']; ?>" /></td>
  <td colspan="3" align="left" valign="top">1 = true leave blank if false</td>
  </tr>
<tr>
  <td>Email:</td>
  <td align="left" valign="top"><input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" /></td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
</tr>
<tr>
  <td>Website</td>
  <td align="left" valign="top"><input name="website" type="text" id="website" value="<? echo $rows['website']; ?>" /></td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
</tr>
<tr>
  <td align="left" valign="top">Image</td>
  <td align="left" valign="top"><input name="photo" type="text" id="photo" value="<? echo $rows['photo']; ?>" /></td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
  <td align="left" valign="top"> </td>
</tr>
<tr>
  <td colspan="5" align="left" valign="top"><hr /></td>
  </tr>
<?php
}
?>
<tr align="left" valign="top">
<td colspan="3"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<div align="center">
  <?php
// Check if button name "Submit" is active, do this 
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET company='$company[$i]', address='$address[$i]', city='$city[$i]', state='$state[$i]', phone='$phone[$i]', asian='$asian[$i]', american='$american[$i]', coffee='$coffee[$i]', fun='$fun[$i]', italian='$italian[$i]', mexican='$mexican[$i]', seafood='$seafood[$i]', upscale='$upscale[$i]', recommend='$recommend[$i]', email='$email[$i]', website='$website[$i]', photo='$photo[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if($result1){
header("location:update.php");
}
mysql_close();
?>
  
  
</div>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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