Jump to content

cannot insert row in table


Pawan_Agarwal
Go to solution Solved by Pawan_Agarwal,

Recommended Posts

I can connect to database but when I try to insert row using submit button in PHP, it does run without any error and does nothing, pls help me out.......

 

if($_POST[query]!="")
{
$n1=$_POST['fname'];
$n2=$_POST['number'];
$n3=$_POST['email'].$_POST['domain1'].$_POST['domain2'];
$n4=$_POST['category'];
$n5=$_POST['query'];
$year=Date("Y");
$month=Date("m");
$day=Date("d");
$now=$year."-".$month."-".$day;
 
$sql=("INSERT INTO table_name (Name,Number,Email,Category,Query,Date) VALUES('$n1','$n2','$n3','$n4','$n5','$now')") or die(mysql_error());  
 
if (!mysql_query($sql,$connect))
  {
  die('Error: ' . mysql_error($connect));
  }else{echo $n1." ".$n2." ".$n3." ".$n4." ".$n5." ".$now;}
echo "1 record added";

Link to comment
Share on other sites

I am trying to insert the data from text box in my form to database, the whole code is running without any error.

 

The row cannot be inserted after execution of

 

 

$sql=("INSERT INTO table_name (Name,Number,Email,Category,Query,Date) VALUES('$n1','$n2','$n3','$n4','$n5','$now')") or die(mysql_error());  
 
if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error($connect));
  }
echo "1 record added";

Link to comment
Share on other sites

Remove the or die() stuff after your query string. That is something you would use on the line where you run the query using mysql_query, not when you define the query text. Since you are checking mysql_query with an if statement though, you do not need it at all.

Link to comment
Share on other sites

<?php

date_default_timezone_set('Asia/Kolkata');

$username = "**********";

$password = "**********";

$hostname = "**********";

$database = "**********";

$connect = mysql_connect($hostname, $username, $password, $database) or die("Could not connect: ".mysql_error());

 

if ($connect) {

echo ("Connection is success <br>");////it executes

} else {

echo ("Connection is failed");

}

 

$selected = mysql_select_db($database,$connect) or die("Could not select database");

if ($selected) {

echo ("Connection is success to database<br><br>");////it executes

} else {

echo ("Connection is failed");

}

 

if($_POST['query']!="")

{

$n1=$_POST['fname'];

$n2=$_POST['number'];

$n3=$_POST['email'].$_POST['domain1'].$_POST['domain2'];

$n4=$_POST['category'];

$n5=$_POST['query'];

$year=Date("Y");

$month=Date("m");

$day=Date("d");

$now=$year."-".$month."-".$day;

echo $n1." ".$n2." ".$n3." ".$n4." ".$n5." ".$now; ///this is not working

 

$sql=("INSERT INTO table_name (Name,Number,Email,Category,Query,Date) VALUES('$n1','$n2','$n3','$n4','$n5','$now')") ///this is not working

 

if (!mysql_query($sql))

  {

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

  }

echo "1 record added";

}

mysql_close($connect);

 

?>

 

 

 

I am trying this code and it is executing, but no row inserted after clicking on submit button...........thanks for helping me out......
Link to comment
Share on other sites

CODE:
$n1=$_POST['fname'];
$n2=$_POST['number'];
$n3=$_POST['email'].$_POST['domain1'].$_POST['domain2'];
 
Error:

Notice: Undefined index: fname in C:\xampp\htdocs\enquiry.php 

Notice: Undefined index: number in C:\xampp\htdocs\enquiry.php 

Notice: Undefined index: email in C:\xampp\htdocs\enquiry.php 

Notice: Undefined index: domain1 in C:\xampp\htdocs\enquiry.php 

Notice: Undefined index: domain2 in C:\xampp\htdocs\enquiry.php 

 

I am facing this error, what can be done here ???

Link to comment
Share on other sites

<form action="enquiry.php" name="myform" method='post'> 

Name <input type="text" size="65" name="fname">

Cell Number <input type="text" size="65" name="number">

Email Address<input type="text" size="32" name="email">

 

<select style="align:center" name="domain1" size="1" style="width:50px">

 <option>@gmail</option>

 <option>@yahoo</option>

 <option>@hotmail</option>

 <option>@aol</option>

 <option>@inbox</option>

 <option>@fastmail</option>

 <option>@mail</option>

 <option>@lycos</option>

 <option>@care2</option>

 <option>@zenbe</option>

 <option>@zoho</option>

 <option>@aim</option>

 <option>@icloud</option>

</select>

 

<select align="center" name="domain2" size="1" style="width:80px">

 <option>.in</option>

 <option>.com</option>

 <option>.co.in</option>

</select>

 

Should I write $_REQUEST or $_POST???

 


CODE:

$n1=$_POST['fname'];

$n2=$_POST['number'];

$n3=$_POST['email'].$_POST['domain1'].$_POST['domain2'];

 

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.