eduard Posted April 16, 2011 Share Posted April 16, 2011 To show the output of the insert data of my form.html in my database, I must write a script SELECT php? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 16, 2011 Share Posted April 16, 2011 If you're talking about displaying the data from your database, the only thing you need is a page that connects and uses a SELECT query to get the data, then a loop to display it. Look at the examples here:http://www.w3schools.com/php/php_mysql_select.asphttp://www.php.net/manual/en/function.mysql-fetch-assoc.php Link to comment Share on other sites More sharing options...
eduard Posted April 16, 2011 Author Share Posted April 16, 2011 If you're talking about displaying the data from your database, the only thing you need is a page that connects and uses a SELECT query to get the data, then a loop to display it. Look at the examples here:http://www.php.net/manual/en/function.mysql-fetch-assoc.php That´s it! Thanks! Link to comment Share on other sites More sharing options...
jeffman Posted April 17, 2011 Share Posted April 17, 2011 Eduard! I went to your site and added some data to your database. Then I saw it show up in your table. I think you are beginning to get it. Good job. Link to comment Share on other sites More sharing options...
eduard Posted April 17, 2011 Author Share Posted April 17, 2011 Eduard! I went to your site and added some data to your database. Then I saw it show up in your table. I think you are beginning to get it. Good job. One of my favourite (I have many!) songs is Supertramp:TAKE THE LONG WAY HOME(Thanks!) Link to comment Share on other sites More sharing options...
eduard Posted April 17, 2011 Author Share Posted April 17, 2011 Can someone tell me what I have to do to chance 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>into this?<?php$conn = mysql_connect("localhost", "mysql_user", "mysql_password");if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit;} if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit;}$sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1";$result = mysql_query($sql);if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit;}if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit;}// While a row of data exists, put that row in $row as an associative array// Note: If you're expecting just one row, no need to use a loop// Note: If you put extract($row); inside the following loop, you'll// then create $userid, $fullname, and $userstatuswhile ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"];}mysql_free_result($result);?> Link to comment Share on other sites More sharing options...
thescientist Posted April 18, 2011 Share Posted April 18, 2011 are you asking how to modify it for your needs? Link to comment Share on other sites More sharing options...
eduard Posted April 18, 2011 Author Share Posted April 18, 2011 are you asking how to modify it for your needs?I want to show the data which have visitors inserted via the form.html in a database on my website! Must this a SELECT script (see above) and what do I have to change in my SELECT script? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2011 Share Posted April 18, 2011 You posted an insert script, from your site, and a select script, from an example. If you want to change that select script to work with your database, change the query so that it selects the correct field names from the correct table, and change the while loop where it prints each row to use the correct field names. You'll also need to update the connection and mysql_select_db information so it uses your database information. Link to comment Share on other sites More sharing options...
eduard Posted April 18, 2011 Author Share Posted April 18, 2011 You posted an insert script, from your site, and a select script, from an example. If you want to change that select script to work with your database, change the query so that it selects the correct field names from the correct table, and change the while loop where it prints each row to use the correct field names. You'll also need to update the connection and mysql_select_db information so it uses your database information.I send my SELECT script:<html><body><?php$con = mysql_connect("localhost","eduardli_user","");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>What do I have to change and how do I update my mysql connection? (tutorial UPDATE database!)But I need to have 2 SELECT files?1 to SELECT data2 to show INSERTed data??? Link to comment Share on other sites More sharing options...
thescientist Posted April 18, 2011 Share Posted April 18, 2011 you use whatever dbname, username, password, etc that you've been using. have you just tried what you have? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2011 Share Posted April 18, 2011 1 to SELECT data2 to show INSERTed data???What's the difference? Link to comment Share on other sites More sharing options...
eduard Posted April 18, 2011 Author Share Posted April 18, 2011 What's the difference?Insert INTO my dbSelect OUT of my dbSorry, I assume you meant the files! Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2011 Share Posted April 18, 2011 When you're selecting data, you don't select "inserted" data versus "other" data. All of the data is the same, regardless of how it got there. Link to comment Share on other sites More sharing options...
eduard Posted April 18, 2011 Author Share Posted April 18, 2011 When you're selecting data, you don't select "inserted" data versus "other" data. All of the data is the same, regardless of how it got there.Still my question: How can I show the data visitors have INSERTed by my form.html in a database on my website? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2011 Share Posted April 18, 2011 You select it, and print it. The same way you display any other data. Link to comment Share on other sites More sharing options...
eduard Posted April 18, 2011 Author Share Posted April 18, 2011 You select it, and print it. The same way you display any other data.Ok, I (finally) understand! Now, how do I do it? Via the fetch mysql example you sent me and how do I make this (SELECT) script apropiate for my website? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2011 Share Posted April 18, 2011 You can send the query and then use mysql_fetch_assoc or another fetch function to get each row. I'm not real sure what you mean about making it appropriate for your site. Link to comment Share on other sites More sharing options...
eduard Posted April 18, 2011 Author Share Posted April 18, 2011 You can send the query and then use mysql_fetch_assoc or another fetch function to get each row. I'm not real sure what you mean about making it appropriate for your site.Is this a right example?<?php$con = mysql_connect("localhost", "peter", "abc123");if (!$con) { die('Could not connect: ' . mysql_error()); }$db_selected = mysql_select_db("test_db",$con);$sql = "SELECT * from Person WHERE Lastname='Refsnes'";$result = mysql_query($sql,$con);print_r(mysql_fetch_assoc($result));mysql_close($con);?> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2011 Share Posted April 18, 2011 That's an example to get a row and use print_r to display it. Link to comment Share on other sites More sharing options...
eduard Posted April 18, 2011 Author Share Posted April 18, 2011 That's an example to get a row and use print_r to display it.But is it that my file must be? (to show the inserted data on my website)? Link to comment Share on other sites More sharing options...
thescientist Posted April 19, 2011 Share Posted April 19, 2011 only you know how you want it to look. That's just one way to display the data. If you want to display it as a table for example, then you'll need to output it within HTML. Like we've said countless times, tutorials and examples are just that; at their most basic they are meant to show you proof of concept. There's too many possibilites for way's to output data (as far as formatted output) to make a tutorial/example for them all. So just figure out how you want it to look, and then work towards that endpoint. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 19, 2011 Share Posted April 19, 2011 But is it that my file must be?No, Yoda, you can output it however you want. Like thescientist said, there are several ways to output your data. It doesn't even need to go on a web page, you could put that in a RSS feed, Excel spreadsheet, PDF document, or even an image if you're nasty. Go into phpMyAdmin and click on the Export tab for a table, and look at how many options there are there. The majority of the time your data will be displayed on a web page, but the point we're trying to make is there is nothing you need to do with the data. Granted, there are certain things you need to use, like mysql_connect, mysql_select_db, mysql_query, etc, but what you want to do with the data is up to you. Link to comment Share on other sites More sharing options...
eduard Posted April 19, 2011 Author Share Posted April 19, 2011 No, Yoda, you can output it however you want. Like thescientist said, there are several ways to output your data. It doesn't even need to go on a web page, you could put that in a RSS feed, Excel spreadsheet, PDF document, or even an image if you're nasty. Go into phpMyAdmin and click on the Export tab for a table, and look at how many options there are there. The majority of the time your data will be displayed on a web page, but the point we're trying to make is there is nothing you need to do with the data. Granted, there are certain things you need to use, like mysql_connect, mysql_select_db, mysql_query, etc, but what you want to do with the data is up to you.I´m going sleep on(?) that!Yes, I could do that! The output on a ´bottom´ of a nude woman! Link to comment Share on other sites More sharing options...
eduard Posted April 19, 2011 Author Share Posted April 19, 2011 only you know how you want it to look. That's just one way to display the data. If you want to display it as a table for example, then you'll need to output it within HTML. Like we've said countless times, tutorials and examples are just that; at their most basic they are meant to show you proof of concept. There's too many possibilites for way's to output data (as far as formatted output) to make a tutorial/example for them all. So just figure out how you want it to look, and then work towards that endpoint.Ok, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.