schoolmommy Posted May 3, 2007 Share Posted May 3, 2007 Hi! I have a program that uses php & mysql. I built the table called "customer" in mysql and an index.htm file and a php file. Basically, the user enteres the data into the form, hits the submit button and the data is entered into the table. I've never worked with mysql and don't really have a clue about how it works. I've worked with Access some and know a lot more about how it works. But for this progam, I have to use mysql. My problem is this - I don't know how to view the data in mysql to make sure that the data enter in the form is in the table. Someone said I needed to put a select statement in my php, but didn't say where it should go. I'm including the php code so hopefully someone can tell me what I'm doing wrong. Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Insert into database</title> </head> <body> <?php //Get data from form extract($_POST); //Check for blank if (($txtName == "") || ($txtemail == "") || ($txtusername == "") || ($txtpassword == "") || ($txtconfirmpass == "") || ($txtaddress == "") || ($txtcity == "") || ($txtstate == "") || ($txtzip == "") || ($txtphone == "")) { header("Location: index.htm"); exit; } if ($txtpassword != $txtconfirmpass) { header("Location: index.htm"); exit; } $connect = @mysql_connect("localhost","****","****") or die(mysql_error()); $db = @mysql_select_db("customer",$connect) or die(mysql_error()); $sql = "INSERT INTO customer VALUES ('$txtname','$txtemail', '$txtusername', '$txtpassword', '$txtaddress', '$txtcity', '$txtstate', '$txtzip', '$txtphone')"; $result = @mysql_query($sql,$db) or die(mysql_error()); SELECT * FROM [customer]; ?> <?php echo "$result"; ?> </body> </html> username & password intentinally *** 'd Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted May 3, 2007 Share Posted May 3, 2007 well to pull info from the database you need to use SELECT <?php $select = "SELECT * FROM customer"; $result = mysql_query($select); if (!$result) { die(mysql_error()); } $rows = mysql_num_rows($result); if ($rows > 0) { echo "Found $rows entries"; } else { echo "Found 0 entries"; } ?> Quote Link to comment Share on other sites More sharing options...
schoolmommy Posted May 4, 2007 Author Share Posted May 4, 2007 Hi! I tried that and still don't see anything on the screen. I went to mysql command line client and typed the Grant All... Is there something else that might keep me from seeing the data in the table? Thanks! Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted May 4, 2007 Share Posted May 4, 2007 try this code <?php //Get data from form extract($_POST); //Check for blank if (($txtName == "") || ($txtemail == "") || ($txtusername == "") || ($txtpassword == "") || ($txtconfirmpass == "") || ($txtaddress == "") || ($txtcity == "") || ($txtstate == "") || ($txtzip == "") || ($txtphone == "")) { header("Location: index.htm"); exit; } if ($txtpassword != $txtconfirmpass) { header("Location: index.htm"); exit; } $connect = @mysql_connect("localhost","****","****") or die(mysql_error()); $db = @mysql_select_db("customer",$connect) or die(mysql_error()); $sql = "INSERT INTO customer VALUES ('$txtname','$txtemail', '$txtusername', '$txtpassword', '$txtaddress', '$txtcity', '$txtstate', '$txtzip', '$txtphone')"; $result = @mysql_query($sql,$db) or die(mysql_error()); $select = "SELECT * FROM customer"; $result = mysql_query($select); if (!$result) { die(mysql_error()); } $rows = mysql_num_rows($result); if ($rows > 0) { echo "Found $rows entries"; } else { echo "Found 0 entries"; } echo "$result"; ?> think it might work Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.