1.

Solve : download data from web sql databse?

Answer»

hey all,

I've got my self a website that has a sql database on it. The data base currently holds data from an online form.

I'd like to have a script that can download the last entry from the database but I'm unsure how to go about it.

The hosting company have provided me with a "perl" and "php" string so I can connect, but I've never used either language, so I'm a bit lost.


Anyone got any ideas??

Cheers in advance Have you got PHPMyAdmin on your website? There is an option to download the database in a .zip file.
But if thats not what you want, Im sure you could PHP Mail to email the last entry in the form to you.

Good luck. thanks for the reply.

yes, I do have PHPMyAdmin in my control panel but I'm trying to automate it and I couldn't find a setting to do this for me.

Basically, the site has been written by SOMEONE else, and I'm trying to add a few features. I no nothing about coding websites, so trying to get the site to email me with the data i need when in input's to the database, is like try to get blood out of a stone!!!

What's the easiest platform to run php code on my local machine??

I'll get that and then script a SQL query that will get me the information I'm after??

Cheers agian
ok, I've installed wamp and I can now run xxx.php script from the command LINE.

I'm using this;

Code: [Select]<?php
$dbhost='localhost';
$dbuser='root';
$dbpass='password';

$conn=mysql_connect($dbhost,$dbuser,$dbpass)ordie('Errorconnectingtomysql');

$dbname='petstore';
mysql_select_db($dbname);
?>

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.

I'm getting an error "Fatal error: Call to undefind function mysql_err() on line 6"

any ideas?Quote from: blastman on July 21, 2008, 09:34:27 AM

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
$dbhost='localhost';
$dbuser='root';
$dbpass='password';

$conn=mysql_connect($dbhost,$dbuser,$dbpass)ordie('Errorconnectingtomysql');

$dbname='petstore';
mysql_select_db($dbname);
?>

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.


Discussion

No Comment Found