Jump to content

[SOLVED] parse error


elite_prodigy

Recommended Posts

I'm getting a

Notice: Undefined variable: mysql_fetch_array in C:\wamp\www\team\php\hire.php on line 30

 

and a

 

Fatal error: Function name must be a string in C:\wamp\www\team\php\hire.php on line 30

 

This is the file that is rendering the error:

 

hire.php

<?php

include 'config.php';
include 'functions.php';

mysql_select_db('exembar_site');

if( ($_POST['username'] != "") & ($_POST['password'] != "") & ($_POST['location'] != "") & ($_POST['realname'] != "") & ($_POST['email'] != "")) {

$username = $_POST['username'];
$password = $_POST['password'];
$location = $_POST['location'];
$realname = $_POST['realname'];
$email = $_POST['email'];


//sanitize everything
$username = sanitize($username);
$password = sanitize($password);
$location = sanitize($location);
$realname = sanitize($realname);
$email = sanitize($email);

$sql = "INSERT INTO `staff` VALUES('','{$username}','{$password}')";
mysql_query($sql) or die(mysql_error());

$sql = "SELECT * FROM `staff` WHERE `username`='{$username}' AND `password`='{$password}'";
echo $sql;
$res = mysql_query($sql) or die(mysql_error());
$info = $mysql_fetch_array($res);
//$id = info['id'];

$sql = "INSERT INTO `staff_info` VALUES('','{$location}','{$realname}','{$email}','{$id}')";

//header("location:{$root}");

}
else {

echo "There can be no empty fields!<br>If something is unknown, type 'UNKNOWN'.";

}

?>

 

I feel as though I must iterate how horribly error-prone I am with PHP, and without you guys, I would never get anything done, ever.

 

So thanks. I'll be trying to make a donation to phpFreaks asap, when I am more financially stable. :)

 

-David

 

 

Link to comment
Share on other sites

<?php

include 'config.php';
include 'functions.php';

mysql_select_db('exembar_site');

if( ($_POST['username'] != "") & ($_POST['password'] != "") & ($_POST['location'] != "") & ($_POST['realname'] != "") & ($_POST['email'] != "")) {

$username = $_POST['username'];
$password = $_POST['password'];
$location = $_POST['location'];
$realname = $_POST['realname'];
$email = $_POST['email'];


//sanitize everything
$username = sanitize($username);
$password = sanitize($password);
$location = sanitize($location);
$realname = sanitize($realname);
$email = sanitize($email);

$sql = "INSERT INTO `staff` VALUES('','{$username}','{$password}')";
mysql_query($sql) or die(mysql_error());

$sql = "SELECT * FROM `staff` WHERE `username`='{$username}' AND `password`='{$password}'";
echo $sql;
$res = mysql_query($sql) or die(mysql_error());
$info = mysql_fetch_array($res);
//$id = info['id'];

$sql = "INSERT INTO `staff_info` VALUES('','{$location}','{$realname}','{$email}','{$id}')";

//header("location:{$root}");

}
else {

echo "There can be no empty fields!<br>If something is unknown, type 'UNKNOWN'.";

}

?>

 

Link to comment
Share on other sites

What line is 31?  This one?

 

$sql = "INSERT INTO `staff_info` VALUES('','{$location}','{$realname}','{$email}','{$id}')";

 

You're not specifying the fields you're inserting into, for example:

 

$sql = "INSERT INTO `staff_info` (field1, location, realname, email, id) VALUES('','{$location}','{$realname}','{$email}','{$id}')";

Link to comment
Share on other sites

What line is 31?  This one?

 

$sql = "INSERT INTO `staff_info` VALUES('','{$location}','{$realname}','{$email}','{$id}')";

 

You're not specifying the fields you're inserting into, for example:

 

$sql = "INSERT INTO `staff_info` (field1, location, realname, email, id) VALUES('','{$location}','{$realname}','{$email}','{$id}')";

 

As long as he has all the fields in the VALUES, he does not need to specify them.

 

Corrected version:

<?php

include 'config.php';
include 'functions.php';

mysql_select_db('exembar_site');

// added && instead of &
if( ($_POST['username'] != "") && ($_POST['password'] != "") && ($_POST['location'] != "") && ($_POST['realname'] != "") && ($_POST['email'] != "")) {
   
   $username = $_POST['username'];
   $password = $_POST['password'];
   $location = $_POST['location'];
   $realname = $_POST['realname'];
   $email = $_POST['email'];
   

   //sanitize everything
   $username = sanitize($username);
   $password = sanitize($password);
   $location = sanitize($location);
   $realname = sanitize($realname);
   $email = sanitize($email);
   
   $sql = "INSERT INTO `staff` VALUES('','$username','$password')"; // removed { and }
   mysql_query($sql) or die(mysql_error());
   
   $sql = "SELECT * FROM `staff` WHERE `username`='$username' AND `password`='$password'"; // removed { and }
   echo $sql;
   $res = mysql_query($sql) or die(mysql_error());
   $info = mysql_fetch_array($res); // removed $ here.
   //$id = info['id'];
   
   $sql = "INSERT INTO `staff_info` VALUES('','$location','$realname','$email','$id')"; // removed the { and } from here { and } are only needed for ' not "

   //header("location:{$root}");

}
else {

   echo "There can be no empty fields!<br>If something is unknown, type 'UNKNOWN'.";
   
}

?>

 

Give that a try and see if you still get the parse error.

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.