473,387 Members | 1,476 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,387 software developers and data experts.

inserting values in a database using php and html

please help me..

kindly see if what's wrong with my code below.. im trying to insert values in a table on my database but the query returned as failed.
[php]
html code -my input page

<form action="addcustomers.php" method="$_POST">
Customer ID: <input type="text" name="CustID"><br>
Name: <input type="text" name="Name"><br>
Address: <input type="text" name="Address"><br>
Credit Limit:<input type="text" name="CreditLimit"><br>
<input type="submit" value="ADD">

php code-to process my html code
<?php

$id = $_POST['CustID'];
$name=$_POST['Name'];
$address=$_POST['Address'];
$creditlimit=$_POST['CreditLimit'];
$con=mysql_connect('localhost','root','my_password ');
$db=mysql_select_db('hsrc',$con);
$query_string="INSERT INTO customer VALUES ($id,'$name','$address',$creditlimit)";
echo $query_string;
$query=mysql_query($query_string);
if($query)
{
echo"customers record successfully added";
}else
{
echo"adding of customers record failed";
}
?>
php code -use to display added values in the table

$con = mysql_connect('localhost','root','my_password');
$db = mysql_select_db('hsrc',$con);
$str = "SELECT * FROM customer";
$query = mysql_query($str);
echo("<table border=1>");
echo("<tr><td>Customer ID</td><td>Name</td><td>Address</td><td>CreditLimit</td></tr>");
while($val=mysql_fetch_array($query))
{
echo "<tr><td>" . $val['CustID'] . "</td><td>" . $val['Name'] . "</td><td>" . $val['Address']."</td><td>" . $val['CreditLimit'] . "</td><td>" . $val['DepotID'] . "</td></tr>";

}
echo "<table>";
?>.[/php]
Mar 9 '07 #1
3 1953
r035198x
13,262 8TB
please help me..

kindly see if what's wrong with my code below.. im trying to insert values in a table on my database but the query returned as failed.

html code -my input page

<form action="addcustomers.php" method="$_POST">

Customer ID: <input type="text" name="CustID"><br>
Name: <input type="text" name="Name"><br>
Address: <input type="text" name="Address"><br>
Credit Limit:<input type="text" name="CreditLimit"><br>

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

php code-to process my html code

<?php

$id = $_POST['CustID'];
$name=$_POST['Name'];
$address=$_POST['Address'];
$creditlimit=$_POST['CreditLimit'];

$con=mysql_connect('localhost','root','my_password ');
$db=mysql_select_db('hsrc',$con);
$query_string="INSERT INTO customer VALUES ($id,'$name','$address',$creditlimit)";
echo $query_string;
$query=mysql_query($query_string);

if($query)
{
echo"customers record successfully added";


}else
{
echo"adding of customers record failed";
}

?>
php code -use to display added values in the table

$con = mysql_connect('localhost','root','my_password');
$db = mysql_select_db('hsrc',$con);
$str = "SELECT * FROM customer";
$query = mysql_query($str);

echo("<table border=1>");
echo("<tr><td>Customer ID</td><td>Name</td><td>Address</td><td>CreditLimit</td></tr>");


while($val=mysql_fetch_array($query))
{
echo "<tr><td>" . $val['CustID'] . "</td><td>" . $val['Name'] . "</td><td>" . $val['Address']."</td><td>" . $val['CreditLimit'] . "</td><td>" . $val['DepotID'] . "</td></tr>";

}

echo "<table>";


?>
Moved to PHP forum.
Please make use of the code tags when posting code and make sure you are posting in the correct forum.
Mar 9 '07 #2
savanm
85
Insert into html table
<?php
$sql = "select * from login";
$ress = mysql_query($sql);
//$res = mysql_fetch_assoc($ress);
echo ("<table name='data' height='21' width='24' cellpadding='3' cellspacing='3' align='center' bordercolor='black' border='1' bgcolor='#45509C'>");
echo "<tr>";
echo"<td>Checkbox</td>";
echo "<td>UserName:</td>";
echo "<td>Password</td>";
echo "</tr>";
while($row = mysql_fetch_array($ress)){
echo "<tr>";
echo "<td><input type='checkbox' name='chkbox' align='center'/></td>";
echo ("<td >$row[user]</td>");
echo ("<td >$row[password]</td>");
echo "</tr>";
}
echo "</table>";
?> Insert into databse
For example the button is like this
-----------------------------------------------
<td><input type="submit" name="btnIns" value="Insert"></td>
For example the textbox is like this is like this
-----------------------------------------------
<input type="password" name="userpass" align="center" maxlength="14" size="12"></td>
<input type="text" name="usertxt" align="center" maxlength="14" size="12"></td>
if(isset($_POST["btnIns"])
{
$usertxt = $_POST["$usertxt"];
$userpass = $_POST["$userpass"];
$sql="insert into tablenamae values('$usertxt','$userpass');
mysql_query($sql);
}
savanm: enclose your code within php or code tags!! - moderator
Mar 9 '07 #3
ronverdonk
4,258 Expert 4TB
Extract the exact error message from mysql, then you'll know what the problem is. Just change the insert command into
Expand|Select|Wrap|Line Numbers
  1. $query=mysql_query($query_string) 
  2.   or die("INSERT error: ".mysql_error());
Ronald :cool:
Mar 9 '07 #4

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

Similar topics

14
by: Miranda | last post by:
Hi, I have a ASP/vbscript program that generates random passwords. The problem is I need to insert those passwords into an Access database of 327 clients. I have the random password program...
1
by: pmud | last post by:
I have an ASP.NET web application using C# code. I am trying to insert values from a web form into an SQL database. I am using SQL COMMAND object for this. I need to know HOW TO INSERT THE RADIO...
6
by: Raqueeb Hassan | last post by:
Hello There! Have you guys tried inserting variables in mySQL tables? Do I have to use 'quote' as we had been doing to insert strings? mysql> INSERT INTO occurrence (word_id,page_id) VALUES...
1
by: Scott Chapman | last post by:
I am working with Python (psycopg). I have HTML with embedded Python that I'm inserting into a database and it could contain any character. Single quotes, at least, must be escaped (to two...
2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
2
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First...
25
by: bseakgano | last post by:
I have developed a intranet . Using HTML , SQL and ASP . I have created a table with SQL is just fine . And design a form is just looks fine to me . But when I try to insert Data into the SQL I just...
5
by: bob44 | last post by:
Hi, I recently created a mysql database using phpmyadmin. I then proceeded to make a form to insert data into the database, but the problem is that the form is only able to insert one record, and...
6
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.