Jump to content

news management


alen

Recommended Posts

Bottom line on the "Warning: mysql_fetch_array()..." is that your query ("SELECT * FROM news WHERE id='$id'") returned nothing.  Therefore, a call to grab the data from the query, like what you are doing with mysql_fetch_array() is invalid.

Maybe try re-formatting your query like this:
[code]$query = mysql_query("SELECT * FROM news WHERE id=$id");[/code]
I removed the single quotes (') from around the variable $id. 

Have you used something like phpMyAdmin to run the query to make sure that with a valid $id you get something?
Look for yourself:

[code]<?php
error_reporting(E_ALL ^ E_NOTICE);
include('config.php');
$db=mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");
if(isset($_GET['id'])) {
$id = $_GET['id'];
echo "<!-- Your query was selected with a get method -->";
$query = mysql_query("SELECT * FROM news WHERE id=$id") or die(mysql_error());
}
if(isset($_POST['id'])){
$id = $_POST['id'];
echo "<!-- Your query was selected with a post method -->";
$query = mysql_query("SELECT * FROM news WHERE id=$id"); or die(mysql_error());
}

while($r=mysql_fetch_array($query)) {
$nid = $r['id'];
$title = $r['title'];
$news = $r['news'];
echo "<form name='edit_process.php' method='post' action='edit_save.php?id=".$nid."'>
  <p>Title :
    <input type='text' name='title' value='".$title."' />
  </p>
  <p>News :</p>
  <p>
    <textarea name='news' cols='40' rows='6'>".$news."</textarea>
  </p>
  <p>
    <input type='submit' name='Submit' value='Save' />
  </p>
</form>";
}
?>[/code}[/code]
I'm back again.. I added a mysql_error to find out what the problem was.

So this is what it returned,

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.

I didn't actually get that, but could someone translate?

Here's my code, http://anigma.sitees.com/rediger.txt and http://anigma.sitees.com/lagre.txt

It consist's of two parts, firstly I have to extract the news from my database, and secondly I have to display this data.

I have chosen to display the latest 10 newest posts.

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.