• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

varable errors

hello
i have a page that is giveing me errors on my web server can anyone help

My errors are for all the varables

An error occurred in script /home/phimualp/public_html/register.php on line 125: Undefined index:

my link that shows the errors
http://phimualphapsi.com/register.php
require_once ('config.inc');
 
// Set the page title and include the HTML header.
$page_title = 'Register ';
 
 
if (isset($_POST['submit'])) { // Handle the form.
 
$con = mysql_connect("localhost","phimualp_defjam9","3490d32");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("phimualp_members", $con);
 
}
 
 
//	if ($id && $fn && $ln && $e && $p && $un && $pw) { // If everything's OK.
 
 
		// Make sure the username is available.
//		$query = "SELECT * FROM members";
	//	$result = @mysql_query ($query);
 
	//	if (mysql_num_rows($result) == 0) { // Available.
error_reporting(0);
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);
			// Add the user.
			$query = "INSERT INTO members (ID,Fname,Lname,Email,Phone,Username) VALUES ('$_POST[id]','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[phone]','$_POST[username]')";
		if (!mysql_query($query,$con))
		  {
		  die('Error: ' . mysql_error());
		  }
		echo "Brother you have been added";mysql_close($con)
 
 
?>
 
	<h1>Register</h1>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<fieldset>
		<p><b>ID:</b> <input type="text" name="id" size="15" maxlength="15" </p>
 
	<p><b>First Name:</b> <input type="text" name="fname" size="15" maxlength="15" </p>
 
	<p><b>Last Name:</b> <input type="text" name="lname" size="30" maxlength="30" </p>
 
	<p><b>Email:</b> <input type="text" name="email" size="40" maxlength="40" </p>
 
    <p><b>Phone</b> <input type="text" name="phone" size="30" maxlength="30" </p>
 
    <p><b>Username</b> <input type="text" name="username" size="30" maxlength="30" </p>
 
 
	<p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20"</p>
 
	</fieldset>
 
	<div align="center"><input type="submit" name="submit" value="Register" /></div>
 
	</form><!-- End of Form -->
 
                            </td>
                        </tr>
                    </table>
                </span></code>
            </td>
        </tr>
        <tr

Open in new window

0
Chris Jones
Asked:
Chris Jones
  • 11
  • 9
1 Solution
 
Terry WoodsIT GuruCommented:
I think you need curly braces around your $_POST variables:
$query = "INSERT INTO members (ID,Fname,Lname,Email,Phone,Username) VALUES ('{$_POST[id]}','{$_POST[fname]}','{$_POST[lname]}','{$_POST[email]}','{$_POST[phone]}','{$_POST[username]}')";

Open in new window

0
 
Terry WoodsIT GuruCommented:
You only need the curly braces when an array variable is specified within a string.
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
this gave me more errors good thought though
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Terry WoodsIT GuruCommented:
What errors this time?

Also, which line is line 125 in the php script?
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
                 $query = "INSERT INTO members (ID,Fname,Lname,Email,Phone,Username) VALUES ('$_POST[id]','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[phone]','$_POST[username]')";

LINE 123
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
sorry that is the line 125
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
here is all the errors its very long sorry its a lot of repeating though




An error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant id - assumed 'id'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: idAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant fname - assumed 'fname'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: fnameAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant lname - assumed 'lname'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: lnameAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant email - assumed 'email'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: emailAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant phone - assumed 'phone'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: phoneAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant username - assumed 'username'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: usernameAn error occurred in script /home/phimualp/public_html/register.php on line 127: Undefined variable: conAn error occurred in script /home/phimualp/public_html/register.php on line 127: mysql_query(): supplied argument is not a valid MySQL-Link resourceError: 

Open in new window

0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
that did not post correct

An error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant id - assumed 'id'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: idAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant fname - assumed 'fname'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: fnameAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant lname - assumed 'lname'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: lnameAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant email - assumed 'email'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: emailAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant phone - assumed 'phone'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: phoneAn error occurred in script /home/phimualp/public_html/register.php on line 126: Use of undefined constant username - assumed 'username'An error occurred in script /home/phimualp/public_html/register.php on line 126: Undefined index: usernameAn error occurred in script /home/phimualp/public_html/register.php on line 127: Undefined variable: conAn error occurred in script /home/phimualp/public_html/register.php on line 127: mysql_query(): supplied argument is not a valid MySQL-Link resourceError:
0
 
