Fix my code, please! Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\ index.php <?php include 'includes/connection.php'; $query = "SELECT * FROM tuotteet"; $result = mysql_query($query); while($tuote = mysql_fetch_array($result)) { echo "<h3>" . $tuote['Nimi'] . "</h3>"; echo "<p>" . $tuote['Kuvaus'] . "</p>"; echo "<a href=\"modify.php\id=" . $tuote['ID'] . "\">Muokkaa Tuotetta</a>"; echo "<span> </span>"; echo "<a href=\"delete.php?id=" . $tuote['ID'] . "\">Muokkaa Tuotetta</a>"; } ?> <h1>Lisää tuote</h1> <form action="create.php" method="post"> Tuotteen nimi <input type="text" name="inputName" value="" /><br /> Tuotteen kuvaus <input type="text" name="inputDesc" value="" /> <br /> <input name="submit" type="submit" id="submit" /> </form> Code (markup):
I'd guess that your connection hasn't worked and therefore $result is null. This kind of query is deprecated, there are newer, safer ways to do it. Check php.net for options.
thx, probly. Damn, i spended alot of time to doing this! *for *makin XD, now lets makin new version of it
Add a PHP variable which establishes connection with your database. Once done, insert the same variable in the mysql_query() function but before the $query varable. For e.g: $con = mysqli_connect('host', 'username', 'password', 'database'); Code (markup): Now add thw $con variable in the mysql_query() function but before the $query parameter. For e.g: $result = mysql_query($con, $query); Code (markup): Just to make you abreast of the latest developments, the 'mysql' extension has been deprecated and it's now been replaced by 'mysqli'. So make sure you update your code with it.
Just an observation, but why are you still using mysql_ functions like it's a decade ago, ignoring the big red warning boxes that they've had for just about two years now... why are you using multiple echo statements to do the job of one? Why do you have a H1 in your markup AFTER the H3? (can I at least assume there's both a H1 and H2 preceeding that?) Why don't you have a complete form with LABELs and at least one FIELDSET? Why are you using double quotes and string addition? Of course, I probably wouldn't waste time making the extra variable either... and if VALUE is empty you don't need to say VALUE. If I was writing the same thing, it would probably look more like this: <?php include('includes/connection.php'); $result = mysql_query('SELECT * FROM tuotteet'); while ($tuote = mysql_fetch_array($result)) echo ' <h3>', $tuote['Nimi'], '</h3> <p>', $tuote['Kuvaus'], '</p> <a href="modify.php?id=', $tuote['ID'], '">Muokkaa Tuotetta</a> <span> </span><!-- suspect this span is doing padding's job --> <a href="delete.php?id=', $tuote['ID'], '">Muokkaa Tuotetta</a>'; echo ' <form action="create.php" method="post"> <h2>Lisää tuote</h2> <fieldset> <label for="createInputName">Tuotteen nimi</label> <input type="text" name="inputName" id="createInputName"/> <br /> <label for="createInputDesc">Tuotteen kuvaus</label> <input type="text" name="inputDesc" id="createInputDesc" /> <br /> <input name="submit" type="submit" id="submit" /> </fieldset> </form>'; ?> Code (markup): Though I'm guessing on the heading level without seeing the whole page... remember, H1 is the element under which every subsection of the page that FOLLOWS is... well, a subsection, which is why it should be the FIRST numbered heading on a page; and there should only be one of them -- preferably before you have ANY other content. H2's are the start of subsections of the H1, h3's are the start of subsections of the H2 immediately before them, and so forth.
This time i have a stupid job for you, please give me css code to this black box left its just left and it looks like that permament still box on pic XD fast please
I think you've missed the point that this is a discussion forum. You show us how far you have got and we suggest fixes etc You know the old thing about teaching a man to fish...
Thx ---> deathshadow your code works, but i already created new one . Please can someone post that nice box css code please XD
Demanding that people help you is not the way to go about it, go away and come back when you've learnt some manners and maybe people here will be more inclined to help you.