kostag Posted May 26, 2010 Share Posted May 26, 2010 Hey all, Firstly let me start by saying thankyou to all the members for their time and experience. The forum has been a great source of information fo someone as new as me. Now onto the interesting bit :-) I have created a form which alows information to be sent to a MySQL database and displayed on a HTML page. All the details are displayed the way I want them. I have included checkboxes linked to the ID field of my database. This would allow certain entries to be selected, and once selected, the user would be able to select one of two radio buttons which will provide a value of 1 or 0, which indicates approved or disapproved. Here is the code so far ...a little raw but workable .... <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $host="localhost"; // Host name $username="root"; // Mysql username $db_name="sqltest"; // Database name $tbl_name="sosql"; //table name where we get the details from mysql_connect("$host", "$username")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); ?> <form method="post" action="dbtest_sql.php"> Name : <input name="name" type="text" id="name"><br> Email : <input name="email" type="text" id="email"><br> <input name="send" type="submit" value="Send!"> </form> <form id="results" name="form1" method="post" action=""> <div align="center"> <p> <?php $id=$_POST['id']; $Date=$_POST['Date']; $name=$_POST['name']; $email=$_POST['email']; $Value=$_POST['Value']; $query="SELECT * FROM $tbl_name"; $result=mysql_query($query); echo "<b><center>Database Output</center></b><br><br>"; echo "<table border='1'>"; echo "<tr> <th>ID</th>"; echo "<th>Date</th>"; echo "<th>Name</th>"; echo "<th>E-mail</th>"; echo "<th>Value</th></tr>"; while($row = mysql_fetch_assoc($result)) { // Print out the contents of each row into a table echo "<tr><td>"; echo "<input type=checkbox name=". $row['id'] . " id=". $row['id'] . " value=". $row['id'] . " />".$row['id']; echo "</td><td>"; echo $row['Date']; echo "</td><td>"; echo $row['name']; echo "</td><td>"; echo $row['email']; echo "</td><td>"; echo $row['Value']; echo "</td></tr>"; } echo "</table>"; if($result){ echo "You have successfully update this entry on the database"; echo "<br>"; echo "<a href='testform.php'> Back to search page</a>"; } else { echo mysql_error(); } ?> </p> <p> <?php //connect to db $host="localhost"; // Host name $username="root"; // Mysql username $db_name="sqltest"; // Database name $tbl_name="sosql"; //table name where we get the details from mysql_connect("$host", "$username")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // variables $fields['1'] = false; $fields['0'] = false; $fields[$_POST['update']] = true; $id=$_POST['id']; //sql queries mysql_query($query); $query="INSERT INTO $tbl_name (Value) VALUES ('$fields[1]', '$fields[0])'"; $result=mysql_query($query); ?> <input type="radio" name="update" id="fields" value="1" /> Approve <input type="radio" name="update" id="fields" value="0" /> Disapprove</p> <p> <input type="submit" name="button" id="button" value="Update the Database" /> </p> </div> </form> </body> </html> For some reason i cant seem to pass the value of the radio button to the database. i dont think im linking the checkbox correctly to the db or the sql query im writing is wrong. Any help would be greatly appreciated as this brick wall is killing me ... Link to comment https://forums.phpfreaks.com/topic/203027-help-in-passing-values-please/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.