 |
PHP How-To Post your "How do I do this with PHP?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

October 11th, 2013, 02:03 PM
|
Authorized User
|
|
Join Date: Apr 2013
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
passing selected data to database
Someone please tell me what I'm doing wrong. It doesn't work.
HTML Code:
<HTML>
<body bgcolor="#ccffff">
<FORM name=Form action="rateselect.php" method=post>
<B><center>
Set tax rate <SELECT name=taxrate>
<OPTION value=0.0000 selected>0.0%
<OPTION value=0.02900>2.9%
<OPTION value=0.04000>4.0%
<OPTION value=0.04225>4.225%
<OPTION value=0.04500>4.5%
<OPTION value=0.04700>4.7%
<OPTION value=0.05000>5.0%
<OPTION value=0.05300>5.3%
<OPTION value=0.05500>5.5%
<OPTION value=0.05600>5.6%
<OPTION value=0.05750>5.75%
<OPTION value=0.06000>6.0%
<OPTION value=0.06250>6.25%
<OPTION value=0.06500>6.5%
<OPTION value=0.06850>6.85%
<OPTION value=0.06875>6.875%
<OPTION value=0.07000>7.0%
<OPTION value=0.08250>8.25%
</OPTION></SELECT><p>
<CENTER>
<INPUT type=image height=24 alt="submit button" width=129 src="rollsubmit.gif"
border=0>
</CENTER>
</FORM></B></BODY></HTML>
PHP Code:
<?php
if (isset( $_POST['taxrate']) )
{
$taxrate=$_POST['taxrate'];
}
mysql_connect("localhost","root","");
mysql_select_db('numbersdb') or die( "Unable to select database");
print $_POST['taxrate'];
$query = "
INSERT INTO numbdata (taxrate)
VALUES('$taxrate')";
echo "data inserted</font><br /><br />";
$stat = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close();
?
|

October 17th, 2013, 12:47 AM
|
Registered User
|
|
Join Date: Oct 2013
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Re: putting data in a database
Hello,
What exactly do you want to do? If you want to update the table, you have to use update query or you will have to use insert to insert new record.
Regard
|

October 17th, 2013, 12:54 AM
|
Registered User
|
|
Join Date: Oct 2013
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Re: putting data in a database
Oh sorry, I didn't read the code to the end. What problem do you have with the code? I think you should use update instead of insert and since you are define a particular column in a table, you should just update. Or what do you think?
|
The Following User Says Thank You to Adebayo For This Useful Post:
|
|

October 17th, 2013, 04:17 PM
|
Authorized User
|
|
Join Date: Apr 2013
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
I can't seem to get the code right
PHP Code:
<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
mysql_connect("localhost","root","");
mysql_select_db("numbersdb") or die( "Unable to select database");
if(!empty($_POST["submit"]))
{
$taxrate = $_POST['taxrate'];
$query="SELECT * FROM numbdata Where id='$id'";
$result=mysql_query($query);
if(mysql_num_rows($result))
{
}else{echo "No listing for taxrate $taxrate .<br />Select another? .<br />";}
}
if(!empty($_POST["update"]))
{
$sql = "UPDATE numbdata SET
taxrate = '" .mysql_real_escape_string($_POST['taxrate']) . "',
WHERE taxrate='".$_POST['taxrate']."'";
mysql_query($sql) or die(mysql_error());
echo "Record for taxrate ".$_POST["taxrate"]." has been updated";
}
?>
|

October 18th, 2013, 11:25 AM
|
Authorized User
|
|
Join Date: Apr 2013
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
I have a one record database table (numbdata)with fields such as taxrate.
I'm trying to select one option using HTML, pass it to PHP and
update the one field (taxrate)in numbdata.
|

October 22nd, 2013, 06:47 PM
|
Authorized User
|
|
Join Date: Apr 2013
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
hello all, Below is my current code w/response. I hope for a solution, thanks
Quote:
GA is invalid.
Select another ?
Abbreviate; NY, CA, etc;
|
PHP Code:
<html><body bgcolor="ccffff"><center>
<?php
error_reporting(E_ALL ^ E_NOTICE);
mysql_connect("localhost","root","");
mysql_select_db("taxdb") or die( "Unable to select database");
if(!empty($_POST["submit"]))
{
$state = $_POST['state'];
$taxrate = $_POST['taxrate'];
$query="SELECT * FROM taxtbl Where id='$id'";
$result=mysql_query($query);
if(mysql_num_rows($result))
{
echo "<form action='#' method='post'><b><br /><br />
<table border='1'>
<tr>
<th>state</th>
</tr>";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>
<td><input type='text' size=2 name='state' value='" . $row['state'] . "'></td>
</tr>";
}
echo "</table>
<input type='submit' name='update' value='Update Record' />
</form>";
}
else{echo "$state is invalid.<br />Select another ?<br />";}
}
if(!empty($_POST["update"]))
{
$sql = "UPDATE taxtbl SET
taxrate = '" . mysql_real_escape_string($_POST['taxrate']) . "',
WHERE state'".$_POST["state"]."'";
mysql_query($sql) or die("Update query failed.");
echo "tax rate".$_POST["state"]." has been set ...";
}
?>
<form method="post" action="#"> <br />
Abbreviate;
<input type="text" name="state"/>NY, CA, etc; <p>
<input type="submit" name="submit" value="make selection"/>
</form>
</center></BODY></HTML>
|
|
 |