Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

varable errors

Posted on 2008-10-13
20
Medium Priority
?
238 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

972 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