Jump to content

Show insert data in database on my website?


eduard

Recommended Posts

ok, well let's look at the line and the error.
while($row = mysql_fetch_array($result))

in other words, if we look at just the function call

mysql_fetch_array($result)

and isolate paramter 1 (parameters are those things in between the ()/parenthesis of functions/methods)

$result

we can look at the rest of the message.http://php.net/manual/en/function.mysql-fetch-array.phpso you have given it a boolean, which are values of either true or false (this is where you need to learn your basic data types). So since we know that you have the a boolean value, we know that you must have been given false as a return value from mysql_query (or else it would have returned a result set).http://php.net/manual/en/function.mysql-query.phpSo it looks like the query failed. Simple.So in conclusion, not that hard of a problem to solve if you take a little bit of your own time to take some initiative to do some basic investigating. You should really start getting into the habit of trying this process first before you post your every issue/problem/question. Being a professional developer requires resourcefulness and self-motivation.edit: updated part about mysql_query return value.

This is exactly what I mean: for you it´s SIMPLE (´a piece of cake´)! For me it is NOT!
Link to comment
Share on other sites

  • Replies 190
  • Created
  • Last Reply

There's not one person here who started out knowing everything. Everyone had to start with nothing and learn it, everyone started on the same level and everyone thought it was hard. How we proceed from that point is what makes us different. Some people take the initiative to do their own research and try and find their own answers and resources, and some people don't. This is why I've suggested the books to you, when I wanted to learn PHP I used my little college student money to buy Rasmus Lerdorf's book and read it. I guess that had a pretty good impact, because now I know PHP. You're trying to use only online tutorials and ask people questions, and I don't think it's working for you. I bet you haven't even read through the PHP manual yet.

Link to comment
Share on other sites

There's not one person here who started out knowing everything. Everyone had to start with nothing and learn it, everyone started on the same level and everyone thought it was hard. How we proceed from that point is what makes us different. Some people take the initiative to do their own research and try and find their own answers and resources, and some people don't. This is why I've suggested the books to you, when I wanted to learn PHP I used my little college student money to buy Rasmus Lerdorf's book and read it. I guess that had a pretty good impact, because now I know PHP. You're trying to use only online tutorials and ask people questions, and I don't think it's working for you. I bet you haven't even read through the PHP manual yet.
Wrong, you lost the bet! But the manual is like your posts: the mayority of it is ábacadabra´ to me! Of course, there´s ´boolean´, ´parameter´ in it! But can I do with it, if I don´t understand the expanations?P. s. I think I´m going to write a book called: php for dummies!
Link to comment
Share on other sites

http://www.dummies.com/store/product/PHP-a...0470527587.html
But can I do with it, if I don´t understand the expanations?
What exactly don't you understand about this page:http://www.php.net/manual/en/language.types.boolean.php
Wrong, you lost the bet!
I don't think so. Reading a couple pages, getting frustrated, and giving up doesn't qualify as "reading the manual". Reading the manual means you finished it.
Link to comment
Share on other sites

http://www.dummies.com/store/product/PHP-a...0470527587.htmlWhat exactly don't you understand about this page:http://www.php.net/manual/en/language.types.boolean.phpI don't think so. Reading a couple pages, getting frustrated, and giving up doesn't qualify as "reading the manual". Reading the manual means you finished it.
The manual:Why don´t they just write ´boolean= ...¨ No, another link (I´m very tired of links!). About the bet, you are right!
Link to comment
Share on other sites

You're "tired of links", but you don't want to get a book. How exactly do you plan to learn what you're trying to learn? If you insist on learning everything online, I would think you would be used to links by now. If you don't want to click any other links, there's a zip file on this page that contains the entire manual on a single 43MB HTML page:http://www.php.net/download-docs.php

Link to comment
Share on other sites

The manual:Why don´t they just write ´boolean= ...¨ No, another link
They do explicitly state what a boolean is:
A boolean expresses a truth value. It can be either TRUE or FALSE.
It doesn't get any simpler than that.Any other links on that page are FYI only. Anything necessary to understand what a boolean is and how it works is on that page. Same for any other manual page.
Link to comment
Share on other sites

You're "tired of links", but you don't want to get a book. How exactly do you plan to learn what you're trying to learn? If you insist on learning everything online, I would think you would be used to links by now. If you don't want to click any other links, there's a zip file on this page that contains the entire manual on a single 43MB HTML page:http://www.php.net/download-docs.php
No, if I have money I am going to buy a book! (paper is much more ´quiet´ as a montor!P. s. you lost the bet as you wrote: reading THROUGH! That´s what I did! So, 5 belgian beer please?
Link to comment
Share on other sites

If you make it through the entire Language Reference, I'll ship you some Hoegaarden.
With lemon please?
Link to comment
Share on other sites

I know since this morning that the query is FALSE, but I still don´t know where to read to find the solution!

Link to comment
Share on other sites

This is exactly what I want:<?php$con = mysql_connect("localhost","peter","abc123");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con);$result = mysql_query("SELECT * FROM Persons");echo "<table border='1'><tr><th>Firstname</th><th>Lastname</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);?>But I still don´t know what I must change in my select script?

Link to comment
Share on other sites

The SELECT clause will select one or more columns from the table you specify in the FROM clause.

SELECT columns FROM table

If you want more than one column then use commas to separate the column name.

SELECT column1,column2 FROM table

The name of the columns and table depend on what you have in your database.After fetching an array from the MySQL resource you can access each field of each row by putting the field name as the key of the array:

echo "<td>" . $row['column1'] . "</td>";

