Jump to content


Photo

Submit info to DB


  • Please log in to reply
4 replies to this topic

#1 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 13 October 2006 - 08:24 PM

I created thsi code is just to submit info to a database... but it dosen't submit the information

database name    natgal
table                  users



<html>
<head>
<title>Record</title></head>
<body>

<?php

$user = "root";
$pass = "12345";
   
$self = $_SERVER['PHP_SELF'];
$userid = $_POST['userid'];
$name = $_POST['name'];
$last = $_POST['last'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['coutry'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$nickname = $_POST['nickname'];
$age = $_POST['age'];

?>

<form action="<?php echo( $self ); ?>" method="post">
Registration Screen <br><br>
User ID: <input type="text" name="userid" size="30"><br>
First Name: <input type="text" name="name" size="30"><br>
Last Name: <input type="text" name="last" size="30"><br>
City: <input type="text" name="city" size="30"><br>
State: <input type="text" name="state" size="30"><br>
Coutry: <input type="text" name="country" size="30"><br>
E-mail: <input type="text" name="email" size="30"><br>
Gender: <input type="text" name="gender" size="30"><br>
Nick Name: <input type="text" name="nickname" size="30"><br>
Age: <input type="text" name="age" size="30"><br><br>

<input type="submit" value="Submit"><br>
</form>

<?php

  if( $self and $userid and $name and $last and $city and $state and $country and $email and $gender and $nickname and $age ){

  $conn=mysql_connect ("localhost", $user, $pass)
  or die ('I cannot connect to the database because: ' . mysql_error());
  mysql_select_db ("natgal");

   
  $sql = "insert into users ( userid, name, last, city, state, country, email, gender, nickname, age) values ( $userid, \"$name\", \"$last\", \"$city\",\"$state\", \"$country\", \"$email\", \"$gender\", \"$nickname\", \"$age\")";
  $rs = mysql_query( $sql, $conn );

  if( $rs ){
  echo( "Record added:$userid $name $last $city $state $country $email $gender $nickname $age" );
  }
}
?>

</body>
</html>

#2 dymon

dymon
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 13 October 2006 - 08:56 PM

Hi,

I would advice you first to show the error:

  $rs = mysql_query( $sql, $conn ) or die (mysql_error());

This error could say a lot about the problem you have.

And try to make the query like this:
$sql = "insert into users ( userid, name, last, city, state, country, email, gender, nickname, age) values ( '$userid', '$name', '$last', '$city', '$state', '$country', '$email', '$gender', '$nickname', '$age')";
This should work. Hope it helps.

Web is the future ... desktop will die ...

#3 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 16 October 2006 - 01:46 AM

I get no errors and that did ot work ... I did a test and i know I am conecting to the DB ...

ay other sugestions

#4 joshi_v

joshi_v
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 16 October 2006 - 10:10 AM

Hi

Replace this in your code

<form action="<?php echo( $self ); ?>" method="post">

with

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

and try.


Regards

Joshi.

#5 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 17 October 2006 - 05:21 PM

here is how i fix it ... Capital letters in the select statements

<html>
<head>
<title>Add Record</title>
</head>
<body>

<?php

$user="root";
$pass="12345";

$self=$_SERVER['PHP_SELF'];
$userid=$_POST['userid'];
$name=$_POST['name'];
$last=$_POST['last'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$nickname=$_POST['nickname'];
$age=$_POST['age'];

?>

<form action="<?php echo( $self );?>" method="post">
User ID: <input type="text" name="userid" size"30"><br>
Name: <input type="text" name="name" size"30"><br>
Last: <input type="text" name="last" size"30"><br>
City: <input type="text" name="city" size"30"><br>
State: <input type="text" name="state" size"30"><br>
Country: <input type="text" name="country" size"30"><br>
Email: <input type="text" name="email" size"30"><br>
Gender: <input type="text" name="gender" size"30"><br>
Nickname: <input type="text" name="nickname" size"30"><br>
Age: <input type="text" name="age" size"30"><br>
<input type="submit" value="Submit"><br>
</form> 



<?php

    if($userid and $name and $last and $city and $state and $country and $email and $gender and $nickname and $age){
 

    $dbh=mysql_connect("localhost", $user, $pass) or die ("Err:Conn");
 
    if($dbh){
      echo ("Congrats!!!");

    $rs=mysql_select_db("natgal", $dbh) or die ("Err:Db");
   
 
    $sql="INSERT INTO users( userid, name, last, city, state, country, email, gender, nickname, age)
          VALUES ($userid, \"$name\", \"$last\", \"$city\", \"$state\", \"$country\", \"$email\", \"$gender\", \"$nickname\", \"$age\")";
   
    $rs=mysql_query($sql, $dbh);
   
    if($rs){
      echo ("Record Added!!!");
     
          }
      }
    }

?>

</body>
</html>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users