Jump to content

While in a var?


unidox

Recommended Posts

Well I have an array that I turn into variables, and I need to insert it into sql. I was thinking of using a count function to count the array, but the problem is how would I insert it into the sql, I was thinking using a counter var, and a while statement. Would that work?

Link to comment
Share on other sites

Here:

 

function add($array, $link, $log) {
	foreach ($array as $v) {
		if (preg_match("/password/i", $v)) {
			eval("$" . $v . " = " . pass($_POST[$v]) . ";");
			if ($password == "") {
				header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_4");
				exit();
			} elseif ($password_check == "") {
				header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_5");
				exit();
			} else {
				if ($password != $password_check) {
					header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_6");
					exit();
				}
			}
		} elseif (preg_match("/url/i", $v)) {
			eval("$" . $v . " = " . url($_POST[$v]) . ";");
			if ($url == "") {
				header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_7");
				exit();
			}
		} elseif (preg_match("/level/i", $v)) {
			if ($this->check == true) {
				eval("$" . $v . " = " . escape_data($_POST[$v]) . ";");
				if ($level == 1) {
					$level = $this->chklvl("Users");
				}
				if (!is_numeric($level)) {
					header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_8");
					exit();
				} elseif ($level == "") {
					$level = $this->chklvl("Users");
				}
				$q = mysql_query("SELECT * FROM `pcp_groups` WHERE `level` = '$level'") or die(mysql_error());
		        $r = mysql_fetch_array($q);
		        $group = $r['name'];
			} else {
				$level = $this->chklvl("Users");
			}
		} elseif (preg_match("/active/i", $v)) {
			eval("$" . $v . " = " . escape_data($_POST[$v]) . ";");
			if (!is_numeric($active)) {
				header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_9");
				exit();
			} elseif ($active == "") {
				$active = 2;
			}
		} else {
			eval("$" . $v . " = " . escape_data($_POST[$v]) . ";");
			if (preg_match("/_required/i", $v)) {
				if ("$" . $v . "" == "") {
					header("Location: index.php?p=error&h=" . $link . "&e=" . $link . "_10&field=" . $v . "");
					exit();
				}
			}
		}
	}

	if (($username != "") || ($email != "")) {
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE `username` = '$username' || `email` = '$email'");
		$r = mysql_fetch_array($q);

		if (($r['username'] == $username_required)) { // If there is already a member in the db
		    header("Location: index.php?p=users&s=add_user&e=6"); // Redirects to error "Sorry, that username/email is already in use, please use forget password to retrieve your account.".
		    exit();
		} elseif (($r['email'] == $email_required)) { // If there is already a member in the db
		    header("Location: index.php?p=users&s=add_user&e=7"); // Redirects to error "Sorry, that username/email is already in use, please use forget password to retrieve your account.".
		}
	}

	$this->create_log("Added " . $log . ": \"" . $username . "\"", $user_name);

}

 

I just need to insert it into sql now. Which I am trying to figure out.

Link to comment
Share on other sites

Notice how I set each string in the array into a variable. I am trying to insert each data into sql. Like:

 

mysql_query("INSERT INTO `" . $this->table . "` ($var) VALUES ('$var')") or die (mysql_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.