Warning: Missing argument 2 for addProfile() - php

I know there are already quite a few articles on SE about "Warning: Missing argument 2 for" questions, although I couldn't really seem to find an answer (even after looking over all of the other questions several times).
First Error Set: http://i.stack.imgur.com/HTySO.png
Second Error Set: http://i.stack.imgur.com/wDwxm.png
(I tried posting as SE images, but since I'm new it wouldn't let me)
Those are the two errors I'm currently getting 20 times (I have 20 different fields for the database, it's a "profile" section).
I've spent the better half of two hours trying to figure out why it's not working but I'm clueless.
addProfile.php :
<?php
include('../includes/functions.php');
if(isset($_POST['submit'])) {
if(isset($_POST['profile_name'])) {
addProfile($_POST['profile_name']);
} else {
echo "Please Enter A Profile Name!";
include('manage_settings.php');
}
if(isset($_POST['profile_description'])) {
addProfile($_POST['profile_description']);
} else {
echo "Please Enter A Profile Description!";
include('manage_settings.php');
}
if(isset($_POST['first_name'])) {
addProfile($_POST['first_name']);
}
if(isset($_POST['last_name'])) {
addProfile($_POST['last_name']);
}
if(isset($_POST['company'])) {
addProfile($_POST['company']);
}
if(isset($_POST['office_phone'])) {
addProfile($_POST['office_phone']);
}
if(isset($_POST['cell_phone'])) {
addProfile($_POST['cell_phone']);
}
if(isset($_POST['fax_num'])) {
addProfile($_POST['fax_num']);
}
if(isset($_POST['email_addr'])) {
addProfile($_POST['email_addr']);
}
if(isset($_POST['website'])) {
addProfile($_POST['website']);
}
if(isset($_POST['motto'])) {
addProfile($_POST['motto']);
}
if(isset($_POST['street_addr'])) {
addProfile($_POST['street_addr']);
}
if(isset($_POST['city'])) {
addProfile($_POST['city']);
}
if(isset($_POST['state'])) {
addProfile($_POST['state']);
}
if(isset($_POST['zip'])) {
addProfile($_POST['zip']);
}
if(isset($_POST['country'])) {
addProfile($_POST['country']);
}
if(isset($_POST['facebook_url'])) {
addProfile($_POST['facebook_url']);
}
if(isset($_POST['places_url'])) {
addProfile($_POST['places_url']);
}
if(isset($_POST['twitter_url'])) {
addProfile($_POST['twitter_url']);
}
if(isset($_POST['linkedin_url'])) {
addProfile($_POST['linkedin_url']);
}
} else {
header("Location: manage_settings.php");
}
?>
functions.php :
<?php
include('connect.php');
function getProfiles() {
$query = mysql_query("SELECT * FROM global_profiles") or die(mysql_error());
if(mysql_num_rows($query) == 0) {
echo "<center><h3><b><u>No Profiles Currently Available</u></b></h3></center>";
} else {
while($profile = mysql_fetch_assoc($query)) {
echo "<tr><td><input type=\"checkbox\" /></td><td>" . $profile['profile_name'] . "</td><td>Coming Soon</td><td>" . $profile['profile_description'] . "</td><td>" . $profile['pid'] . "</td><td><img src=\"images/pencil.png\" alt=\"Edit\" /> <img src=\"images/cross.png\" alt=\"Delete\" /> <img src=\"images/hammer_screwdriver.png\" alt=\"Duplicate\" /></td></tr>";
}
}
}
function deleteProfile($pid) {
$pid = (int) $pid;
mysql_query("DELETE FROM global_profiles WHERE pid = '$pid'") or die(mysql_error());
header("Location: manage_settings.php");
}
function addProfile($pid, $profile_name, $profile_description, $first_name, $last_name, $company, $office_phone, $cell_phone, $fax_num, $email_addr, $website, $motto, $city, $state, $zip, $country, $facebook_url, $places_url, $twitter_url, $linkedin_url) {
$query = mysql_query("INSERT INTO global_profiles VALUES(null,'$profile_name','$profile_description','$first_name','$last_name','$company','$office_phone','$cell_phone','$fax_num','$email_addr','$website','$motto','$city','$state','$zip','$country','$facebook_url','$places_url','$twitter_url','$linkedin_url')") or die(mysql_error());
}
?>
What I'm trying to do is basically "save" new information to my database. I've been able to manually add it into the database via phpMyAdmin, then display the information inside my admin area.
Any assistance is much appreciated!

Modify your addProfile() to:
function addProfile($post) {
// Here check wether you have certain post array key set and add it to query
}
and use it as :
if(isset($_POST['profile_name'])) {
addProfile($_POST);
}

Related

Login form db check error

