jr41
12-03-2008, 10:42 AM
hi,
i have a simple php form, to enter names, email, etc. When submitted it will insert data into DB and show a page that has a newsletter "radio" button. when click on the radio button, it will update the inserted data before to inlcude newsletter (Y/N)..
but i cant seem to update the last record to apply the radio button...
i have 2 php scripts....
first one to insert normal data...
<html>
<head>
<title>PHP and Forms</title>
</head>
<body>
<?php
//connect to server
$conn = mysql_connect("localhost","admin","");
if(!$conn){
die("Connection Failed: " .mysql_error());
}
//connect to database
mysql_select_db("activity4",$conn);
//inserting data into table 'mycustomers'
$sql = "INSERT INTO customers (gname,fname,email)
VALUES
('$_POST[gname]','$_POST[fname]','$_POST[email]')";
$result = mysql_query($sql,$conn);
$cookieID = mysql_insert_id();
//set customer ID as a COOKIE
setcookie('customerid', $cookieID);
echo $_COOKIE['customerid'];
?>
<form method="post" action="part3form2.php">
<br>
Newsletter?? <input type="radio" name="newsletter">
<br>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</form>
</body>
</html>
and the second to update data to apply newsletter (Y/N)...
<?php
//connect to server
$conn = mysql_connect("localhost","admin","");
if(!$conn){
die("Connection Failed: " .mysql_error());
}
//connect to database
mysql_select_db("activity4",$conn);
$newsletter = $_POST['newsletter'];
$id = $_POST['customerid'];
//updating data into table 'mycustomers'
$sql = mysql_query("update customers set newsletter='$newsletter' where customerid='$id'");
$result = mysql_query($sql,$conn);
echo "Your Customer ID is: " . mysql_insert_id();
?>
still learning php and dont have the knowledge to figure it out. can someone please point out what i'm doin wrong.
Cheers for the help everyone
i have a simple php form, to enter names, email, etc. When submitted it will insert data into DB and show a page that has a newsletter "radio" button. when click on the radio button, it will update the inserted data before to inlcude newsletter (Y/N)..
but i cant seem to update the last record to apply the radio button...
i have 2 php scripts....
first one to insert normal data...
<html>
<head>
<title>PHP and Forms</title>
</head>
<body>
<?php
//connect to server
$conn = mysql_connect("localhost","admin","");
if(!$conn){
die("Connection Failed: " .mysql_error());
}
//connect to database
mysql_select_db("activity4",$conn);
//inserting data into table 'mycustomers'
$sql = "INSERT INTO customers (gname,fname,email)
VALUES
('$_POST[gname]','$_POST[fname]','$_POST[email]')";
$result = mysql_query($sql,$conn);
$cookieID = mysql_insert_id();
//set customer ID as a COOKIE
setcookie('customerid', $cookieID);
echo $_COOKIE['customerid'];
?>
<form method="post" action="part3form2.php">
<br>
Newsletter?? <input type="radio" name="newsletter">
<br>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</form>
</body>
</html>
and the second to update data to apply newsletter (Y/N)...
<?php
//connect to server
$conn = mysql_connect("localhost","admin","");
if(!$conn){
die("Connection Failed: " .mysql_error());
}
//connect to database
mysql_select_db("activity4",$conn);
$newsletter = $_POST['newsletter'];
$id = $_POST['customerid'];
//updating data into table 'mycustomers'
$sql = mysql_query("update customers set newsletter='$newsletter' where customerid='$id'");
$result = mysql_query($sql,$conn);
echo "Your Customer ID is: " . mysql_insert_id();
?>
still learning php and dont have the knowledge to figure it out. can someone please point out what i'm doin wrong.
Cheers for the help everyone