Jump to content


Photo

Simple input for Data Base


  • Please log in to reply
3 replies to this topic

#1 Jay2391

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

Posted 27 September 2006 - 07:48 PM

All I am trying to do is to input data from a PHP page to my database but it is not working looking for a new set of eyes...

Database:  mainlydigital
Table: users
server: localhost
hot id: host
pass: 12345
>:(

<HTML>
<head>
<title>MD Register</title></head>
<body>

<?php
$self = $_SERVER['PHP_SELF'];
$userid = $_POST['userid'];
$name = $_POST['name'];
$last = $_POST['last'];
$email = $_POST['email'];
$state = $_POST['state'];
$country = $_POST['country'];
$accname = $_POST['accname'];
$password = $_POST['password'];
$code = $_POST['code'];
$news = $_POST['news'];
$agreed = $_POST['agreed'];
$domain = "localhost";
$user = "root";
$pass = "12345";


if( $userid and $name and $last and $email and $state and $country and $accname and $password and $code and $news and $agreed){

    $conn = mysql_connect($domain, $user, $pass);

    $rs = mysql_select_db("mainlydigital", $conn) or die( "Err:Db" );

    $sql = "insert into users (userid, name, last, email, state, country, accname, password, code, news, agreed) values ( $userid, \"$name\", \"$last\", \"$email\", \"$state\", \"$country\", \"$accname\", \"$password\", \"$passwordv\", \"$code\", \"$news\", \"$agreed\")";

    $rs = @mysql_query( $sql, $conn );

        if( $rs ){
        echo( "Record added:$userid <br> $name <br> $last" );
        }
}

?>

<form
          action="<?php echo( $self ); ?>" method="post"><br>
          ID: <input type="text" name="id" size="3"><br>
          First Name: <input type="text" name="name" size="30">
          Last Name: <input type="text" name="last" size="30"><br>
          E-Mail:<input type="text" name="email" size="50"><br>
          City & State: <input type="text" name="state" size="30">
          Country: <input type="text" name="country" size="30"><br><br>
          Account Name: <input type="text" name="accname" size="30"><br><br>
          Enter Password (8 to 12 Characters):<br><input type="text" name="password" size="30"><br>
          Enter a four Digit Numeric Code:<br><input type="text" name="code" size="30"><br><br>
          Will you like email news about this site:<br><input type="text" name="news" size="30"><br>
          Confirm you have read all the rules and regulations <br>and you
          agreed to obey by those:<br><input type="text" name="agreed" size="30"><br>

<br><br>
<input type="submit" value="Register">
</form>
</body>
</HTML>



#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 27 September 2006 - 07:54 PM

First of all, dont surpress with @ when testing....

replace --> $rs = @mysql_query( $sql, $conn );
with --> $rs = mysql_query( $sql, $conn ) or die(mysql_error());

and see what it says..

#3 Jay2391

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

Posted 27 September 2006 - 08:03 PM

No erros...at all ...

I am on php5 BTW

#4 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 27 September 2006 - 08:33 PM

mismatch in number of cols compared to variables in query - missing "passwordv"

$sql = mysql_query("insert into users (userid, name, last, email, state, country, accname, password, [red]passwordv[/red], code, news, agreed) values ('$userid', '$name', '$last', '$email', '$state', '$country', '$accname', '$password', '$passwordv', '$code', '$news', '$agreed')") or die(mysql_error());

But if userid is auto incr primary key, you should also remove this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users