Jump to content

post error


rdkd1970

Recommended Posts

Can someone help with this error message when I had the @ sign in front of include (db connection etc) I was able to post to my db now I inserted the error_reporting to see why sessions was not going to next page welcoming the member I took out @ added in the error_reporting and get this message.

 

 

Notice: Undefined index: submit in /home/ebermy5/public_html/form.php on line 9

line 9 is the  if($_POST["submit"]){

below

 

<?php

include_once ("Connections/connect_to_mysql.php");

 

error_reporting(E_ALL);

ini_set("display_errors", 1);

 

  $err='';

 

  if($_POST["submit"]){

 

    // Validate form data

 

    if($_POST["firstname"]=='') $err.='Please enter First Name<br>';

    if($_POST["email"]=='') $err.='Please enter Email<br>';

 

 

 

    if($err==''){

 

      // Check if there are duplicate entries in the 'contacts' table

 

      $results = mysql_query("SELECT id FROM `Members` WHERE firstname='".addslashes($_POST["firstname"])."' and Email='".addslashes($_POST["email"])."'");

      if($row = mysql_fetch_array($results)){

        $err.='Can not add duplicate entry<br>';

      }

      else{

 

        // adding new record to 'contacts' table

 

        mysql_query("INSERT INTO Members (firstname,lastname,country,Email)

                    values ('".addslashes($_POST["firstname"])."','".addslashes($_POST["lastname"])."','".addslashes($_POST["country"])."','".addslashes($_POST["email"])."')");

 

      // redirecting to success screen

  if($results){

        header("Location: login.php");

}else

die(mysql_error());

 

      }

    }

  }

 

?>

<html>

<head>

<title>Add New Contact</title>

</head>

 

<body>

 

<h2>Register with us</h2>

 

<?php echo $err==''?'':('<p style="color:red;">'.$err.'</p>') ?>

 

<form method="post" action="form.php">

 

<table border="0">

<tr>

<td valign="middle">First Name:</td>

<td><input type="text" name="firstname" size="30" value="<?php echo htmlspecialchars($firstname) ?>"></td>

</tr>

<tr>

<td valign="middle">Last Name:</td>

<td><input type="text" name="lastname" size="30" value="<?php echo htmlspecialchars($lastname) ?>"></td>

</tr>

<tr>

<td valign="middle">Country:</td>

<td><input type="text" name="country" size="30" value="<?php echo htmlspecialchars($country) ?>"></td>

</tr>

<tr>

<td valign="middle">Email:</td>

<td><input type="text" name="email" size="30" value="<?php echo htmlspecialchars($email) ?>"></td>

</tr>

</table><br>

 

<input type="submit" name="submit" value=" Submit! ">

 

</form>

 

</body>

</html>

 

 

this is my next page after the top information is added to the db.

 

<?php

session_start();

session_id();

?>

 

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Welcome</title>

</head>

 

<body>

<?php

/* Program: login.php

* Desc: Displays the new member welcome page. Greets

* member by name and gives a choice to enter

* restricted section or go back to main page.

*/

error_reporting(E_ALL);

ini_set("display_errors", 1);

$firstname = '';

$id = '';

 

if (isset($_SESSION['id'])) {

 

$id = $_SESSION['id'];

} else {

echo "can not get id";

}

 

include('Connections/connect_to_mysql.php');

$result = mysql_query("SELECT firstname FROM `Members` WHERE id=$id");

$row = mysql_fetch_array($result);

 

if ($firstname == ''){ //condition, is name equal to lower case firstname notice we use == and not =

echo "Welcome, $firstname";

} else { //so incase the condition is not as expected

echo "Sorry you are not $firstname";

}

 

?>

<p>Your new Member accounts lets you enter the members only section

of our web site. You'll find special discounts, a profile of matches,

live advise from experts, and much more.</p>

<p>Your new Member ID and password were emailed to you. Store them

carefully for future use.</p>

<div style="text-align: center">

<p style="margin-top: .5in; font-weight: bold">

Glad you could join us!</p>

<form action="profile.php" method="post">

<input type="submit"

value="Enter the Members Only Section">

</form>

<form action="index.php" method="post">

<input type="submit" value="Go to Main Page">

</form>

</div>

</body>

</html>

 

Link to comment
Share on other sites

Before the form is submitted, the $_POST variables do not exist. Use isset to test variables that might not exist -

  if(isset($_POST["submit"])){

 

You should also have the error_reporting/display_errors settings right after the first opening <?php tags so that any errors produced by any of your code will be reported and displayed.

 

Actually, you should set the error_reporting/display_errors settings in your master php.ini so that fatal parse errors will also be reported and displayed. Then you won't need to remember to put the lines into your files during development and remember to remove them when you put your code onto a live server.

Link to comment
Share on other sites

Okay I got the error message to go and now I am not sure what I am doing as before my page live was not doing showing the coding in the lines to insert member information live. Same coding as before not much has changed but the error reporting.

Link to comment
Share on other sites

Notice: Undefined index: submit in /home/ebermy5/public_html/form.php on line 9\

 

that error means that either $_POST['submit'] hasnt been submitted yet or doesnt exist...do what PFMaBiSmAd said and use isset()

Link to comment
Share on other sites

Okay I was wrong about the error message in the form line is the error message <br /><b>Notice</b>:  Undefined variable: firstname in <b>/home/ebermy5/public_html/form.php</b> on line <b>60</b><br /> due to the coding

 

<tr>

<td valign="middle">First Name:</td>

<td><input type="text" name="firstname" size="30" value="<?php echo htmlspecialchars($firstname) ?>"></td>

</tr>

 

Sorry for my confusion.

Link to comment
Share on other sites

All right I put the vars at the top of the page under the connection to db. $err=""; $id="";$firstname"";$lastname""; etc things are looking better. I am going say before I test it updating data to the database that is is a good well done thanks all.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.