SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: inserting data wit alert
-
May 4, 2003, 04:23 #1
- Join Date
- Apr 2003
- Location
- daejeon, South Korea
- Posts
- 2,223
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
inserting data with alert
So far, I've learned about inserting data to a table in mysql.
It was carried out at one page.
this time, I like to try inserting data through two pages and give " alert" to users whether it's going well or not well.
Next is the first page(index.php)
PHP Code:<script language="JavaScript">
function Add(){
Form=document.Add;
if( Form.name.value == "") {
alert("Name, Please");
Form.name.focus();
return;
} else if( Form.phone.value == "") {
alert("Phone number, Please");
Form.phone.focus();
return;
} else {
ans = confirm("Would you save?")
if (ans == true) {
document.Add.submit();
} else {
Form.R2.focus()
return;
}
</script>
<FORM name=Add action="Add.php" method="post">
<p> Type your entries<br>
<input type=text name="name" >
<input type=text name="address" >
<input type=text name="phone" >
<br>
<input type=button name=submission value="sign" onclick="javascript:Add()">
</p>
</FORM>
Anyway, if I finish the first page without error, this might be the second page(Add.php)
PHP Code:<?php
if (isset($_POST['submission']))
{
$V2=$_POST['name'];
$V3=$_POST['address'];
$V4=$_POST['phone'];
$I="INSERT INTO table1(name, address, phone, time) VALUES('$V2', '$V3', '$V4', '".date("Y-m-d-H-m-s" )."')";
$I=@mysql_query($I);
}
?>
I hope you help me with fixed code or suggessions for my intention.Last edited by dotJoon; May 4, 2003 at 05:26.
-
May 4, 2003, 09:50 #2
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I actually think your were using some reserved words for your form name and function names. AS this works fine
PHP Code:<script language="JavaScript">
function addCheck()
{
Form=document.addForm;
if( Form.name.value == "" )
{
alert("Name, Please" );
Form.name.focus();
return;
}
else if( Form.phone.value == "" )
{
alert("Phone number, Please" );
Form.phone.focus();
return;
}
else
{
ans = confirm("Would you save?" );
if (ans == true)
{
Form.submit();
}
else
{
Form.R2.focus();
return;
}
}
}
</script>
<FORM name="addForm" action="formTest.php" method="post">
<p> Type your entries<br>
<input type=text name="name" >
<input type=text name="address" >
<input type=text name="phone" >
<br>
<input type=button name=submission value="sign" onClick="addCheck();">
</p>
</FORM>
-
May 4, 2003, 14:04 #3
- Join Date
- Apr 2003
- Location
- daejeon, South Korea
- Posts
- 2,223
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Inserting data into mysql
Thanks to freddydoesphp .
Your code does work fine.
I still have a problem.
The javascript above I put into my index.php should connected to "php".
The values of the name, address, and phone should be inserted into the table1 of mysql test database.
I put next code into formTest.php for inserting the
data(name, address, phone).
PHP Code:<?$dbconn=mysql_connect("localhost","root","********"); $status=mysql_select_db("test", $dbconn);
if (isset($_POST['submission']))
{
$V2=$_POST['name'];
$V3=$_POST['address'];
$V4=$_POST['phone'];
$I="INSERT INTO table1(name, address, phone, time) VALUES('$V2', '$V3', '$V4', '".date("Y-m-d-H-m-s" )."')";
$I=@mysql_query($I);
}
?>
My trial doesn't work, either.
What's wrong in your think?
Bookmarks