Jump to content

Show insert data in database on my website?


eduard

Recommended Posts

Sadly, there is nobody here that can make you an "expert" overnight. That onus is entirely on you, and you must dedicate yourself to a discipline I you want to be good at it. I'm sorry to hear about your financial situation, but keep in mind there are millions of people in financial distress, however you have to make a decision. If you are looking to "jump into" web development, you will get in line with the other thousands of developers waiting for job offers. Until you can perfect your skills, then you might be forced to work in other jobs you might not like, but that is just a fact of life.I strongly suggest if this profession has your 100% passion, then continue your studies and focus not on the picture of an hobbyist, but a professional developer. You need to focus on not only writing the code, but DESIGNING the site, the pages, and then design the page at the object level.The senior members of W3Schools are bending over backwards to help you as much as they can, as this venue has helped many web developers in solving questions. May I suggest you take a step backwards and using some type of "plan" describe the high level steps to create your project. If you can provide that information, then it would be more productive to "dissect" your problem code and help you.Cheers!

Link to comment
Share on other sites

  • Replies 190
  • Created
  • Last Reply

Is this file right to show insert data on my website?<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 * FROM Products");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'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Quantity'] . "</td>; echo "</tr>"; }echo "</table>";mysql_free_result($result);?></body></html>

Link to comment
Share on other sites

Sadly, there is nobody here that can make you an "expert" overnight. That onus is entirely on you, and you must dedicate yourself to a discipline I you want to be good at it. I'm sorry to hear about your financial situation, but keep in mind there are millions of people in financial distress, however you have to make a decision. If you are looking to "jump into" web development, you will get in line with the other thousands of developers waiting for job offers. Until you can perfect your skills, then you might be forced to work in other jobs you might not like, but that is just a fact of life.I strongly suggest if this profession has your 100% passion, then continue your studies and focus not on the picture of an hobbyist, but a professional developer. You need to focus on not only writing the code, but DESIGNING the site, the pages, and then design the page at the object level.The senior members of W3Schools are bending over backwards to help you as much as they can, as this venue has helped many web developers in solving questions. May I suggest you take a step backwards and using some type of "plan" describe the high level steps to create your project. If you can provide that information, then it would be more productive to "dissect" your problem code and help you.Cheers!
Another time: you are totally right and I will AFTER this website is finished!
Link to comment
Share on other sites

This is what I see now.What do I wrong?Description Price Quantity "; while($row = mysql_fetch_assoc($result)) { echo "" . $row['Description'] . ""; echo "" . $row['Price'] . ""; echo "" . $row['Quantity'] . "; echo ""; } echo ""; mysql_free_result($result); ?>

Link to comment
Share on other sites

Is this file right to show insert data on my website?<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 * FROM Products");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'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Quantity'] . "</td>; echo "</tr>"; }echo "</table>";mysql_free_result($result);?></body></html>
it's right if it works. does it?
Link to comment
Share on other sites

you just asked if it was right. you never said anything about a problem. Your past few posts have been just code snippets asking if they work. In this case, as with the past ones, there was no indication you had actually tried it to see if it works.

Link to comment
Share on other sites

Now I´ve finally data via (INSERT) my form html on my screen, but it doesn´t do what I want (showing only the latest inserted data!). I assume I must use a loop, but which one? While?, For, For each, etc.? And this is the problem I wrote yesterday! The LATEST INSERTED data is NOT on my screen!<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 * FROM Products");echo "<table border='1'><tr><th>Description</th><th>Price</th><th>Quantity<th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Description'] . "</td>"; 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

what do you mean latest? Do you mean only the very last record added to the database? If so, you can use LIMIT, DESC, and ORDER BY in your query to pull it off. http://www.w3schools.com/php/php_mysql_order_by.asphttp://www.w3schools.com/sql/sql_orderby.asphttp://www.1keydata.com/sql/sql-limit.html

Link to comment
Share on other sites

what do you mean latest? Do you mean only the very last record added to the database? If so, you can use LIMIT, DESC, and ORDER BY in your query to pull it off. http://www.w3schools.com/php/php_mysql_order_by.asphttp://www.w3schools.com/sql/sql_orderby.asphttp://www.1keydata.com/sql/sql-limit.html
Thanks very much! Indeed, LIMIT I´m going to use! But I need 2 htm files with 2 different SELECT queries? 1 for the SELECT query and 1 for the INSERT data? Does it matter how I call them: ......php/.......html?
Link to comment
Share on other sites

What´s the error in line 13?<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 eduardli_company FROM Products ORDER BY Price DESC LIMIT 1echo "<table border='1'><tr><th>Description</th><th>Price</th><th>Quantity<th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Description'] . "</td>"; 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

Did you get an error message and try to fix it yourself first before asking? These are easy mistakes you've already made before and should be able to solve on your own by now.As we've mentioned before, you could do it all with one script, but for now it's just easier to focus on the individual pieces until you get them working and understand them better.

Link to comment
Share on other sites

Did you get an error message and try to fix it yourself first before asking? These are easy mistakes you've already made before and should be able to solve on your own by now.As we've mentioned before, you could do it all with one script, but for now it's just easier to focus on the individual pieces until you get them working and understand them better.
Ok, thanks!
Link to comment
Share on other sites

But this error I don´t understand: Because it doesn´t show the values and those I need!Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/eduardli/public_html/web_designer/select.php on line 24Description Price Quantity <html><body><?php$con = mysql_connect("localhost","eduardli_user","-z.x,c");if (!$con) { die('Could not connect: ' . mysql_error()); }$result = mysql_query ("SELECT eduardli_company FROM Products ORDER BY Price DESC LIMIT 1");echo "<table border='1'><tr><th>Description</th><th>Price</th><th>Quantity<th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Description'] . "</td>"; 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

It means that the function expects a resource but it was given a boolean. Which means that your query failed and returned false. Add this snippet after you execute the query to see why it failed:

if (!$result) {   echo mysql_error();}

Link to comment
Share on other sites

Why is it so difficult to explain what I´ve been trying since 6 days?If you go to my website www.eduardlid.com > webdesigner > INSERT dataI only want to show the result of the output on my website! That´s all!

Link to comment
Share on other sites

ok, well let's look at the line and the error.

while($row = mysql_fetch_array($result))

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/eduardli/public_html/web_designer/select.php on line 24
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.

expects parameter 1 to be resource, boolean given
http://php.net/manual/en/function.mysql-fetch-array.php
Parameters(1) resultThe result resource that is being evaluated. This result comes from a call to mysql_query().
so 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.php
Return ValuesFor SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query
So 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.
Link to comment
Share on other sites

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

$result

we can look at the rest of the message.so 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), or in this case, $result, since it's a string, will resolve to a true value when tested for true or false value. So since we know that you have the wrong type of variable for the mysql_fetch_array function, you know you need a resource type instead. What's that? You've dealt with them before. But for your own reference, looking up the function on the php.net site would have told you.http://php.net/manual/en/function.mysql-fetch-array.phpSo it looks like you've never bothered to execute the query. 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 you're every issue/problem/question. Being a professional developer requires resourcefulness and self-motivation.

Sorry, I don´t understand your explanation!I totally disagree with the latest part! I even think there´s no one in the WORLD as motivated as I am (because I urgently to earn my own money with it!)EDIT:It´s very easy to ´prejudige´ from your lazy chair:- you don´t live in a foreign country- I assume you aren´t disabled- you don´t live alone in a house WITHOUT any adaptation- I assume you have heating and a fridge! I don´t!- etc.
Link to comment
Share on other sites

It´s very easy to ´prejudige´ from your lazy chair:- you don´t live in a foreign country- I assume you aren´t disabled- you don´t live alone in a house WITHOUT any adaptation- I assume you have heating and a fridge! I don´t!- etc.
You know, none of those are required to be a good programmer or to learn effectively. It sounds like more excuses to me.
Sorry, I don´t understand your explanation!
What don't you understand? Take it step-by-step and ask specific questions about specific things you don't understand.
Link to comment
Share on other sites

You know, none of those are required to be a good programmer or to learn effectively. It sounds like more excuses to me.NO THEY ARE NOT! BUT THEY ARE INCONVENIENCES! E. g. I need much more time to do shopping, to dress myself, need to go every time when I go to the centre in tavi, etc. So I have far less time and much more stress!What don't you understand? Take it step-by-step and ask specific questions about specific things you don't understand.
Link to comment
Share on other sites

Actually, scientist's explanation is a little off. Particularly:

So it looks like you've never bothered to execute the query. Simple.
The query actually was executed. This:$result = mysql_query ("SELECT eduardli_companyFROM ProductsORDER BY Price DESCLIMIT 1");executes the query.If you look at the documentation it tells you:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
So...if the query is successful, you get a resource. If it fails, you get the boolean value FALSE.Now look at the error message:
mysql_fetch_array() expects parameter 1 to be resource, boolean given
So, you're sending a boolean value to mysql_fetch_array instead of a resource. This means that the variable $result was assigned a boolean value. The only possible return values of mysql_query are resource or FALSE, so if $result is boolean, that means $result is FALSE. If $result is FALSE, that means your query failed.You need to look at the SQL string you sent to mysql_query to figure out why the query failed.
Link to comment
Share on other sites

Actually, scientist's explanation is a little off. Particularly:The query actually was executed. This:$result = mysql_query ("SELECT eduardli_companyFROM ProductsORDER BY Price DESCLIMIT 1");executes the query.If you look at the documentation it tells you:So...if the query is successful, you get a resource. If it fails, you get the boolean value FALSE.Now look at the error message:So, you're sending a boolean value to mysql_fetch_array instead of a resource. This means that the variable $result was assigned a boolean value. The only possible return values of mysql_query are resource or FALSE, so if $result is boolean, that means $result is FALSE. If $result is FALSE, that means your query failed.You need to look at the SQL string you sent to mysql_query to figure out why the query failed.
Thanks!
Link to comment
Share on other sites

Actually, scientist's explanation is a little off. Particularly:The query actually was executed. This:$result = mysql_query ("SELECT eduardli_companyFROM ProductsORDER BY Price DESCLIMIT 1");executes the query.If you look at the documentation it tells you:So...if the query is successful, you get a resource. If it fails, you get the boolean value FALSE.Now look at the error message:So, you're sending a boolean value to mysql_fetch_array instead of a resource. This means that the variable $result was assigned a boolean value. The only possible return values of mysql_query are resource or FALSE, so if $result is boolean, that means $result is FALSE. If $result is FALSE, that means your query failed.You need to look at the SQL string you sent to mysql_query to figure out why the query failed.
noted and fixed/updated.
Link to comment
Share on other sites

You´ve accused me of NOT being motivated and I use excuses (which I don´t!)! Thanks to you I´ve enough luggage to go my own way! I´ll finish my website and I´ll ´see´ you after that, because there´s still a lot to learn!

Link to comment
Share on other sites

Archived

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


×
×
  • Create New...