954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

submiting info into a database for retrieval!


How people felt about my site!

<?php


// prints out at top of page, so that poeple know what they are looking at//
echo "poeple that found site to be horrible:

";


/* declar some relevant variables */

$Host = "locationofmysql"; //location of mySQL on server
$User = "yourlogin"; //my username
$Pass = "yourpass"; //my password
$Name = "phpforms"; //name of the database to be used
$Table = "nameoftable"; //name of the table within the database

mysql_connect ($Host, $User, $Pass, $Name, $Table) or die ("unable to connect to database");
@mysql_select_db("$Name") or die ("unable to select DB");
$sqlquery = "SELECT * FROM $Table WHERE opinion = 'is horrible'";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);


$i = 0;

if ($number < 1)
{
echo "No results to display!


";
}
else
{
while ($number > $i)
{
$thename = mysql_result ($result, $i, "name");
$theemail = mysql_result ($result, $i, "email");
echo "Name: $thename
E-Mail:$theemail ";
$i++;
}
}
?>


<?php


// prints out at top of page, so that poeple know what they are looking at//
echo "People that found your site ok:

";


/* declar some relevant variables */

$Host = ""; //location of mySQL on server
$User = ""; //my username
$Pass = ""; //my password
$Name = "phpforms"; //name of the database to be used
$Table = "information"; //name of the table within the database

mysql_connect ($Host, $User, $Pass, $Name, $Table) or die ("unable to connect to database");
@mysql_select_db("$Name") or die ("unable to select DB");
$sqlquery = "SELECT * FROM $Table WHERE opinion = 'is OK'";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);


$i = 0;

if ($number < 1)
{
echo "No results to display!


";
}
else
{
while ($number > $i)
{
$thename = mysql_result ($result, $i, "name");
$theemail = mysql_result ($result, $i, "email");
echo "Name: $thename
E-Mail:$theemail ";
$i++;
}
}
?>


<?php


// prints out at top of page, so that poeple know what they are looking at//
echo "People that liked your site:

";


/* declar some relevant variables */

$Host = ""; //location of mySQL on server
$User = ""; //my username
$Pass = ""; //my password
$Name = "phpforms"; //name of the database to be used
$Table = "information"; //name of the table within the database

mysql_connect ($Host, $User, $Pass, $Name, $Table) or die ("unable to connect to database");
@mysql_select_db("$Name") or die ("unable to select DB");
$sqlquery = "SELECT * FROM $Table WHERE opinion = 'is great'";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);


$i = 0;

if ($number < 1)
{
echo "No results to display!


";
}
else
{
while ($number > $i)
{
$thename = mysql_result ($result, $i, "name");
$theemail = mysql_result ($result, $i, "email");
echo "Name: $thename
E-Mail:$theemail ";
$i++;
}
}
?>

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

Heres a zip file with the code. (had to fix the code, previous version had sensative information in it ;))

Attachments database.zip (2.58KB)
Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

Hey there!

Your tutorial has really helped me so far... but i am sort of wondering something: can you do more than one 'INSERT' at the same time to the same table and same database? If so, how do you do the connection? Once at the beginning or everytime? Do you have to do a new query everytime too?

Here is my code.. i have a few if-statements depending on which and if a product has been chosen. I want to inserta new row for every if-statement. But i can't get it to work..

Would appreciate any help i can get..

Cynthia
(cynno410@student.liu.se)

<?php
$DBhost = "*****";
$DBuser = "*****";
$DBpass = "******";
$NameofDB = "******";
$Table = "bestallning_info";

$product = $_POST["chosen_product"]; //"chosen_produkt" is a //checkbox.. there is 5 of them on my site that can all be chosen at the same time, of course.
$temp = $_POST["amout"];
$input1 = ltrim($temp);

$temp2 = $_POST["amount2"];
$input2 = ltrim($temp2);

$temp3 = $_POST["amount3"];
$input3 = ltrim($temp3);

$temp4 = $_POST["amount4"];
$input4 = ltrim($temp4);

$temp5 = $_POST["amount5"];
$input5 = ltrim($temp5);

$order_id = $t;
//$produkt_id;




if ($product == "gron_randig"){
mysql_connect($DBhost, $DBuser, $DBpass) or die("Unable to connect to database");
@mysql_select_db($NameofDB) or die("Unable to select $NameofDB");

$t ='1';
$produkt_id1 ='100301';
$sqlquery = "INSERT INTO $Table VALUES ('$t','$input1','$produkt_id1')";
$results = mysql_query($sqlquery);
mysql_close();

}


if ($product == "rod_randig"){

mysql_connect($DBhost, $DBuser, $DBpass) or die("Unable to connect to database");
@mysql_select_db($NameofDB) or die("Unable to select $NameofDB");

$t ='1';
$produkt_id2 ='100302';
$sqlquery2 = "INSERT INTO $Table VALUES ('$t','$input2','$produkt_id2')";
$results2 = mysql_query($sqlquery2);
mysql_close();

}

Angelik
Newbie Poster
2 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

I havn't evaluated your code in depth, but your code doesn't look half bad. Maybe double check your pre-existing table [bestallning_info] and make sure the SQL code was done correctly.

Also, maybe post the exact problem your having..

example: cant connect to db
error on line whatever

something specific would help us help you.

snipertomcat
Newbie Poster
2 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You