...

View Full Version : Form problem / updating



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

abduraooft
12-03-2008, 10:57 AM
when click on the radio button, it will update the inserted data before to inlcude newsletter (Y/N)..
Don't you need two radio inputs then?, like


<input type="radio" name="newsletter" value="Yes"> Yes
<input type="radio" name="newsletter" value="No"> No and then the php side like

if(isset($_POST['newsletter']))
{
if($_POST['newsletter'] == "Yes")
$newsletter='Y';
else
$newsletter='N';
$sql = mysql_query("update customers set newsletter='$newsletter' where customerid='$id'");

$result = mysql_query($sql,$conn) or die(mysql_error());

}

jr41
12-03-2008, 11:17 AM
Don't you need two radio inputs then?, like


<input type="radio" name="newsletter" value="Yes"> Yes
<input type="radio" name="newsletter" value="No"> No

I'v got the submit button and reset button there, so i guess if i click on the radio button then submit, logically that means yes. and if i dont click on the button and submit it , thats a no. Do i have to write up a function for that???

Fumigator
12-03-2008, 04:54 PM
Just use the code that abduraooft was so kind to write up for you. You want two radio buttons, one for yes and one for no.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum