Jump to content
eduard

Show insert data in database on my website?

Recommended Posts

That's an example to get a row and use print_r to display it.
But I can use it to show the output of this:<html><body><?phpvar_dump($_POST);if (isset($_POST['price']) && isset($_POST['description']) && isset($_POST['quantity'])){echo "succesful form submission. initialize DB connection .....";$con = mysql_connect("localhost","eduardli_user","-z.x,c");if (!$con){die('Could not connect: ' . mysql_error());};echo "connection initialized.....";mysql_select_db("eduardli_company", $con);$sql="INSERT INTO Products (description, price, quantity) VALUES ('$_POST[description]','$_POST[price]','$_POST[quantity]')";echo 'prepare for INSERT: ' . $sql;if (!mysql_query($sql,$con)){die('Error: ' . mysql_error());}else{echo "1 record added";};mysql_close($con);}else{echo "one or more form fields missing";}?></body></html>

Share this post


Link to post
Share on other sites

That script doesn't really have any output. To show the data in the database you use a select statement. You should just put the questions on hold and start trying things, it's really easy to do this and it sounds like you're getting bogged down in asking questions instead of just trying it. Start with that basic example, fill in your database information, see what the script does, and then start changing it to suit your needs.

Share this post


Link to post
Share on other sites
That script doesn't really have any output. To show the data in the database you use a select statement. You should just put the questions on hold and start trying things, it's really easy to do this and it sounds like you're getting bogged down in asking questions instead of just trying it. Start with that basic example, fill in your database information, see what the script does, and then start changing it to suit your needs.
I´ve been to phpMyadmin. To what file do I have to export the output of my INSERT php file into my db on my website? A html file with a SELECT script php in it with a mysql_fetch_assoc() function? Edited by eduardchile

Share this post


Link to post
Share on other sites

again...phpMyAdmin should have nothing to do with the actual output of data on your website. It's just ONE way of managing your database. Hence phpMyADMIN. admin == administration.I'm really finding it hard to think of different way's to explaining this most basic concept. To put data into a database, you've created an1) HTML form to accept user input2) which submits to a PHP script which INSERT(s) that info to the databaseSo now, you just need to do kind of the opposite. You make a script which 1) SELECT(s) information from the database. 2) displays that somehow. In the case of a website, it is outputted within the context of appropriate HTML tags. Seriously, just look at the tutorials. I know I've linked you this before, but everything you need is right there. The SELECT example even shows you how to output the info in <table> tags. Just give it a try. :sigh:

Edited by thescientist

Share this post


Link to post
Share on other sites
again...phpMyAdmin should have nothing to do with the actual output of data on your website. It's just ONE way of managing your database. Hence phpMyADMIN. admin == administration.I'm really finding it hard to think of different way's to explaining this most basic concept. To put data into a database, you've created an1) HTML form to accept user input2) which submits to a PHP script which INSERT(s) that info to the databaseSo now, you just need to do kind of the opposite. You make a script which 1) SELECT(s) information from the database. 2) displays that somehow. In the case of a website, it is outputted within the context of appropriate HTML tags. Seriously, just look at the tutorials. I know I've linked you this before, but everything you need is right there. The SELECT example even shows you how to output the info in <table> tags. Just give it a try. :sigh:
But the examples don´t show a mysql_fetch_ assoc function!So, a html file with a SELECT query (php) in it with a mysql_fetch_assoc function? Edited by eduardchile

Share this post


Link to post
Share on other sites

Eduard, the database on your site already works. You should be able to adapt that code to a new situation.

Share this post


Link to post
Share on other sites

so because they have a working example that uses a similar function for the same kind of output you desire, you're not even going to try it? whatever...

Share this post


Link to post
Share on other sites
mysql_fetch_array() and mysql_fetch_assoc() and mysql_fetch_row() works quite like similarly.in mysql_fetch_array() the second parameter is by default MYSQL_BOTH which will return numeric and associative array both.If you specify the second parameter is MYSQL_NUM it will act as mysql_fetch_row(), it will return the rows as numerical index.If you specify the second parameter is MYSQL_ASSOC it will act as mysql_fetch_assoc(), it will return the rows as associative array.

Share this post


Link to post
Share on other sites
Eduard, the database on your site already works. You should be able to adapt that code to a new situation.
But therefore my question: I am NOT able to adapt that code to a new situation!

Share this post


Link to post
Share on other sites
But therefore my question: I am NOT able to adapt that code to a new situation!
why not? you have shown no attempt at doing so, so what exactly is preventing you from even trying?

Share this post


Link to post
Share on other sites

