Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

need help little help  on  snippet php code

Posted on 2014-04-03
7
Medium Priority
?
512 Views
Last Modified: 2014-04-03
hello i need your help on a little snippet php code
what i have is a textarea called keyword in this textarea the user wild put several or one only keyword, if there are several keyword it will be seperated by a ','
code will determinated if one or several keyword are used if there are several ones,
insert each one into a table (2 rows ;id, name), id is a numbers which autoincrements, and keep the id into a variable cause it will be use in a other part of the script if there is only one keywrd insert it as well in the table and also keep the id used into a variable, lets call it $used_id


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ajoutez une citation</title>

</head>
<body>
<FORM method="post" action="ajout_citations.php">
<TEXTAREA name="keyword" rows=10 COLS=40></TEXTAREA>
<INPUT TYPE="submit" NAME="nom" VALUE=" Envoyer ">
</form></script>

</body></html>

Open in new window




CREATE TABLE IF NOT EXISTS `mots_clefs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Nom` varchar(80) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

Open in new window

explain2.jpg
0
Comment
Question by:jerrrrry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 1900 total points
ID: 39974519
This should work:

<?php
$mysqli = new mysqli(SQLI_SERVER, MYSQLI_USER, MYSQLI_PWD, MYSQLI_DBNAME);
$kw = filter_input(INPUT_POST, 'keyword');
if ($kw)
{
	$kwywords = explode(',' $kw);
	$ids = array();
	foreach ($keywords as $k)
	{
		if (!empty($k)
		{
			$query = "INSERT INTO mots_clefs (Nom) VALUES('$k')";
			if ($result = $mysqli->query($query) or die("Error: " - mysqli_error()))
				array_push($ids, $mysqli->insert_id);
		}
	}
}

Open in new window

0
 

Author Comment

by:jerrrrry
ID: 39974567
Parse error: parse error in C:\wamp\www\citations\test.php on line 6
are u sure of this?

      $kwywords = explode(',' $kw);
thanks
0
 

Author Comment

by:jerrrrry
ID: 39974594
i tried  
  $kwywords = explode(',' ,$kw);

Open in new window

but then i got Parse error: parse error in C:\wamp\www\citations\test.php on line 11

<?php
$mysqli = new mysqli('localhost', 'root', '', 'citations');
$kw = filter_input(INPUT_POST, 'keyword');
if ($kw)
{
	$kwywords = explode(',', $kw);
	$ids = array();
	foreach ($keywords as $k)
	{
		if (!empty($k)
		{
			$query = "INSERT INTO mots_clefs (Nom) VALUES('$k')";
			if ($result = $mysqli->query($query) or die("Error: " - mysqli_error()))
				array_push($ids, $mysqli->insert_id);
		}
	}
}

Open in new window

0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 39974640
If you're running the code you posted here, you could not have gotten a parse error on line 11.  You probably got a parse error because of unbalanced parentheses on line 10:

if (!empty($k)

Change it to this:

if (!empty($k))
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39974641
In case you're new to PHP and want to learn something of the basics, this article will help you get started.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39974658
oops, I was away. I'm sorry for the typo on the parentheses :)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

598 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