473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to insert values into mysql, after parsing a submiting textbox?

Hello!!
how do i insert values into mysql , after parsing a submiting textbox??
I made the arrays, so this should be a basic insertion of them in the db, but something is missing, or in the wrong place...can anyone help me??

i didnt made anything in the VALUES (unless the POST [textbox]), because i bet the error is there (yes, the arrays are missing):

$sql = "INSERT INTO dgplanets ( ID, coords , player name , alliance , name , ground , orbit , metal% , mineral% , food% , energy% , pop ) VALUES ('".$_POST['textbox']."')"; */

here´s the code :
[PHP]<?php

/*
* makes the connection
* and select the database
*/
$conexao = mysql_connect("localhost", "root", "12345")
or die ("Error connecting to db");
$db = mysql_select_db("dg")
or die ("error selecting db");

//here is where i should input the arrays??
$sql = "INSERT INTO dgplanets ( ID, coords , player name , alliance , planet name , ground , orbit , metal% , mineral% , food% , energy% , pop ) VALUES ('".$_POST['textbox']."')"; */




$_POST['data'] = (empty($_POST['data'])) ? '' : $_POST['data'];

$data = array(
'parsed' => FALSE,
'player' => array('name' => ''),
'planet' => array()
);

if (!empty($_POST['data']))
{
$subject = trim($_POST['data']);
$subject = str_replace(array("\t", "\r", "\r\n"), array(' ', "\n", "\n"), $subject);
$subject = preg_replace(array('/[ ]+/', '/([ ]*\n+[ ]*)+/') , array(' ', "\n"), $subject);

//echo '<pre>';
//echo $subject;
//echo '</pre>';

//
// First we find the player name
//
$pattern = '/';
$pattern .= '(.+) [Logout]\n'; // player name
$pattern .= '(?:';
$pattern .= ')*?';
$pattern .= '/iU'; // tirase ?

$matches = array();

if (preg_match($pattern, $subject, $matches))
{
$data['player']['name'] = $matches[1];
}

//
// Now we parse the planet data
//
$pattern = '/';
$pattern .= '(.+) - \((\d+)\) (.+) (.+)\n';
$pattern .= '([\d,]+) \(\+([\d,]+)\) (\d+)% ([\d,]+) \(\+([\d,]+)\) (\d+)% ([\d,]+) \(\+([\d,]+)\) (\d+)% ([\d,]+) \(\+([\d,]+)\) (\d+)%
';
$pattern .= '/i';

$matches = array();
if ($size = preg_match_all($pattern, $subject, $matches))
{
$data['player']['planets'] = $size;

foreach ($matches[0] as $key => $val)
{
$matches[0][$key] = str_replace("\n", ' ', $val);
}


//echo '<pre>';
//print_r($matches);
//echo '</pre>';

for ($i = 0; $i < $size; $i++)
{
$planet = array(
'planet.name' => $matches[1][$i],
'id' => $matches[2][$i],
'ground' => $matches[3][$i],
'orbit' => $matches[4][$i],
'metal.ouput' => str_replace(',', '', $matches[6][$i]),
'metal.stored' => str_replace(',', '', $matches[5][$i]),
'mineral.abudance' => $matches[10][$i],
'mineral.ouput' => str_replace(',', '', $matches[9][$i]),
'mineral.stored' => str_replace(',', '', $matches[8][$i]),
'food.abudance' => $matches[13][$i],
'food.ouput' => str_replace(',', '', $matches[12][$i]),
'food.stored' => str_replace(',', '', $matches[11][$i]),
'energy.abudance' => $matches[16][$i],
'energy.ouput' => str_replace(',', '', $matches[15][$i]),
'energy.stored' => str_replace(',', '', $matches[14][$i]),
'metal.abudance' => $matches[7][$i],
'pop' => str_replace(',', '', $matches[17][$i]),
);
$data['planet'][] = $planet;
}
$data['parsed'] = TRUE;
}
}







/*
* executes the query
*/
$sql = mysql_query($sql)
or die ("there was a mistake");
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<h1>INSERT PLANET LIST</h1>

<form action="test.php" method="post">

<label for="texto"></label>
<textarea name="textbox" id="text" rows="10" cols="30" />
</textarea><br />

<input type="submit" value="insert">

</form>
</body>
</html>[/PHP]
Jul 19 '07 #1
2 5834
any clue?!?! you can give just a small example :)
Jul 20 '07 #2
tscott
22
Hey, Yeah it is on $_POST. Post is defined by the script referring to it so therefore you must redefine the variable so it can be edited.

For Example:
$post = $_POST['whatever'];

Then do

$post = explode('Seperator' , $post);

Then send it to you query with post instead of $_POST['post'];

I like your coding style ;).

~Tyler
Jul 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
6
by: a-ok | last post by:
Hi, My client has a product database od around 20000 items. And it is updated every few days when he gets a catalog from the supplier. It's supposed to work like this: if there already is a...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
10
by: Ricardo | last post by:
How can I make a insert sql string to insert direct in a table(not a dataset) using the textbox.text propert??
4
savanm
by: savanm | last post by:
#! c:/perl/bin/perl.exe use CGI qw(:standard); use DBI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); $dbh = DBI->connect("DBI:mysql:database=perldbi;host=localhost","root",""); $sth =...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
6
by: TheRealDan | last post by:
Hi all. I'm having a problem with a special characters. I have php script that reads from an xml file and writes to a mysql db. It's a script called phptunest that I found on the net, although the...
3
by: Waruna | last post by:
Is there a way to block insert into mysql(5.0) using c api of mysql db.. i.e. say there is a table with 2 columns, one contains char other int then i want to insert 500 records at once,, as i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.