Hi i need help to make a login check thourght db working anyone can say to me where is the error?
This is the code
if (!empty($_POST['user']) && !empty($_POST['password']))
{
$user=stripslashes(trim($_POST['user']));
$password=stripslashes(trim($_POST['password']));
mysql_connect("localhost","root","");
mysql_select_db("project");
$check=mysql_query("SELECT * FROM utenti WHERE nome='$user' AND password='$password'");
if(mysql_num_rows($check)!0)
{
$details=mysql_fetch_array($check);
$_SESSION['display_name']=$details[0];
$_SESSION['username']=$details[1];
$_SESSION['password']=$details[2];
print "Login succesful. <p> Level access: " . $details["type"] ;
}
else
{
print "Error";
}
}
else
{
print "Not all fields are compiled" ;
}
if ($details["type"] == "admin" )
{
$admn = 1;
}
else
{
$admn = 0;
}
I've no clue why is not working. Thanks in advance.
Change this:
if(mysql_num_rows($check)!0)
To This:
if(mysql_num_rows($check) != 0)

why are some Email Ids Getting accepted and some not PHP

I have written This PHP code to for a login and a register page but, I don't know how it doesn't seem logical but it's not accepting some email it's while its accepting others. I don't know how is this even possible. I don't think is the apache server that I'm using because It wouldn't have accepted the other mails it accepted, I also tried restarting the server, Trying a different browser, I tried all that is to try. Please help.
<?php
session_start();
require_once "connect.php"
$con=#new mysqli($hn,$un,$pw,$db);
if($con->connect_error) die("Failed to connect to the database");
if (isset($_POST['register']))
{
$nam=$_POST['name'];
$sur=$_POST['sur'];
$email=$_POST['email'];
$pass=$_POST['pass'];
$cpass=$_POST['cpass'];
if ($nam!="" && $sur!="" && $email!="" && $pass!="" && $cpass!="")
{
if ($pass==$cpass)
{
$userinfo=sanitise($nam,$sur,$email,$pass);
if (validate($userinfo[0],$userinfo[1],$userinfo[2],$userinfo[3]))
{
if(dataentry($userinfo[0],$userinfo[1],$userinfo[2],$userinfo[3]))
{
echo "Account Create Successfully";
}
else
{
echo "Failed to Create the account, Please try again After Some Time";
}
}
}
else
{
echo "The Entered Password do not Match";
}
}
else
{
echo "Please fill all the fields";
}
}
if (isset($_POST['login']))
{
$id=$_POST['email'];
$pin=$_POST['lpass'];
$id=ucfirst(strtolower(stripslashes(strip_tags(htmlentities($id)))));
$pin=stripcslashes(strip_tags(htmlentities($pin)));
$pin=hash('ripemd128', $pin);
if (isuser($id))
{
if (verify($id,$pin))
{
$_SESSION['email']=$id;
header("Location:homepage.php");
}
else
{
echo "The Password And Email Do not Match";
}
}
else
{
echo "The Email Id is Not Registered";
}
}
function verify($email,$pass)
{
global $con;
$query="SELECT * FROM users WHERE email='$email' AND password='$pass'";
$result=$con->query($query);
$rows=$result->num_rows;
if ($rows==1)
{
return 1;
}
else
{
return 0;
}
}
function isuser($email)
{
global $con;
$query="SELECT * FROM users WHERE Email='$email'";
$result=$con->query($query);
$rows=$result->num_rows;
if ($rows==1)
{
return 1;
}
else
{
return 0;
}
}
function sanitise($name,$surname,$email,$password)
{
$name=ucfirst(strtolower(stripslashes(strip_tags(htmlentities($name)))));
$surname=ucfirst(strtolower(stripslashes(strip_tags(htmlentities($surname)))));
$email=ucfirst(strtolower(stripslashes(strip_tags(htmlentities($email)))));
$password=stripcslashes(strip_tags(htmlentities($password)));
$password=hash('ripemd128',$password);
return array($name,$surname,$email,$password);
}
function validate($name,$surname,$email,$password)
{
global $con;
$query="SELECT * FROM users WHERE email='$email'";
$result=$con->query($query);
$rows=$result->num_rows;
if ($rows==0)
{
return 1;
}
else
{
echo "Email Address is already in use";
}
}
function dataentry($name,$surname,$email,$password)
{
global $con;
$query="INSERT INTO users (Name,Surname,Email,Password) VALUES ('$name','$surname','$email','$password')";
$result=$con->query($query);
if ($result)
{
return 1;
}
else
{
return 0;
}
}
?>
Hey there is no Reason for some email Ids to get accepted and some not, try restarting your apache server that might help.
Also read more about SQL Injection, I know you must be working locally and not deploying this, but still its good to know about it.Peace

PHP Form IF Issues

Ok, so I have this in the top part of my code
require(__DIR__ . "/lib/db.php");
if (!empty($_POST["action"])) {
if ($_POST["action"] == "addCat") {
echo "Please wait...";
$sql1 = "INSERT INTO categories (name) VALUES ('".$_POST["name"]."')";
if (mysql_query($sql1)) {
$success = true;
}
if (!isset($success)) {
echo "Error Occured Adding Category!";
} else {
echo "Category added!";
}
}
if ($_POST["action"] == "delCat") {
echo "Please wait...";
$catNames = $_POST['catName'];
if(empty($catNames)) {
return;
} else {
$N = count($catNames);
for($i=0; $i < $N; $i++) {
$sql = "DELETE FROM categories WHERE id='$catNames[$i]'";
if (mysql_query($sql)) {
$success = true;
}
$sql2 = "SELECT * FROM catrel WHERE categoryID = '$catNames[$i]'";
if (mysql_query($sql2)) {
mysql_query("DELETE FROM catrel WHERE categoryID = '$catNames[$i]'");
}
}
}
if (!isset($success)) {
echo "Could not delete category! Error Occured!";
} else {
echo "Category deleted!";
}
}
}
I have a 2 different forms in the same page, with hidden values that will push addCat or delCat. For some reason it seems like the SQL is not getting parsed, however it is not displaying any errors. Any help would be highly appreciated. I can post the entire page if needed.

User levels with PHP

What I'm trying to do is make it so that when a specific user level is set in my Database it shows up specific text. Here is my code.
$userget = mysql_query("SELECT * FROM `usertable` WHERE `username`='".$_SESSION['user']."'");
$user = mysql_fetch_array($userget);
function getUserlevel() {
if($user['userlevel'] == '1') { echo "Regular User"; }
elseif($user['userlevel'] == '2') { echo "Moderator"; }
elseif($user['userlevel'] == '3') { echo "Administrator"; }
else { echo "Undefined"; }
}
I know the function is working, because the Echo of Undefined works, which I set up as a test but the others are not working despite my user level being set to 3 and only echoing Undefined. A session is also set for when the user is logged in.
This is when the function is called.
<div class="userData">Welcome Back, <?php echo $_SESSION['user']; ?><hr /><?php
getUserlevel(); ?></div>
Ok, I'm going to take a stab at:
getUserlevel($user['userlevel']);
function getUserlevel($usrlvl) {
if($usrlvl == '1') { echo "Regular User"; }
elseif($usrlvl == '2') { echo "Moderator"; }
elseif($usrlvl == '3') { echo "Administrator"; }
else { echo "Undefined"; }
}
I just included query into function, and its working :P
<?php
function getUserlevel() {
$userget = mysql_query("SELECT * FROM `users` WHERE `username`='".$_SESSION['username']."'");
$user = mysql_fetch_array($userget);
if($user['user_level'] == 1) { echo "Regular User"; }
elseif($user['user_level'] == 2) { echo "Moderator"; }
elseif($user['user_level'] == 3) { echo "Administrator"; }
else { echo "Error"; }
}
?>
You can not access $user as $user[userlevel] because mysql_fetch_array return an array. Does username is unique if not use an id instead of using username. So you should write the function as below
function getUserlevel()
{
foreach($user as $u)
{
if($u['userlevel'] == 1){echo "Regular User";}
else if($u['userlevel'] == 2){echo "Moderator";}
else if($u['userlevel'] == 3){echo "Administrator";}
else{echo "Undefined";}
}
}
If it does not work make sure you have write a vaild mysql query

Returning specific values dependent on the email entered

I have a function that tells me if an email is in or not in the database. What I would like to know if it is found how could I also pass the variables like id,name etc along with it for the particular email that has been found in the DB.
function candidateInsert()
{
if($this->checkEmail($email))
{
echo 'found in db';
echo $email['id'];
}else{
echo 'error';
}
}
function checkEmail($email)
{
$email = $POST('Email');
if($email)
{
$candemail ="SELECT * FROM {table} WHERE email=?",$email"";
if(isset($candemail['email']))
{
return TRUE;
} else {
return FALSE;
}
}
}
if you want to echo something of the mail, you need to return the values from CheckMail() function, as like this:
function candidateInsert() {
$newmail = $this->checkEmail($email);
if($newmail != FALSE ) {
echo 'found in db';
echo $newmail['id'];
}else{
echo 'error';
}
}
function checkEmail($email)
{
$email = $POST('Email');
if($email)
{
$candemail ="SELECT * FROM {table} WHERE email=?",$email"";
$result = result($candemail ) // Don't know which sql functions u use
if(isset($result['email'])) {
return $result;
} else {
return FALSE;
}
}
}
I will assume that aside from boolean value, you also want to return the id and name. In this case, pass parameters by reference:
function candidateInsert()
{
$id = "";
$name;
if($this->checkEmail($email, $id, $name))
{
echo 'found in db';
echo $id;
echo $name;
}else{
echo 'error';
}
}
function checkEmail($email, &$id, &$name)
{
$email = $POST('Email');
if($email)
{
$candemail ="SELECT * FROM {table} WHERE email=?",$email"";
if(isset($candemail['email']))
{
$id = $candemail['id'];
$name = $candemail['name'];
return TRUE;
} else {
return FALSE;
}
}
}
By adding & at the beginning of the parameter, you can edit the content of the variables you pass as argument.

Categories