Solved

varable errors

Posted on 2008-10-13
20
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

696 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