Database Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesDatabase Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 13th, 2010, 06:06 AM
Cowprint Cowprint is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2010
Posts: 2 Cowprint User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 4 m 47 sec
Reputation Power: 0
Editing stored information

Hi all!

I'm new here, and new to PHP and mysql.

Currently i'm building a basic online address book. Just stores information and displays it to the user really. I have made a form that allows users to add new details to the database.

I'm trying to add a button to allow users to edit the current details held for a particular entry in the database.

The code for my main page is:
Code:
<?php
$username="xxxx";
$password="xxxx";
$database="xxxx";

mysql_connect(localhost,xxxx,xxxx);
@mysql_select_db(xxxx or die( "Unable to select database");
$query="SELECT * FROM magazines ORDER BY `NAME` ASC";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
  <table border="0" cellspacing="20" cellpadding="1">
  <tr>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">ID</font></th>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">PUBLICATION</font></th>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">COUNTRY</font></th>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">EDITOR</font></th>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">DESK</font></th>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">PHONE</font></th>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">EMAIL</font></th>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">ADDITIONAL INFO</font></th>
  <th><font face="Verdana, Geneva, sans-serif" size="2" color="#254176">OPTIONS</font></th>
  </tr>
    
  <?php
$i=0;
while ($i < $num) {

$ID=mysql_result($result,$i,"ID");
$NAME=mysql_result($result,$i,"NAME");
$COUNTRY=mysql_result($result,$i,"COUNTRY");
$CONTACT=mysql_result($result,$i,"CONTACT");
$DESK=mysql_result($result,$i,"DESK");
$PHONE=mysql_result($result,$i,"PHONE");
$EMAIL=mysql_result($result,$i,"EMAIL");
$COMMENTS=mysql_result($result,$i,"COMMENTS");
?>
    
  <tr>
  <td><font face="Arial, Helvetica, sans-serif"><?php echo $ID; ?></font></td>
  <td><font face="Arial, Helvetica, sans-serif"><?php echo $NAME; ?></font></td>
  <td><font face="Arial, Helvetica, sans-serif"><?php echo $COUNTRY; ?></font></td>
  <td><font face="Arial, Helvetica, sans-serif"><?php echo $CONTACT; ?></font></td>
  <td><font face="Arial, Helvetica, sans-serif"><?php echo $DESK; ?></font></td>
  <td><font face="Arial, Helvetica, sans-serif"><?php echo $PHONE; ?></font></td>
  <td><font face="Arial, Helvetica, sans-serif"><?php echo $EMAIL; ?></font></td>
  <td><font face="Arial, Helvetica, sans-serif"><?php echo $COMMENTS; ?></font></td>
  <td><font face="Arial, Helvetica, sans-serif"><a href="contacts_magazines_editdetails.php?id<? echo $ID['ID']; ?>"><img src="images/edit_details_button.gif" width="102" height="16" border="0" /></a></font></td>
  </tr>
    
  <?php
$i++;
}
?>


The Edit Details button then goes to:

Code:
<?php
$host="localhost"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="xxxx"; // Database name
$tbl_name="magazines"; // Table name

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

// get value of id that sent from address bar
$id=$_GET['ID'];


// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$ID'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
  <table width="400" border="0" cellspacing="1" cellpadding="0">
  <tr>
  <form name="form1" method="post" action="contacts_magazines_editdetails_submit.php">
  <td>
  <table width="100%" border="0" cellspacing="1" cellpadding="0">
  <tr>
  <td>&nbsp;</td>
  <td colspan="3"><strong>Update data in mysql</strong> </td>
  </tr>
  <tr>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  </tr>
  <tr>
  <td align="center">&nbsp;</td>
  <td align="center"><strong>Name</strong></td>
  <td align="center"><strong>Lastname</strong></td>
  <td align="center"><strong>Email</strong></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td align="center"><input name="NAME" type="text" id="NAME" value="<? echo $NAME['NAME']; ?>"></td>
  <td align="center"><input name="COUNTRY" type="text" id="COUNTRY" value="<? echo $COUNTRY['COUNTRY']; ?>" size="15"></td>
  <td><input name="PHONE" type="text" id="PHONE" value="<? echo $PHONE['PHONE']; ?>" size="15"></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td><input name="ID" type="hidden" id="ID" value="<? echo $ID['ID']; ?>"></td>
  <td align="center"><input type="submit" name="Submit" value="Submit"></td>
  <td>&nbsp;</td>
  </tr>
  </table>
  </td>
  </form>
  </tr>
  </table>
              
  <?

// close connection
mysql_close();

?>


Which then goes to:

Code:
<?php
$host="localhost"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="xxxx"; // Database name
$tbl_name="magazines"; // Table name

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

// update data in mysql database
$sql="UPDATE magazines SET NAME='$NAME', COUNTRY='$COUNTRY', PHONE='$PHONE' WHERE ID='$ID'";
$result=mysql_query($sql);

// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='contacts_magazines.php'>Go back to contact list. </a>";
}

else {
echo "ERROR";
}

?>


When the user goes to edit the details, the current information does not appear in the text fields, and when the user clicks submit it says it sucessfully changed the data, but it's not been changed when you go back to the main page to check,.

Seems to connect to the database fine, it just won't update the data or show the existing data in the fields...

What am I doing wrong?

Thanks!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesDatabase Development > Editing stored information


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap