Jump to content

Recommended Posts

In the code below I am getting the error:

 

string(119) "INSERT INTO feeder_keyword (id, keyword, forum_id, group_id, type, status, rotate_urls) VALUES ('','', 2, '', 0, 1, '')" record added

 

I am trying to take 5 keywords that are submitted on the form and insert them into a table.

If there is a better way to do this, please let me know.

 

<?php
define('QUADODO_IN_SYSTEM', true);
require_once('includes/header.php');
$qls->Security->check_auth_page('addkeywords.php');
?>
<html>
<head>
<title>Add Keyword Script Section</title>
</head>
<body>
<div align="center">
<?php
if ($qls->user_info['username'] != '') {
?>

<?php
include 'includes/database_info.php';
// query the database
mysql_connect($database_server_name,$database_username,$database_password) or die("Unable to connect to database");
mysql_select_db("$database_name") or die("Unable to select database $database_name");
// get the twitterid
$useridqry = "SELECT userrid FROM table_users WHERE qls3_Id=".$qls->user_info['id'];
$userid = mysql_query($useridqry) or die("Query failed : " . mysql_error());

$userididrow = mysql_fetch_assoc($userid);


//look up forum_group_id
$groupidqry = "SELECT id FROM feeder_keyword_groups WHERE name=".$useridrow['twitterid'];
$groupid = mysql_query($groupidqry) or die("Query failed : " . mysql_error());

$groupidrow = mysql_fetch_assoc($groupid);

$involv = "INSERT INTO feeder_keyword (id, keyword, forum_id, group_id, type, status, rotate_urls)
VALUES ('','{$keyword}', 2, '{$row['userid']}', 0, 1, '')";

var_dump($involv);
if (!mysql_query($involv))
{
die('Error: ' . mysql_error());
}

echo "$row record added";

mysql_close()
?>

<?php
}
else {
?>

Sorry but you must be <a href="register.php">registered</a> and <a href="login.php">logged in</a> to access this area.

<?php
}
?>
</div>
</body>
</html> 

________________________________

 

Form

 

		<form id="form_102529" class="appnitro"  method="post" action="addkeywords.php">
				<div class="form_description">
		<h2>Add Keywords to Twitter Account</h2>
		<p>This is where you will add keywords to your $account Twitter Account</p>
	</div>						
		<ul >

				<li id="li_1" >
	<label class="description" for="element_1">Keyword 1 </label>

	<div>
		<input id="element_1" name="keyword[]" class="element text medium" type="text" maxlength="255" value=""/> 
	</div><p class="guidelines" id="guide_1"><small>Please Enter a Keyword or Keyword Phrase</small></p> 
	</li>		<li id="li_2" >
	<label class="description" for="element_2">Keyword 2 </label>
	<div>
		<input id="element_2" name="keyword[]" class="element text medium" type="text" maxlength="255" value=""/> 
	</div><p class="guidelines" id="guide_2"><small>Please Enter a Keyword or Keyword Phrase</small></p> 
	</li>		<li id="li_3" >

	<label class="description" for="element_3">Keyword 3 </label>
	<div>
		<input id="element_3" name="keyword[]" class="element text medium" type="text" maxlength="255" value=""/> 
	</div><p class="guidelines" id="guide_3"><small>Please Enter a Keyword or Keyword Phrase</small></p> 
	</li>		<li id="li_4" >
	<label class="description" for="element_4">Keyword 4 </label>
	<div>
		<input id="element_4" name="keyword[]" class="element text medium" type="text" maxlength="255" value=""/> 
	</div><p class="guidelines" id="guide_4"><small>Please Enter a Keyword or Keyword Phrase</small></p> 
	</li>		<li id="li_5" >

	<label class="description" for="element_5">Keyword 5 </label>
	<div>
		<input id="element_5" name="keyword[]" class="element text medium" type="text" maxlength="255" value=""/> 
	</div><p class="guidelines" id="guide_5"><small>Please Enter a Keyword or Keyword Phrase</small></p> 
	</li>

				<li class="buttons">
		    
		    
			<input id="submit" class="button_text" type="submit" name="submit" value="Submit" />
	</li>

Link to comment
https://forums.phpfreaks.com/topic/173966-keyword-form-to-php-file/
Share on other sites

string(119) "INSERT INTO feeder_keyword (id, keyword, forum_id, group_id, type, status, rotate_urls) VALUES ('','', 2, '', 0, 1, '')"

is coming from the

var_dump($involv);

its a variable dump usually used during debugging to see what is in a variable.  You should probably remove that line from the final page.

 

record added

is being echoed by your script at

echo "$row record added";

although I don't see where $row is defined.

 

So, it's not an error message, it is output that you told the script to produce.

Ok, understood about the var_dump.

 

My values are not correct, I know from the database that the values should look like this:

 

VALUES ('','keyword1', 2, 3, 0, 1, '')

 

But I should have a record for keyword1, keyword2, keyword3, keyword4, keyword5.

 

Any idea how I can loop through each of the keyword submissions and enter them along with the rest of the data into the multiple records in the database.

Your form will submit an array of keywords in the super-global $_POST.  You will have to loop through that array using something along these lines:

if (isset($_POST['keyword'])) { // Always check to see if there is something to process
  foreach ($_POST['keyword'] as $ind => $keyw) {
  // $ind is now the index of the keyword; i.e. 0, 1, 2, etc.
  // $keyw is the keyword the user typed (or empty)

  // **** CHECK THE USER'S INPUT TO MAKE SURE IT IS VALID 

  // Insert the data into the table

  } // end foreach
} else {  // end if(isset($_POST))
  // No data submitted, what will I do now?
} // end else 

ok, here is what I have inputted, I will do the isset after I get it working.  I am also having problems with the array $groupidrow, it is showing it as a 0 and I know it is a 3.

 

//Assign each array to a variable

foreach($_POST['keyword'] as $row=>$key)
{
$keyword=$key;
}

// Assigns $keyword as variable

foreach($_POST['keyword'] as $row=>$key)
{
$keyword=mysql_real_escape_string($key);
}

// inserts variables into database
$involv = "INSERT INTO feeder_keyword (id, keyword, forum_id, group_id, type, status, rotate_urls)
VALUES ('','$keyword', 2, $groupidrow, 0, 1, '')";

 

When the code works, I get

Based on your original code, $groupidrow is an array, so the reference should be $groupidrow['id'] (unless you changed something that you're not showing).

 

I don't know why you have the foreach loop in there twice, the first one is completely unnecessary since you overwrite the only value it creates in the second one.

 

To get all of the keywords inserted into the database as separate rows, you will have to move the INSERT code up into the foreach loop.  The way you have it written, $keyword will be the value of your 5th keyword posted and the first four have just been ignored.  If this is the code you are still using, move it inside the loop.

 

$involv = "INSERT INTO feeder_keyword (id, keyword, forum_id, group_id, type, status, rotate_urls)
VALUES ('','{$keyword}', 2, '{$row['userid']}', 0, 1, '')";

if (!mysql_query($involv))
{
die('Error: ' . mysql_error());
}

 

Here is the final code that works.  Now is just have to put in the isset.

 

DavidAM, I worked on this code for 3 days.  Frick, 3 days for 1 page.  But I appreciate all of the help because it would have turned into 30 days without your help.

 

foreach($_POST['keyword'] as $row=>$key)
{
$keyword=mysql_real_escape_string($key);
$involv = "INSERT INTO feeder_keyword (id, keyword, forum_id, group_id, type, status, rotate_urls)
VALUES ('','{$keyword}', 2, '{$groupidrow[id]}', 0, 1, '')";

if (!mysql_query($involv))
{
die('Error: ' . mysql_error());
}
}

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.