benji87 Posted October 2, 2007 Share Posted October 2, 2007 Hi all im curently working on a script for editing records in a database. Trouble is when i call fields from my database it seems to only select the id and fill that id into text fields where other data should be appearing. I cant understand how or why its doing it. It seems that the query is writing the id of the entry to both my title and text fields which shouldnt be happening i want the title and text data obviously! Could someone take a look and tell me where im going wrong as i designed this script for a previous project and it worked fine, ive only made a few minor changes to this one: <? session_start(); include "db.php"; if (isset($_GET['action'])) { switch ($_GET['action']) { case 'delete': $query=("DELETE FROM profile_blog WHERE id = '{$_GET['id']}'"); $result=mysql_query($query); mysql_query("UPDATE staff_profile SET last_login=now() WHERE username='$username'"); header("Location: editblog.php"); break; case 'edit': $query1=("SELECT * FROM profile_blog WHERE id = '{$_GET['id']}'"); $result=mysql_query($query1); $title_fld=mysql_result($result,"title"); $text_fld=mysql_result($result,"text"); }; }; ?> <link href="../../../css/default.css" rel="stylesheet" type="text/css"> <body> <table width="250" border="0" cellspacing="6" bgcolor="efefef" class="bodytext"> <tr> <td height="149"> <table width="300" border="0" cellpadding="0" class="bodytext"> <tr> <td width="234">Links:</td> <td width="60"><div align="center">Action:</div></td> </tr> </table> <? $username = $_SESSION['username']; $query=("SELECT * FROM profile_blog WHERE username = '$username' ORDER BY title ASC"); $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $title=mysql_result($result,$i,"title"); $date=mysql_result($result,$i,"date"); $id=mysql_result($result,$i,"id"); ?> <table width="100%" border="0" cellpadding="0" bordercolor="cdcdcd" class="bodytext" style="border-bottom:dotted; border-bottom-color:cdcdcd; border-bottom-width:1px;"> <tr> <td width="6%" bgcolor="#EFEFEF"><? echo "$date" ?></td> <td width="73%" bgcolor="#EFEFEF"><? echo "$title" ?></td> <td width="10%" bgcolor="#EFEFEF"><div align="center"><? echo "<a href='blogactions.php?id=$id&action=edit'>E</a>" ?></div></td> <td width="11%" bgcolor="#EFEFEF"><div align="center"><? echo "<a href='blogactions.php?id=$id&action=delete'>D</a>" ?></div></td> <? $i++; } ?> </tr> </table> <form name="form1" method="post" action="editlinks_frm.php"> <table width="300" border="0" cellpadding="0" cellspacing="2" class="bodytext"> <tr> <td width="234">Title:</td> <td width="60"><input name="title" type="text" class="bodytext" id="title" style="background-color:efefef; border: none; color: 009900; border: solid; border-width: 1px; border-color: cdcdcd;" value="<? echo ("$title_fld") ?>" size="40"></td> </tr> <tr> <td>URL:</td> <td><textarea name="text" cols="70" rows="10" class="bodytext" id="text" style="background-color:efefef; border: none; color: 009900; border: solid; border-width: 1px; border-color: cdcdcd;"><? echo ("$text_fld") ?></textarea></td> </tr> <tr> <td> </td> <td><input name="Submit" type="submit" class="bodytext" value="Update"> </td> </tr> </table> </form></td> </tr> </table> </body> </html> Cheers Link to comment https://forums.phpfreaks.com/topic/71504-query-only-returning-ids/ Share on other sites More sharing options...
jaymc Posted October 2, 2007 Share Posted October 2, 2007 Try this approach $query1="SELECT * FROM profile_blog WHERE id = '$_GET[id]'"; $result=mysql_query($query1); $data=mysql_fetch_array($result); echo $data[fieldnamehere]; Link to comment https://forums.phpfreaks.com/topic/71504-query-only-returning-ids/#findComment-359963 Share on other sites More sharing options...
benji87 Posted October 2, 2007 Author Share Posted October 2, 2007 Nope not luck, says the fetch_array is not a valid argument ( Link to comment https://forums.phpfreaks.com/topic/71504-query-only-returning-ids/#findComment-359966 Share on other sites More sharing options...
jaymc Posted October 2, 2007 Share Posted October 2, 2007 Then this is wrong $query1="SELECT * FROM profile_blog WHERE id = '$_GET[id]'"; AKA, your query Pay attention to the way you are using this '$_GET[id]' in your queries I noticed you had apostrophies within apostrophies That will balls it up '$_GET['id']' = no '$_GET[id]' = yes Try sort them out, its probably the current issue Link to comment https://forums.phpfreaks.com/topic/71504-query-only-returning-ids/#findComment-359969 Share on other sites More sharing options...
benji87 Posted October 2, 2007 Author Share Posted October 2, 2007 Ive changed that but ive always done apostrophes like that before and never had problems with it. Although i will change that in future scripts so cheers for that. I have changed them for this script but im still getting the same error says its not a valid result resource Link to comment https://forums.phpfreaks.com/topic/71504-query-only-returning-ids/#findComment-359973 Share on other sites More sharing options...
hemlata Posted October 2, 2007 Share Posted October 2, 2007 Hello, Modify your script with the following code block, may be either you get your problem solved or the result will return the error for the query.. $query1="SELECT * FROM `profile_blog` WHERE `id` = '" . $_GET['id'] . "'"; $result=mysql_query($query1) or die(mysql_error()); $data=mysql_fetch_array($result); Regards, Link to comment https://forums.phpfreaks.com/topic/71504-query-only-returning-ids/#findComment-359990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.