Jump to content

[SOLVED] simple insert in table


Recommended Posts

hi,

please kindly check my query

it has an error when executed

<?php 
$sql="INSERT INTO tbl_exceed (address, city, phone)
VALUES
('$_POST['$data[2]']',
'$_POST['$data[3]']','$_POST['$data[4]']')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
mysql_close($con)
?>

 

thanks

 

Link to comment
Share on other sites

<?php

$sql="INSERT INTO tbl_exceed (address, city, phone)

VALUES

('$_POST[\"$data[2]\"]','$_POST[\"$data[3]\"]','$_POST[\"$data[4]\"]')";

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

mysql_close($con)

?>

Link to comment
Share on other sites

<!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>Untitled Document</title>
</head>

<body>
<?php

// Connecting, selecting database
$con = mysql_connect('asecasiasdi', 'root', 'itsysdev')
   or die('Could not connect: ' . mysql_error());
echo '<b>Step 1:</b> Connected successfully! <BR>';

$db = 'aai_dbexceed';
mysql_select_db($db) or die('Could not select database ('.$db.') because of : '.mysql_error());
echo '<b>Step 2:</b> Connected to ('.$db.') successful!<BR>';


?>

<?php 
$sql="INSERT INTO tbl_exceed (address, city, phone)
VALUES
('$_post[\"$data[2]\"]',
'$_post[\"$data[3]\"]',
'$_post[\"$data[4]\"]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
mysql_close($con)
?>
</body>
</html>

Link to comment
Share on other sites

<?php

// Connecting, selecting database
$con = mysql_connect('asecasiasdi', 'root', 'itsysdev')
   or die('Could not connect: ' . mysql_error());
echo '<b>Step 1:</b> Connected successfully! <BR>';

$db = 'aai_dbexceed';
mysql_select_db($db) or die('Could not select database ('.$db.') because of : '.mysql_error());
echo '<b>Step 2:</b> Connected to ('.$db.') successful!<BR>';


?>

<?php 
$sql="INSERT INTO tbl_exceed (address, city, phone)
VALUES
('$_post[\"$data[2]\"]',
'$_post[\"$data[3]\"]',
'$_post[\"$data[4]\"]')";
if (!mysql_query($sql,$con))
 {
 die('Error: ' . mysql_error());
 }
mysql_close($con);
?>

 

It was the last line in the code.

Link to comment
Share on other sites

can anyone knows what is the error in my script?

<?php 
$sql="INSERT INTO tbl_exceed (address, city, phone)
VALUES
('$_post[\"$data[2]\"]',
'$_post[\"$data[3]\"]',
'$_post[\"$data[4]\"]')";
if (!mysql_query($sql,$con))

mysql_close($con);
?>

error message:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\exceed\upload.php on line 26

Link to comment
Share on other sites

<?php 
$sql="INSERT INTO tbl_exceed (address, city, phone)
VALUES
('".$_post['$data[2]']."', '".$_post['$data[3]']".', '".$_post['$data[4]']".')";

if (!mysql_query($sql,$con))
{
mysql_close($con);
}
?>

 

you could try that too. i did not test at all so there might be small errors but i think it should work

Link to comment
Share on other sites

another same errror...  :'(

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\exceed\upload.php on line 26

line 26 is

('".$_post['$data[2]']."', '".$_post['$data[3]']".', '".$_post['$data[4]']".')";

:'(

Link to comment
Share on other sites

it executed but no data were added.  ???

this is the source of the $data[], how to insert the $data[2], $data[3], $data[4]?

from this script to database above?

<?php
$text = $_REQUEST['fname'];
$file = file("$text");
$a = $file;
$state = $_REQUEST['state'];
$newfile = $_REQUEST['txtfile'];
$count = 0;
foreach ($a as $row => $line)

{
//$data[0] = trim(substr($line,  0, 16))."<br />";
//$data[1] = trim(substr($line, 16,125))."<br />";

$data[2] = trim(substr($line,141, 55))."<br />";

$data[3] = trim(substr($line,196, 32))."<br />";

$data[4] = trim(substr($line,228, 14))."<br />";

//$data[5] = trim(substr($line,240,  2))."<br />";
if ($data[2]!= "<br />" or $data[3] != "<br />" or $data[4] != "<br />") $final[] = $data;
$count++;
}

echo "There are " . $count . ": Records Found";
?>

<table width="100%" border="1">
<th bgcolor="#CCCCCC">ADDRESS</th><th bgcolor="#CCCCCC">CITY</th><th bgcolor="#CCCCCC">STATE</th><th bgcolor="#CCCCCC">PHONE</th><th bgcolor="#CCCCCC">ZIP CODE</th>
  <tr>
  <?php for($i = 0;$i <=$count; $i++)
{
$data = $final[$i];?>
    <td><?php echo $data[2];?></td>
    <td><?php echo $data[3];?></td>
    <td><?php echo $state;?></td>
    <td><?php echo $data[4];?></td>
</tr>

<?php } ?> 

please....

Link to comment
Share on other sites

yes i have a form

<!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>UDAC</title>
</head>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<table border="0">
<tr><td><b>Filename:</b></td><td><input name="fname" type="text" /></td>
<br />
<tr><td><b>State:</b> </td><td><input name="state" type="text" /></td>
<tr><td colspan="2"><input name="submit" type="submit" value="load"  /></td>
</table>
</form>

</form>
<form action="upload.php" method="GET" enctype="multipart/form-data">
<input name="submit" type="submit" value="save database" />
</form>
<?php
$text = $_REQUEST['fname'];
$file = file("$text");
$a = $file;
$state = $_REQUEST['state'];
$newfile = $_REQUEST['txtfile'];
$count = 0;
foreach ($a as $row => $line)

{
//$data[0] = trim(substr($line,  0, 16))."<br />";
//$data[1] = trim(substr($line, 16,125))."<br />";

$data[2] = trim(substr($line,141, 55))."<br />";

$data[3] = trim(substr($line,196, 32))."<br />";

$data[4] = trim(substr($line,228, 14))."<br />";

//$data[5] = trim(substr($line,240,  2))."<br />";
if ($data[2]!= "<br />" or $data[3] != "<br />" or $data[4] != "<br />") $final[] = $data;
$count++;
}

echo "There are " . $count . ": Records Found";
?>

<table width="100%" border="1">
<th bgcolor="#CCCCCC">ADDRESS</th><th bgcolor="#CCCCCC">CITY</th><th bgcolor="#CCCCCC">STATE</th><th bgcolor="#CCCCCC">PHONE</th><th bgcolor="#CCCCCC">ZIP CODE</th>
  <tr>
  <?php for($i = 0;$i <=$count; $i++)
{
$data = $final[$i];?>
    <td><?php echo $data[2];?></td>
    <td><?php echo $data[3];?></td>
    <td><?php echo $state;?></td>
    <td><?php echo $data[4];?></td>
</tr>

<?php } ?> 



</table>

</body>
</html>

what im trying to do is i need to insert the data from here to the database.

and the script that will insert the data to db is script above from previous post.

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.