Terry WoodsIT GuruCommented:
Hmm, try this:
$query = "INSERT INTO members (ID,Fname,Lname,Email,Phone,Username) VALUES ('{$_POST['id']}','{$_POST['fname']}','{$_POST['lname']}','{$_POST['email']}','{$_POST['phone']}','{$_POST['username']}')";

Open in new window

0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
to help with the length of the post here is the link to the php output
http://phimualphapsi.com/register.php

there are less errors but still the same errors
0
 
Terry WoodsIT GuruCommented:
$_POST['id'] must be coming from an html form somewhere, right?

I think the value of $_POST['id'] may not be set - when I view the link you gave, I'm not posting data to the page because I'm not filling in the html form that sets it.

You could add this to your code to get an idea of what's in $_POST:

print_r($_POST)
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
sorry i was in a meeting there is a form but it does not show
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<fieldset>
		<p><b>ID:</b> <input type="text" name="id" size="15" maxlength="15" </p>
 
	<p><b>First Name:</b> <input type="text" name="fname" size="15" maxlength="15" </p>
 
	<p><b>Last Name:</b> <input type="text" name="lname" size="30" maxlength="30" </p>
 
	<p><b>Email:</b> <input type="text" name="email" size="40" maxlength="40" </p>
 
    <p><b>Phone</b> <input type="text" name="phone" size="30" maxlength="30" </p>
 
    <p><b>Username</b> <input type="text" name="username" size="30" maxlength="30" </p>
 
 
	<p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20"</p>
 
	</fieldset>
 
	<div align="center"><input type="submit" name="submit" value="Register" /></div>
 
	</form><!-- End of Form -->

Open in new window

0
 
Terry WoodsIT GuruCommented:
Apologies - I should've seen it in the code above.

You are missing a semi-colon after this line:
echo "Brother you have been added";mysql_close($con)

For readability, it should probably be changed to:
echo "Brother you have been added";
mysql_close($con);
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
ok i made the chanfes and still have the same error
0
 
Terry WoodsIT GuruCommented:
Another try below - the only substantial change is I moved a curly brace for an if statement, but it includes the other corrections I've suggested too.
Try changing:
 
 
if (isset($_POST['submit'])) { // Handle the form.
 
$con = mysql_connect("localhost","phimualp_defjam9","3490d32");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("phimualp_members", $con);
 
}
 
 
//      if ($id && $fn && $ln && $e && $p && $un && $pw) { // If everything's OK.
 
 
                // Make sure the username is available.
//              $query = "SELECT * FROM members";
        //      $result = @mysql_query ($query);
 
        //      if (mysql_num_rows($result) == 0) { // Available.
error_reporting(0);
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);
                        // Add the user.
                        $query = "INSERT INTO members (ID,Fname,Lname,Email,Phone,Username) VALUES ('$_POST[id]','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[phone]','$_POST[username]')";
                if (!mysql_query($query,$con))
                  {
                  die('Error: ' . mysql_error());
                  }
                echo "Brother you have been added";mysql_close($con)
 
 
?>
 
 
to:
 
 
if (isset($_POST['submit'])) { // Handle the form.
 
  $con = mysql_connect("localhost","phimualp_defjam9","3490d32");
  if (!$con) {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("phimualp_members", $con);
 
  //      if ($id && $fn && $ln && $e && $p && $un && $pw) { // If everything's OK.
 
 
                // Make sure the username is available.
  //              $query = "SELECT * FROM members";
        //      $result = @mysql_query ($query);
 
        //      if (mysql_num_rows($result) == 0) { // Available.
  error_reporting(0);
  $ebits = ini_get('error_reporting');
  error_reporting($ebits ^ E_NOTICE);
  
  // Add the user.
  $query = "INSERT INTO members (ID,Fname,Lname,Email,Phone,Username) VALUES ('{$_POST['id']}','{$_POST['fname']}','{$_POST['lname']}','{$_POST['email']}','{$_POST['phone']}','{$_POST['username']}')";
  if (!mysql_query($query,$con)) {
    die('Error: ' . mysql_error());
  }
  echo "Brother you have been added";
  mysql_close($con);
}
 
?>

Open in new window

0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
ok that fixed the problem i dont see what i did ? with my posted code was it a missing ;
0
 
Terry WoodsIT GuruCommented:
The code was trying to add a user before the form was submitted, so the user value wasn't available. I shifted the ending curly brace for:
if (isset($_POST['submit'])) {
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
oh ok i see

cool thank you very much i will look closer next time

thanks agian
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
great help
0
 
Terry WoodsIT GuruCommented:
No problem.

Just a quick note - you might want to change your MySQL password for the phimualp_defjam9 user, as it's available for the public to see in your code above.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 11
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now