Solved

varable errors

Posted on 2008-10-13
20
224 Views
Last Modified: 2013-12-13
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
Comment
Question by:Chris Jones
  • 11
  • 9
20 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 22707193
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
 
LVL 35

Expert Comment

by:Terry Woods
ID: 22707210
You only need the curly braces when an array variable is specified within a string.
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 22707226
this gave me more errors good thought though
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 22707242
What errors this time?

Also, which line is line 125 in the php script?
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 22707266
                 $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
 
LVL 1

Author Comment

by:Chris Jones
ID: 22707268
sorry that is the line 125
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 22707281
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 22707290
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
 
LVL 35

Expert Comment

by:Terry Woods
ID: 22707326
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 22707360
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 35

Expert Comment

by:Terry Woods
ID: 22707706
$_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
 
LVL 1

Author Comment

by:Chris Jones
ID: 22707715
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
 
LVL 35

Expert Comment

by:Terry Woods
ID: 22707769
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 22707817
ok i made the chanfes and still have the same error
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 22707885
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 22708009
ok that fixed the problem i dont see what i did ? with my posted code was it a missing ;
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 22708044
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
 
LVL 1

Author Comment

by:Chris Jones
ID: 22708057
oh ok i see

cool thank you very much i will look closer next time

thanks agian
0
 
LVL 1

Author Closing Comment

by:Chris Jones
ID: 31505711
great help
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 22708139
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now