Jump to content

php & mysql


schoolmommy

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/49901-php-mysql/
Share on other sites

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";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/49901-php-mysql/#findComment-244792
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/49901-php-mysql/#findComment-244990
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.