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
https://forums.phpfreaks.com/topic/136521-solved-parse-error/
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
https://forums.phpfreaks.com/topic/136521-solved-parse-error/#findComment-712672
Share on other sites

Don't see anything near line 31, but all these &'s need to be &&.

 

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

 

You should really be using isset or empty instead however.

Link to comment
https://forums.phpfreaks.com/topic/136521-solved-parse-error/#findComment-712680
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
https://forums.phpfreaks.com/topic/136521-solved-parse-error/#findComment-712691
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
https://forums.phpfreaks.com/topic/136521-solved-parse-error/#findComment-712692
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.