It's all explained properly here: http://w3schools.com/php/php_mysql_select.asp

Link to comment
Share on other sites

If mysql_query returns false, you can use mysql_error to print the error message from MySQL. In fact, every time you use mysql_query you should follow it with mysql_error:$result = mysql_query("your query here") or exit(mysql_error());

With lemon please?
Don't push it...
Link to comment
Share on other sites

They do explicitly state what a boolean is:It doesn't get any simpler than that.Any other links on that page are FYI only. Anything necessary to understand what a boolean is and how it works is on that page. Same for any other manual page.
But can you imagine that: I focused on the word ´boolean´?
Link to comment
Share on other sites

This sentence I don´t understand:Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/eduardli/ parameter 1?resource?

Link to comment
Share on other sites

That's the same error we've been explaining to you for the past several posts. It means the query failed. Parameter 1 is the first parameter you send to mysql_fetch_assoc:while($row = mysql_fetch_assoc($result))A resource is what mysql_query returns when the query does not fail.

Link to comment
Share on other sites

I finally got what I want: Description, price, quantity!However, I get now an input which isn´t mine!Description Price Quantity mutt200 5I want to show the very latest input e. g. if a visitor inputs data now, I also want to show the output now!<html><body><?php$con = mysql_connect("localhost","eduardli_user","-z.x,c");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("eduardli_company", $con);$result = mysql_query ("SELECT Description, Price, QuantityFROM ProductsORDER BY Price DESCLIMIT 1");if (!$result) {echo mysql_error();} echo "<table border='1'><tr><th>Description</th><th>Price</th><th>Quantity<th></tr>";while($row = mysql_fetch_assoc($result)){echo "<td>" . $row['Description'] . "</br>";echo "<td>" . $row['Price'] . "</td>";echo "<td>" . $row['Quantity'] . "</td>";echo "</tr>";}echo "</table>";mysql_close($con);?></body></html>Do I have to use mysql update?

Link to comment
Share on other sites

No, the easy way is just insert an extra int field (usually 'ID') that uses auto increment, so every time a new record is submitted, this field increases by one, for that specific record. You don't have to include this in the insert form, just in the select page using$result = mysql_query ("SELECT ID, Description, Price, QuantityFROM ProductsORDER BY ID, Price DESCLIMIT 1");to sort by the highest ID value (the latest record), then by Price.

Link to comment
Share on other sites

No, the easy way is just insert an extra int field (usually 'ID') that uses auto increment, so every time a new record is submitted, this field increases by one, for that specific record. You don't have to include this in the insert form, just in the select page using$result = mysql_query ("SELECT ID, Description, Price, QuantityFROM ProductsORDER BY ID, Price DESCLIMIT 1");to sort by the highest ID value (the latest record), then by Price.
Ok, thanks!
Link to comment
Share on other sites

(I´m getting very tired of this file!)What´s now wrong with it:Parse error: syntax error, unexpected T_IF in /home/eduardli/public_html/web_designer/insert.php on line 19 1 <html> 2 <body> 3 4 <?php 5 $con = mysql_connect("localhost","eduardli_user","-z.x,c"); 6 if (!$con) 7 { 8 die('Could not connect: ' . mysql_error()); 9 }10 11 mysql_select_db("eduardli_company", $con);12 13 14 $result = mysql_query ("SELECT ID, Description, Price, Quantity15 FROM Products16 ORDER BY ID, Price DESC17 LIMIT 1") or exit(mysql_error()18 19 if (!$result) {20 echo mysql_error();21 } 22 23 echo "<table border='1'>24 <tr>25 <th>Description</th>26 <th>Price</th>27 <th>Quantity<th>28 </tr>";29 30 while($row = mysql_fetch_assoc($result))31 {32 echo "<td>" . $row['Description'] . "</br>";33 echo "<td>" . $row['Price'] . "</td>";34 echo "<td>" . $row['Quantity'] . "</td>";35 echo "</tr>";36 }37 echo "</table>";38 39 mysql_close($con);40 ?>41 42 </body>43 </html>

Link to comment
Share on other sites

well, errors usually occur on the line before the actual line given in the error message. the last line before line 19 is

LIMIT 1") or exit(mysql_error()

looks like you forgot a closing paren --> )

Link to comment
Share on other sites

The problem is always the same!Person 1 says aPerson 2 says bPerson 3 says cetc.Spelling checker 1 says zSpelling checker 2 says yThe result by a lot of trying-without a solution I get very frustrated:<html><body><?php$con = mysql_connect("localhost","eduardli_user","-z.x,c");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("eduardli_company", $con);$result = mysql_query ("SELECT ID, Description, Price, QuantityFROM ProductsORDER BY ID, Price DESCLIMIT 1") echo"<table border='1'><tr><th>Description</th><th>Price</th><th>Quantity<th></tr>";while($row = mysql_fetch_assoc($result)){echo "<td>" . $row['Description'] . "</br>";echo "<td>" . $row['Price'] . "</td>";echo "<td>" . $row['Quantity'] . "</td>";echo "</tr>";}echo "</table>";mysql_close($con);?></body></html>

Link to comment
Share on other sites

I don't know why you are using a spellchecker, but...if you bothered to pay attention to your syntax, you would be able to solve these problems for yourself. the basics you keep forgetting are all lines need to end with a semicolon, and your quotes, parens, and curly braces need to match. (one closing one for each opening one). that's just syntax. the rules are the same no matter who gives you advice. You could just learn it, and then you could solve most of your own questions.... Also, typically, instead of taking the advice, you just change your code (removing a good thing, the error checking) and present it with another syntax error. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...