Jump to content

Problem while trying to insert values of form fields into table

- - - - -

  • Please log in to reply
1 reply to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi, here's my form.html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
<body>

<form action="welcome.php" method="post">
Number: <input type="text" name="number" />
Name: <input type="text" name="name" />
Surname: <input type="text" name="surname" />
Level: <input type="text" name="level" />
<input type="submit" />
</form>

</body>
</html>
And here's my welcome.php file. I get 4 such errors in line 28: Notice: Undefined index: number in C:\wamp\www\PhpProject1\welcome.php on line 28. I have coded everything exactly like in this link PHP MySQL Insert Into. Does anyone know what's wrong?

<html>
<body>

<!--Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years olddd2.-->
<?php
$con = mysql_connect("localhost","root","");
if (!$con){
  die('<br/> Could not connect: ' . mysql_error());
} else{
    echo "<br/> Conected";
        mysql_select_db("base1", $con);
        
        $query = "CREATE TABLE Players (
            Number int NOT NULL,
            PRIMARY KEY (Number),
            FirstName char(20),
            LastName char(20),
            Level int
        )";        
        if (mysql_query($query, $con))
            echo "<br/> table created";
        else
            echo "<br/> Error: " . mysql_error();
            
        $query = "INSERT INTO Players (Number, FirstName, LastName, Level) VALUES ('$_POST[number]', '$_POST[name]', '$_POST[surname]', '$_POST[level]')";
        if (mysql_query($query, $con))
            echo "<br/> inserted";
        else
            echo "<br/> Error: " . mysql_error();
            
        $query = "DROP TABLE Players";
        if (mysql_query($query, $con))
            echo "<br/> table deleted";
        else
            echo "<br/> Error: " . mysql_error();
}
mysql_close($con);
?> 

</body>
</html> 


#2
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
Well first off I can tell you it's not your code. I made a few changes (username, passwords, etc.) and ran it on my server and it works fine. Did you make sure the user name you made is set to allow all privileges ( I assume you have to do that on localhost just like if it was a live server?)? A quick googlesearch of your error give us this: [SOLVED] Getting PHP Notice: Undefined index: HTTP_REFERER in C:\Inetpub\cgi-bin\search5.php o - Hot Scripts Forums which in a nutshell says that your full error reporting is not turned on. Turn on full reporting and the errors we get then will help us to solve the problem
Posted Image




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users