InterviewSolution
| 1. |
Solve : download data from web sql databse? |
|
Answer» hey all, am i right in thinking that "dbhost" should be my website address?? (www.xyz.com) the dbuser and dbpass are pretty clear, as is the dbname. No, "dbhost" is right as localhost, because the server at http://www.xyz.com/ is localhost. But if you are testing it at home using WAMP, it will also be localhost. Quote from: blastman on July 21, 2008, 09:34:27 AM Code: [Select]<?php This is not a good way to store your username and password, though as anyone, if they have the web address, can view it. You would be better off to save it as "these_are_my_database_settings.php" or something to make it difficult for someone to GUESS it. Also, be sure to close the database connection: Code: [Select]<?php $con=mysql_connect("localhost","peter","abc123"); if(!$con) { die('Couldnotconnect:'.mysql_error()); } //somecode mysql_close($con); ?> It would be quite a long script getting all the form fields from a database to an email. You could try W3Schools for more information. Im kind of new to PHP, myself, but if you cant find anything here, I will help you as best I can. cheers fro the help; I've managed to get connected to my remote mysql server OK, but I'm having trouble with getting values from the database. I have a table called 'main'. in this table there is s column called 'id'. I want to know what the max number is in this column. I have the sql statement right, but it returns a 'resource' whcih when i run get_resouce_type() it produces "mysql query" How can I see the value that the sql statement produces??? If I run the sql statement on the server it produces "7" which is what I'm trying to get via my remote script. Cheers in advanceYou could try something like this: Code: [Select]<?php $con=mysql_connect("localhost","username","password"); if(!$con) { die('Couldnotconnect:'.mysql_error()); } mysql_select_db("my_db",$con); $query_table=mysql_query("SELECT*FROMperson"); while($row=mysql_fetch_array($query_table)) { echo$row['FirstName']."".$row['LastName']; echo"<br/>"; } mysql_close($con); ?> If you had two fields in the table, "FirstName" and "LastName", this would write the contents of those fields. Alternatively, you could email them to an email address like this: Code: [Select]<?php $con=mysql_connect("localhost","username","password"); if(!$con) { die('Couldnotconnect:'.mysql_error()); } mysql_select_db("my_db",$con); $query_table=mysql_query("SELECT*FROMperson"); while($row=mysql_fetch_array($query_table)) { $to="[emailprotected]"; $subject="Testmail"; $message="$row['FirstName']."".$row['LastName']"; mail($to,$subject,$message); } mysql_close($con); ?> Please dont copy and paste it, because some of it may be incorrect. |
|