Jump to content

[SOLVED] Displays but will not populate database?


sandbudd

Recommended Posts

Displays the information from the database.  When update is clicked it does display the correct id but when I make changes it does not update the database?  Please help.

Here is the file that displays the correct info but when click submit it does not update the database.

 

<?php
// Connect database.
$host=""; 
$db_user=""; 
$db_password=""; 
$database=""; 
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);

// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_POST['Submit']){

$id=$_POST['id'];
$name=$_POST['name'];
$email=$_POST['email'];
$bday_month=$_POST['bday_month'];
$bday_day=$_POST['bday_day'];
$ann_month=$_POST['ann_month'];
$ann_day=$_POST['ann_day'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$favorite=$_POST['favorite'];
$lunch=$_POST['lunch'];
$reservations=$_POST['reservations'];
$parties=$_POST['parties'];
$new_menu=$_POST['new_menu'];
$chef_specials=$_POST['chef_specials'];

// Do update statement.
mysql_query("update mastodon set name='$name', email='$email', bday_month='$bday_month', bday_day='$bday_day', ann_month='$ann_month', ann_day='$ann_day', address='$address', city='$city', state='$state', zip='$zip', favorite='$favorite', lunch='$lunch', reservations='$reservations', parties='$parties', new_menu='$new_menu', chef_specials='$chef_specials' where id='$id'");

// Re-direct this page.
header("location:update.php");
exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method)
$id=$_GET['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from mastodon where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

// Close database connection.
mysql_close();
?>

<!-- END OF PHP CODES AND START HTML TAGS -->

<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">

<table width="707" border="1" cellpadding="3" cellspacing="0" class="appfields">
  <tr>
    <td width="42%"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Member </span></td>
    <td width="58%"><input name="name<? echo $row['id']; ?>" type="text" id="name<? echo $row['id']; ?>" value="<? echo $row['name']; ?>" size="50" /></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Email Address<br>
    </span></td>
    <td><input name="email" type="text" id="email" value="<? echo $row['email']; ?>"/></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Birthday<strong><br>
    </strong></span></td>
    <td><strong>
      <input name="bday_month" type="text" id="bday_month" value="<? echo $row['bday_month']; ?>"/>
         
      <input name="bday_day" type="text" id="bday_day" value="<? echo $row['bday_day']; ?>"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Anniversary<strong><br>
    </strong></span></td>
    <td><strong>
      <input name="ann_month" type="text" id="ann_month" value="<? echo $row['ann_month']; ?>"/>
         
      <input name="ann_day" type="text" id="ann_day" value="<? echo $row['ann_day']; ?>"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Address<br>
    </span></td>
    <td><strong>
      <input name="address" type="text" id="address" value="<? echo $row['address']; ?>"/>
         </strong></td>
  </tr>
  <tr>
    <td><br></td>
    <td><strong>
      <input name="city" type="text" id="city" value="<? echo $row['city']; ?>"/>
      , 
      <input name="state" type="text" id="state" value="<? echo $row['state']; ?>" size="4"/>
      <input name="zip" type="text" id="zip" value="<? echo $row['zip']; ?>" size="10"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">
      <label for="favorite">Favorite Menu Items</label>
    </span></td>
    <td><strong>
      <input name="favorite" type="text" id="favorite" value="<? echo $row['favorite']; ?>" size="60"/>
    </strong></td>
  </tr>
  <tr>
    <td colspan="2"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">I am interested in information:</span></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">
      <label for="lunch">Lunch & Dinner Specials</label>
    </span></td>
    <td><strong>
      <input name="lunch" type="text" id="lunch" value="<? echo $row['lunch']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">
      <label for="reservations">Reservations</label>
    </span></td>
    <td><strong>
      <input name="reservations" type="text" id="reservations" value="<? echo $row['reservations']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Large Parties or Groups</span></td>
    <td><strong>
      <input name="parties" type="text" id="parties" value="<? echo $row['parties']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">New Menu Selections</span></td>
    <td><strong>
      <input name="new_menu" type="text" id="new_menu" value="<? echo $row['new_menu']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Our Chef's Specials</span></td>
    <td><strong>
      <input name="chef_specials" type="text" id="chef_specials" value="<? echo $row['chef_specials']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td colspan="2"> </td>
  </tr>
</table>
<p> </p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>

Link to comment
Share on other sites

Try:

 

mysql_query('update mastodon set name="' . $name . '", email="' . $email . '", bday_month="' . $bday_month . '", bday_day="' . $bday_day . '", ann_month="' . $ann_month . '", ann_day="' . $ann_day . '", address="' . $address . '", city="' . $city . '", state="' . $state . '", zip="' . $zip . '", favorite="' . $favorite . '", lunch="' . $lunch . '", reservations="' . $reservations . '", parties="' . $parties . '", new_menu="' . $new_menu . '", chef_specials="' . $chef_specials . '" where id="' . $id . '"');

 

Link to comment
Share on other sites

changed to this it is displays but still does not update database?

 

<?php
mysql_query('update mastodon set name="' . $name . '", email="' . $email . '", bday_month="' . $bday_month . '", bday_day="' . $bday_day . '", ann_month="' . $ann_month . '", ann_day="' . $ann_day . '", address="' . $address . '", city="' . $city . '", state="' . $state . '", zip="' . $zip . '", favorite="' . $favorite . '", lunch="' . $lunch . '", reservations="' . $reservations . '", parties="' . $parties . '", new_menu="' . $new_menu .'", chef_specials="' . $chef_specials . '" where id="' . $id . '"');
?>

Link to comment
Share on other sites

The query looks fine to me. Try this to debug it:

 

mysql_query('update mastodon set name="' . $name . '", email="' . $email . '", bday_month="' . $bday_month . '", bday_day="' . $bday_day . '", ann_month="' . $ann_month . '", ann_day="' . $ann_day . '", address="' . $address . '", city="' . $city . '", state="' . $state . '", zip="' . $zip . '", favorite="' . $favorite . '", lunch="' . $lunch . '", reservations="' . $reservations . '", parties="' . $parties . '", new_menu="' . $new_menu .'", chef_specials="' . $chef_specials . '" where id="' . $id . '"') or die(mysql_error());

Link to comment
Share on other sites

offtopic(sorry):

I dont get why every one uses all that dot stuff in the querys

doesnt:

mysql_query("update mastodon set name='$name' ") or die(mysql_error());

 

work the same as:

mysql_query('update mastodon set name="' . $name . '" ') or die(mysql_error());

 

except the way you do it is longer and gets me confused, (unless its some sort of security issue?)

 

Any way

 

your query looks correct to me but ill look further in to it may just be a small error

Link to comment
Share on other sites

changed and it still did not update the db and threw no errors

 

whats a link to your site?

 

also

 

<input name="name<? echo $row['id']; ?>" type="text" id="name<? echo $row['id']; ?>" value="<? echo $row['name']; ?>

 

 

Whats that all about?  that wont work as above you have $name as just $_POST['name']; and not name<idhere>

 

as you can see it works on my server , did a lil adapting but yer:

 

http://biz-e-allotments.com/pleasedowork.php?id=3

 

<?php
// Connect database.
$host="localhost"; 
$db_user=""; 
$db_password=""; 
$database=""; 
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);

// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_GET['page'] == "update")
{

$id=$_GET['id'];
$name=$_POST['name'];
$email=$_POST['email'];
$bday_month=$_POST['bday_month'];
$bday_day=$_POST['bday_day'];
$ann_month=$_POST['ann_month'];
$ann_day=$_POST['ann_day'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$favorite=$_POST['favorite'];
$lunch=$_POST['lunch'];
$reservations=$_POST['reservations'];
$parties=$_POST['parties'];
$new_menu=$_POST['new_menu'];
$chef_specials=$_POST['chef_specials'];

// Do update statement.
mysql_query("update help set name='$name', email='$email', bday_month='$bday_month', bday_day='$bday_day', ann_month='$ann_month', ann_day='$ann_day', address='$address', city='$city', state='$state', zip='$zip', favorite='$favorite', lunch='$lunch', reservations='$reservations', parties='$parties', new_menu='$new_menu', chef_specials='$chef_specials' where id='$id'") or die(mysql_error());


}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method)
$id=$_GET['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from help where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

// Close database connection.
mysql_close();
?>

<!-- END OF PHP CODES AND START HTML TAGS -->

<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="?id=3&page=update">

<table width="707" border="1" cellpadding="3" cellspacing="0" class="appfields">
  <tr>
    <td width="42%"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Member </span></td>
    <td width="58%"><input name="name" type="text" id="name" value="<? echo $row['name']; ?>" size="50" /></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Email Address<br>
    </span></td>
    <td><input name="email" type="text" id="email" value="<? echo $row['email']; ?>"/></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Birthday<strong><br>
    </strong></span></td>
    <td><strong>
      <input name="bday_month" type="text" id="bday_month" value="<? echo $row['bday_month']; ?>"/>
         
      <input name="bday_day" type="text" id="bday_day" value="<? echo $row['bday_day']; ?>"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Anniversary<strong><br>
    </strong></span></td>
    <td><strong>
      <input name="ann_month" type="text" id="ann_month" value="<? echo $row['ann_month']; ?>"/>
         
      <input name="ann_day" type="text" id="ann_day" value="<? echo $row['ann_day']; ?>"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Address<br>
    </span></td>
    <td><strong>
      <input name="address" type="text" id="address" value="<? echo $row['address']; ?>"/>
         </strong></td>
  </tr>
  <tr>
    <td><br></td>
    <td><strong>
      <input name="city" type="text" id="city" value="<? echo $row['city']; ?>"/>
      , 
      <input name="state" type="text" id="state" value="<? echo $row['state']; ?>" size="4"/>
      <input name="zip" type="text" id="zip" value="<? echo $row['zip']; ?>" size="10"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">
      <label for="favorite">Favorite Menu Items</label>
    </span></td>
    <td><strong>
      <input name="favorite" type="text" id="favorite" value="<? echo $row['favorite']; ?>" size="60"/>
    </strong></td>
  </tr>
  <tr>
    <td colspan="2"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">I am interested in information:</span></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">
      <label for="lunch">Lunch & Dinner Specials</label>
    </span></td>
    <td><strong>
      <input name="lunch" type="text" id="lunch" value="<? echo $row['lunch']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">
      <label for="reservations">Reservations</label>
    </span></td>
    <td><strong>
      <input name="reservations" type="text" id="reservations" value="<? echo $row['reservations']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Large Parties or Groups</span></td>
    <td><strong>
      <input name="parties" type="text" id="parties" value="<? echo $row['parties']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">New Menu Selections</span></td>
    <td><strong>
      <input name="new_menu" type="text" id="new_menu" value="<? echo $row['new_menu']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Our Chef's Specials</span></td>
    <td><strong>
      <input name="chef_specials" type="text" id="chef_specials" value="<? echo $row['chef_specials']; ?>" size="4"/>
    </strong></td>
  </tr>
  <tr>
    <td colspan="2"> </td>
  </tr>
</table>
<p> </p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>

 

Link to comment
Share on other sites

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.