First,-I didn´t have connection (again) for some hours!Second- as I wrote before-I always try myself BEFORE I send a post (I hate to wait!)Third-is it so difficult to write how it works? Trying many times the wrong way is pretty frustrating and causes a lot of stress (own experience!)

Share this post


Link to post
Share on other sites

I don´t get it! If visitors INSERT data into my db (so it isn´t yet in my db!) by SELECT (data is in the db!) obtain the data I need?

Share this post


Link to post
Share on other sites
If visitors INSERT data into my db (so it isn´t yet in my db!)
That's wrong, that's what we've been trying to tell you. When you use an insert query, the data is in your database. Where else would it go? So using select would get that data.

Share this post


Link to post
Share on other sites
That's wrong, that's what we've been trying to tell you. When you use an insert query, the data is in your database. Where else would it go? So using select would get that data.
Exactly, WOULD IT GO! So, it comes from someone´s mind via a form html, ????? into a database!Or do the data by INSERT first go into the database and AFTER that by a msql_select query you get it? Edited by eduardchile

Share this post


Link to post
Share on other sites

Right, no matter how it gets there, it ends up in the database along with all of the other little data, where they have parties and sleepovers when you're not watching.

Share this post


Link to post
Share on other sites

:)just don't feed them after midnight :)

Share this post


Link to post
Share on other sites

Some times ...... :)

Edited by eduardchile

Share this post


Link to post
Share on other sites
Right, no matter how it gets there, it ends up in the database along with all of the other little data, where they have parties and sleepovers when you're not watching.
How do YOU know (parties, ....)?I assume you watch too many american movies! Edited by eduardchile

Share this post


Link to post
Share on other sites

While I'm up, can I get you guys some more popcorn? :) On a serious note Eduard,If a career in professional web development is your aim, you want to be able to first design the structure of the code. I'm not talking about the visual layout but how the code is structured. This is one of the most important skills a developer needs to learn, because in a professional career, you might be tasked with using several languages and or technologies. However I will digress, lets start with your first project using php and mySql running on Apache.Let's say you are tasked with writing a simple input page, where the user enters their name, email, and comments, and they can submit this. You then want to save this data to a database, and then display the data they entered with a confirmation that the data was successfully received.So the first thing you want to do is write out some psudo code (just use comments) to describe the flow of execution of the program. To get you started, lets assume you haven't created the database or table yet, so the psudo code would look something like this;

// Create the database first// Add the users that can access the database and assign user rights// Create the table to collect the information you need for the comments

As you already know how to do this, your next step is to write the code to display the the page described above. So start by just thinking about how the code is going to flow and forget about the syntax for a moment. What would your psudo code look like?

Share this post


Link to post
Share on other sites
Sometimes they invite me.
In your dreams?

Share this post


Link to post
Share on other sites
While I'm up, can I get you guys some more popcorn? :) On a serious note Eduard,If a career in professional web development is your aim, you want to be able to first design the structure of the code. I'm not talking about the visual layout but how the code is structured. This is one of the most important skills a developer needs to learn, because in a professional career, you might be tasked with using several languages and or technologies. However I will digress, lets start with your first project using php and mySql running on Apache.Let's say you are tasked with writing a simple input page, where the user enters their name, email, and comments, and they can submit this. You then want to save this data to a database, and then display the data they entered with a confirmation that the data was successfully received.So the first thing you want to do is write out some psudo code (just use comments) to describe the flow of execution of the program. To get you started, lets assume you haven't created the database or table yet, so the psudo code would look something like this;
// Create the database first// Add the users that can access the database and assign user rights// Create the table to collect the information you need for the comments

As you already know how to do this, your next step is to write the code to display the the page described above. So start by just thinking about how the code is going to flow and forget about the syntax for a moment. What would your psudo code look like?

Thanks very much! However, first I´ve to solve my ´problem´ (I already have a database!)

Share this post


Link to post
Share on other sites
Thanks very much! However, first I´ve to solve my ´problem´ (I already have a database!)
Perhaps you do not understand what I am asking you.For example, if you were a carpenter and were going to build a house, would you just start laying down lumber and nailing wood together until it "looked like" what you wanted, or would you build this house from a plan?

Share this post


Link to post
Share on other sites
Perhaps you do not understand what I am asking you.For example, if you were a carpenter and were going to build a house, would you just start laying down lumber and nailing wood together until it "looked like" what you wanted, or would you build this house from a plan?
You are totally right! But I wrote several times that I´m ina hurry (unfortunately!) My family won´t support me anymore, so I have to earn mmoney very soon!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...