j3rmain3 Posted October 30, 2006 Share Posted October 30, 2006 i have a form which is used to rate documents. I have been able to create the form well, but now i am trying to get the rating into MySQL. the problem is for the rating to appear into the database, i need to use the $var = $_POST['var'];. I was trying to use the [code]if (mysql_fetch_row($results) > 0) { while ($row=mysql_fetch_rows($result)) { echo $row[1]tech = $_POST['$row[1]tech']; }}[/code]This was so when a new row was added to the table it would automatically add a new POST into the file. This would be alot easier for the user because they do not know how to code. Help ???Thanks,j3rmain3 Quote Link to comment https://forums.phpfreaks.com/topic/25568-putting-html-form-_postvar-in-a-function/ Share on other sites More sharing options...
kenrbnsn Posted October 30, 2006 Share Posted October 30, 2006 WHat is the field name in your table?In general the code you should use will look something like:[code]<?php$q = "select * from tablename where fieldname = 'somevalue'";$rs = mysql_query($q);while ($row = mysql_fetch_assoc($rs)) { $qtmp = "update tablename set tech = '" . mysql_real_escape_string($_POST['tech'] . " where fieldname = 'somevalue'"; $urs = mysql_query($qtmp) or die("Error updating database, query: $qtmp<br>" . mysql_error());}?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/25568-putting-html-form-_postvar-in-a-function/#findComment-116674 Share on other sites More sharing options...
j3rmain3 Posted October 30, 2006 Author Share Posted October 30, 2006 The fieldname is 'filename', but i havent labelled the field so when i type in $row['filename'] nothing appears, that is why i am using $row[1] in my coding.j3rmain3 Quote Link to comment https://forums.phpfreaks.com/topic/25568-putting-html-form-_postvar-in-a-function/#findComment-116680 Share on other sites More sharing options...
HuggieBear Posted October 30, 2006 Share Posted October 30, 2006 [quote author=j3rmain3 link=topic=113212.msg459909#msg459909 date=1162209212]when i type in $row['filename'] nothing appears, that is why i am using $row[1] in my coding.[/quote]That's because mysql_fetch_row() only returns a numerical array, not an associative array. If you wanted to use $row['filename'] then you'd need to use mysql_fetch_array() or mysql_fetch_assoc():[code]<?phpwhile ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ ...}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25568-putting-html-form-_postvar-in-a-function/#findComment-116685 Share on other sites More sharing options...
j3rmain3 Posted October 30, 2006 Author Share Posted October 30, 2006 Not sure if i explained my situation well because i am bit confused with the advice you peeps have given me. I wll use the mysql_fetch_assoc function but where is hasrow[1]tech - the 'tech' bit is what i want to be added after the filename. filename is the name of row[1]. So it should produce something like this:$filename1tech = $_POST['filename1tech'];$filename2tech = $_POST['filename2tech'];$filename3tech = $_POST['filename3tech'];I am not sure if it has anything to with updating the database in mysql because it will not affect the data in there. I want the file to be updated so that when the user enters a new row in the mysql table, the new filename will appear in the $_POST section as:$filename4tech = $_POST['filename4tech']; So the file has been updated without manually adding any coding.Hope this has helped.Thanks for the feedback so far........J3rmain3 Quote Link to comment https://forums.phpfreaks.com/topic/25568-putting-html-form-_postvar-in-a-function/#findComment-116692 Share on other sites More sharing options...
HuggieBear Posted October 30, 2006 Share Posted October 30, 2006 I don't think that you've explained this well enough, and maybe you're getting confused with terminology.My advice would be to leave all technical details out and post a description of what you're trying to achieve, something like this:[color=blue][i]I have a web page with a form on it, the form fields are dynamically generated from the database, the form allows users to rate documents in the database. I want the ratings applied in the form to be replicated through to the database. Here's the code I have so far...[/i][/color]Something like that.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25568-putting-html-form-_postvar-in-a-function/#findComment-116718 Share on other sites More sharing options...
j3rmain3 Posted October 30, 2006 Author Share Posted October 30, 2006 OkI have created a site which allows users to view documents on a server and i am currently trying to create a rating system so people can rate each document.I have created the database, the form and i am able to update the database perfectly through an HTML form. But what i am trying to do now is store the rating into mysql and get it saved. I am using dropdown menus as a way for the user to put in their rating. This is the coding which i am currently structing to insert the rating. I have built some script so each row will appear with a drop down menu.[code]$connection = mysql_connect($host,$user,$pass) or die ("ERROR: Unable To Connect");mysql_select_db($db) or die ("ERROR: Unable To Connect To DB");$query = "SELECT * FROM url ORDER BY session";$result = mysql_query($query) or die ("ERROR: Unable To Run Query".mysql_error());if (mysql_num_rows($result) > 0) {echo "<form name=ratings method=POST action=linkstable1.php>";echo "<table border=1 cellpadding=3 cellspacing=3>";echo "<tr>";echo "<td><b><font face=Verdana size=-1>Session</td>";echo "<td><b><font face=Verdana size=-1>Title Of Brainstorm Idea</b>";echo "<td><b><font face=Verdana size=-1>Inventor Name</td>";echo "<td><b><font face=Verdana size=-1>Rating</td>";echo "</tr>";while ($row=mysql_fetch_row($result)){echo "<tr>";echo "<td><font face=Verdana size=-1>".$row[4]."</td>";echo "<td><font face=Verdana size=-1><a href=https://mysite.com/$row[2] target=_blank>".$row[1]."</a></td>";echo "<td><font face=Verdana size=-1>".$row[3]."</td>";echo "<td><select name=rates> <option value= selected> <option value=1 name=$row[1]tech>1 - Poor <option value=2 name=$row[1]tech>2 - Fair <option value=3 name=$row[1]tech>3 - Average <option value=4 name=$row[1]tech>4 - Good <option value=5 name=$row[1]tech>5 - Excellent</select></td>";echo "</tr>";} echo "</table>";} else { echo "No Rows Found!";}echo "<br>";echo "<input type=submit value=submit name=sumbit_rating>";echo "</form>";?>[/code]i have started a new php file which will display the new ratings.I am confused about how to get the rating into the table and saving it.When i was doing previous exercises, to get the data from an HTML form into a database, the processed php file needed to have[b]$var = $_POST['var'][/b]; at the top and this is for every input type which was being copied from the HTML form to the database. My problem is i want the coding above to be updated every time new data has been added to the database, but i want it to be updated automatically, not manually. So the scenario would be; a new row has been added to the database and then in the php file, a new line of code would be generated. So another one would appear when a new row was added to the database.Hope i have explained it well.Maybe if you undestand what i am trying to do with the coding here, you may understand what i mean alot better.[code]$connection = mysql_connect($host,$user,$pass) or die ("ERROR: Unable To Connect".mysql_error());mysql_select_db($db) or die ("ERROR:Unable To Connect To DB".mysql_error());$query = "SELECT * FROM url";$result = mysql_query($result) or die ("ERROR:Unable To Connect Query".mysql_error());if (mysql_fetch_row($results) > 0) { while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) { echo "$row[1]tech = $_POST[$row[1]tech]"; } else { echo " "; }} ?>[/code]Thanks Quote Link to comment https://forums.phpfreaks.com/topic/25568-putting-html-form-_postvar-in-a-function/#findComment-116785 Share on other sites More sharing options...
j3rmain3 Posted October 31, 2006 Author Share Posted October 31, 2006 Sorry to bring this up again, but can someone please tell me what i am doing wrong because i still dont understand how to do it.Thanks,j3rmain3 Quote Link to comment https://forums.phpfreaks.com/topic/25568-putting-html-form-_postvar-in-a-function/#findComment-117207 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.