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(arr ay("\t", "\r", "\r\n"), array(' ', "\n", "\n"), $subject);
$subject = preg_replace(ar ray('/[ ]+/', '/([ ]*\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($pa ttern, $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($matche s);
//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.abudan ce' => $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.abudanc e' => $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($sq l)
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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitl ed Document</title>
</head>
<body>
<h1>INSERT PLANET LIST</h1>
<form action="test.ph p" 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]
2 5882
any clue?!?! you can give just a small example :)
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('Sepera tor' , $post);
Then send it to you query with post instead of $_POST['post'];
I like your coding style ;).
~Tyler
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 atmosphere.
Good food.", " (Harry Houdini - 03/01/2004)");
INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada",
" (Herbert Hoover - 03/03/2004)");
INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
|
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 product in the
database with that ID (primary key), just UPDATE the price, and if
there is no product with that ID it should do an INSERT for that item.
Now I've tried it in several ways and I can't seem to get it to execute
|
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 string or NULL.
Becaus i have a if statement:
if ....
cursor.execute(".................insert NULL ..............")
if ....
|
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;
|
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??
| |
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 = $dbh->prepare('select * from foo1');
$sth->execute();
print header;
print start_html('Newgen');
print h1("DBI SAMPLES");
|
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 find syntax to insert values into a mysql database table. I'm able to use the below syntax to insert hard-coded values like 'josie' and 'smith' but can't find working syntax to insert $scalar data from another file (which is really what perl-mysql is...
|
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
original website for the author appears to be gone.
It works really nicely except when it hits special characters. Everything from a sp char forward
just gets lost. It is using mysql_real_escape_string, but that doesn't seem to help with the ...
|
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 explained below.
here i declare 2 arrays of char and int to store the values i want,
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |