Jump to content

[SOLVED] Displays but will not populate database?


sandbudd

Recommended Posts

display page



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


$result=mysql_query("select * from mastodon order by id asc");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../includes/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="620" border="0" cellpadding="5" cellspacing="0">

<?
// Fetch record rows in $result by while loop and put them into $row.
while($row=mysql_fetch_assoc($result)){
?>

<tr>
  <td><table width="100%" border="1" cellpadding="3" cellspacing="0" class="appfields">
    <tr>
      <td width="45%"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Member </span></td>
      <td width="55%"><strong><? echo $row['name']; ?></strong></td>
      </tr>
    <tr>
      <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Email Address<br>
      </span></td>
      <td><strong><? echo $row['email']; ?></strong></td>
      </tr>
    <tr>
      <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Birthday<strong><br>
      </strong></span></td>
      <td><strong><? echo $row['bday_month']; ?>   <? 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><? echo $row['ann_month']; ?>   <? 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><? echo $row['address']; ?>   </strong></td>
      </tr>
    <tr>
      <td><br></td>
      <td><strong><? echo $row['city']; ?>, <? echo $row['state']; ?> <? echo $row['zip']; ?></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><? echo $row['favorite']; ?></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><? echo $row['lunch']; ?></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><? echo $row['reservations']; ?></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><? echo $row['parties']; ?></strong></td>
    </tr>
    <tr>
      <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">New Menu Selections</span></td>
      <td><strong><? echo $row['new_menu']; ?></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><? echo $row['chef_specials']; ?></strong></td>
    </tr>
    <tr>
      <td colspan="2"><? echo '<a href="update_mastodon.php?id='.$row['id'].'">Update</a>'; ?></td>
      </tr>
  </table></td>
  </tr>
<tr>
  <td> </td>
</tr>
<tr>
  <td> </td>
</tr>
  


<? } // End while loop. ?>
</table>

</body>
</html>

 

edit page not populating

 

<?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($_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 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());


}
// ************* 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="?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>

Found the error:

 

<?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($_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 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());


}
// ************* 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="?id=<? echo $id; ?>&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>

that worked what was the error?

 

i acidently left in

 

?id=3&page=update in the action of the form instead of making it update auto

 

two lines:

 

<form id="form1" name="form1" method="post" action="?id=<? echo $id; ?>&page=update">

 

and (old)

 

<form id="form1" name="form1" method="post" action="?id=3&page=update">

 

i aint very good at explaining things

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.