I would like to create a database using MySQL and php. But because of php, i can only access through my website, not a stand alone database? What I want is to have a database that I could type in the generic or scientific name of the product and comes up with the details of that product. How can I do that? I just started learning mysql and php. Thanks
most of hosting have cpanel and there is a option when you can create a db. ( i don't think that you'll have the privilege of doing that from php) but if you can you can find the syntax here dev.mysql.com/doc/refman/5.0/en/create-database.html but i think that you are talking about a table try mysql.com for more documentation
Assuming you have rights to create a database and create a table, try.. <? $connect = mysql_connect("host","username","password"); mysql_query("CREATE DATABASE somename",$connect) or die(mysql_error()); mysql_query("CREATE TABLE products ( id INT(11) default NULL auto_increment, productGenericName char(120) default NULL, productScientificName char(120) default NULL, productDescription text default NULL, PRIMARY KEY (id) ) ENGINE=MyISAM") or die(mysql_error()); mysql_close($connect); ?> PHP:
If you want to do this on your local machine you will need to install Apache and mysql. You will still have to use your browser but it will all be hosted on your machine. Check out Xampp or any of the othe complete packages. More questions?
OK ppl, i have wamp installed, played around with mysql console and phpmyadmin, created db's and tables. Cool.. Now, I'm trying to connect php to mysql, but I get "download index.php" when I load the file in IE. Code I used: <?php mysql_connect("localhost", "root", "xxxx") or die(mysql_error()); echo "Connected to MySQL<br />"; ?> PHP: If it worked, it was supposed to say "Connected to MySQL ", according to a tutorial. Anything I'm missing?
Create a simple page with the following code and save in the document root and access it through browser. If you see any output it means your PHP is configured properly. <?php phpinfo(); ?> Code (markup):
If you are using some form of wamp, the most common reason for the server downloading files instead of rendering them is that your configuration file (httpd.conf) is missing the line that tells it to parse PHP files. Try adding this line to the Apache configuration file if it's not already there. AddType application/x-httpd-php .php
I have created a database and a table, was able to use php and mysql display the information onto a webpage using query, fetch_array, and loops. Now I want to have a field (or search box?) so the user can enter the name of the product and it's related details appear.
A quick show: <?php if($_POST['submit']){ $user = $_POST['user']; // YOU MUST SANITIZE THIS $qu = mysql_query("SELECT * FROM tblname WHERE username='$user'")or die(mysql_error()); echo 'There were '.mysql_num_rows($qu).' matches!'; }else{ echo ' <form method="post"> Username to search: <input type="text" name="user"/> <input type="submit" name="submit" value="Search"/> </form> '; } PHP:
xfreex, do you need action there? I've never had action in any of my forms, but it seems to work. I did miss out the closing php tag though, here you go: <?php if($_POST['submit']){ $user = $_POST['user']; // YOU MUST SANITIZE THIS $qu = mysql_query("SELECT * FROM tblname WHERE username='$user'")or die(mysql_error()); echo 'There were '.mysql_num_rows($qu).' matches!'; }else{ echo ' <form method="post"> Username to search: <input type="text" name="user"/> <input type="submit" name="submit" value="Search"/> </form> '; } ?> PHP:
^it wasn't about the closing tag, i had it included, but it sitll didn't work. And the action didn't make a difference. I'm getting this: Notice: Undefined index: submit in D:\wamp\www\php_sandbox\index.php on line 3 Any ideas? And in place of "user" I put the username I have for the database, correct? I did that, and when I search for a pdt, I get "No database selected". There's no place to add the database name in the code, only the table name.