Mr Chris Posted May 8, 2006 Share Posted May 8, 2006 Hi Guys,On my form I created I can call a record OUT and display it on the page, but cant UPDATE the page?Can anyone please advise?Thanks[code]<?php // Set the variables for access; include("*************");// Update Query if(!isset($_GET['story_id'])) { $result = mysql_query("Update cms_stories set section='$section', added_by='$added_by', headline='$headline', byline_name='$byline_name', appeared='$appeared', opening='$opening', body_text='$body_text', picture='$picture', pic_caption='$pic_caption', pic_ref='$pic_ref', notes='$notes' where story_id=".$_GET['story_id']); $msg = "The Story record has been updated in the database - Please Click <a href=\"menu.php\">Here</a> to return to the main menu"; } // Get Story ID From Database if(isset($_GET['story_id'])) { $result = mysql_query("Select * From cms_stories where story_id=".$_GET['story_id'],$link); $row = mysql_fetch_array($result); $section = $row['section']; $added_by = $row['added_by']; $headline = $row['headline']; $byline_name = $row['byline_name']; $appeared = $row['appeared']; $opening = $row['opening']; $body_text = $row['body_text']; $picture = $row['picture']; $pic_caption = $row['pic_caption']; $pic_ref = $row['pic_ref']; $notes = $row['notes']; } else{// Run Query $link = mysql_connect; mysql_select_db($db); $result = mysql_query($query) or die('Query failed: ' . mysql_error()); mysql_close(); } ?> <html> <head> <title>Website Admin</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> BODY,H1,H2,H3,H4,H5,UL,LI,INPUT,A,B,TEXTAREA { font-family: Geneva, Helvetica, Arial, sans-serif } P { font-family: Geneva, Helvetica, Arial, sans-serif; } A { color: #1c1c1c } A:visited { color: #1c1c1c } A:hover { text-decoration: none; color: #ffffff; background-color: #3333cc } </style> </head> <body bgcolor="#CCCCCC"> <table width="95%" border="0" align="center" bgcolor="#FFFFFF"> <tr> <td> </td> </tr> <tr bgcolor="#CC0000"> <td height="24"> <div align="center"><b><font color="#FFFFFF">ADD A STORY</font></b></div> </td> </tr> <tr> <td> <table width="70%" border="0" align="center"> <tr> <td><?php echo $msg?></td> </tr> </table> <br> <form action="" method="post" enctype="multipart/form-data" name="uploadform"> <table width="70%" border="0" align="center" bgcolor="#000000"> <tr> <td height="442"> <table width="100%" border="0" bgcolor="#FFFFFF" cellpadding="3" cellspacing="1"> <tr> <td width="26%" bgcolor="#CCCCCC" height="24"><b>Edition:</b></td> <td width="74%" height="24"><b><font color="#CC0000">Website.</font></b></td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC"><b>Section:</b></td> <td width="74%"> <select name="section"> <option><?php echo $section?></option> <option value="news">News</option> <option value="sport">Sport</option> <option value="business">Business</option> <option value="viator">Viator</option> </select> </td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC"><b>Added by:</b></td> <td width="74%"> <input name="added_by" type="text" id="added_by" value="<?php echo $added_by?>" size="50"> </td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC"><b>Headline:</b></td> <td width="74%"> <input name="headline" type="text" id="headline" value="<?php echo $headline?>" size="50"> </td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC"><b>Byline Name:</b></td> <td width="74%"> <input name="byline_name" type="text" id="byline_name" value="<?php echo $byline_name?>" size="35" maxlength="128"> </td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC"> <p><b>Appeared in G Telegraph:</b></p> </td> <td width="74%"> <input name="appeared" type="text" id="appeared" value="<?php echo $appeared?>" size="30"> </td> </tr> <tr bgcolor="#CC0000"> <td colspan="2"> <div align="center"><b><font color="#FFFFFF">OPENING PARAGRAPH</font></b></div> </td> </tr> <tr> <td colspan="2"> <div align="center"> <textarea name="opening" id="opening" cols="80" rows="7"><?php echo $opening?></textarea> </div> </td> </tr> <tr bgcolor="#CC0000"> <td colspan="2"> <div align="center"><b><font color="#FFFFFF">BODY TEXT</font></b></div> </td> </tr> <tr> <td colspan="2"> <div align="center"> <textarea name="body_text" id="body_text" cols="80" rows="25"><?php echo $body_text?></textarea> </div> </td> </tr> <tr bgcolor="#CC0000"> <td colspan="2"> <div align="center"><b><font color="#FFFFFF">PICTURE (IF REQUIRED)</font></b></div> </td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC"><b>Pic to Upload:</b></td> <td width="74%"> </td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC" valign="top"><b>Caption:</b></td> <td width="74%"> <textarea name="pic_caption" id="pic_caption" cols="40"><?php echo $pic_caption?></textarea> </td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC"><b>Pic Ref No:</b></td> <td width="74%"> <input name="pic_ref" type="text" id="pic_ref" value="<?php echo $pic_ref?>" size="30"> <br> </td> </tr> <tr bgcolor="#CC0000"> <td colspan="2"> <div align="center"><b><font color="#FFFFFF">ADDITIONAL NOTES (NOT PUBLISHED)</font></b></div> </td> </tr> <tr> <td width="26%" bgcolor="#CCCCCC" valign="top"><b>Notes:</b></td> <td width="74%"> <textarea name="notes" id="notes" rows="4" cols="65"><?php echo $notes?></textarea> </td> </tr> <tr> <td width="26%"> </td> <td width="74%"> <input name="upload" type="submit" class="box" id="upload" value=" Upload "> <input type="reset" name="Reset" value="Clear Story"> </td> </tr> </table> </td> </tr> </table> </form> </td> </tr> </table> </body> </html> [/code] Link to comment https://forums.phpfreaks.com/topic/9302-update-not-working/ Share on other sites More sharing options...
ober Posted May 8, 2006 Share Posted May 8, 2006 1) Are you getting any errors?2) Is $_GET['story_id'] a string or an integer?3) You're not verifying the UPDATE. You display a success message no matter what happens.[code]$result = mysql_query("UPDATE tablex SET .... ")if($result) echo "success message";else echo "error message";[/code] Link to comment https://forums.phpfreaks.com/topic/9302-update-not-working/#findComment-34283 Share on other sites More sharing options...
alpine Posted May 8, 2006 Share Posted May 8, 2006 you are trying to use $_GET['story_id'] inside an if condition only to run when there is no $_GET['story_id'] setif([!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]![!--colorc--][/span][!--/colorc--]isset($_GET['story_id'])){ $result = mysql_query("Update cms_stories set section='$section', added_by='$added_by', headline='$headline', byline_name='$byline_name', appeared='$appeared', opening='$opening', body_text='$body_text', picture='$picture', pic_caption='$pic_caption', pic_ref='$pic_ref', notes='$notes' where story_id=".[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$_GET['story_id'][!--colorc--][/span][!--/colorc--]); $msg = "The Story record has been updated in the database - Please Click <a href=\"menu.php\">Here</a> to return to the main menu";}so that wont work Link to comment https://forums.phpfreaks.com/topic/9302-update-not-working/#findComment-34319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.