Jump to content

Query only returning id's??


benji87

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.