j3rmain3 Posted November 15, 2006 Share Posted November 15, 2006 I am trying to display numbers which have been sent from a form but i get the error message:Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\Apache\Apache2\PHPFiles\brainstorm\btable.php on line 42This is the code:while ($row=mysql_fetch_assoc($result)){$num = $row;for ($i=1;$i<=$row;$i++) { $post = $row['filename']."tech"; $$post = $_POST[$post];}[b]42:[/b] echo "<td><font face=Verdana size=-1>".${$post}"</td>";Can anyone see what is wrong IN LINE 42? Isn't that the way i display something using variable variableThanksJ3RMAIN3 Quote Link to comment Share on other sites More sharing options...
marcus Posted November 15, 2006 Share Posted November 15, 2006 You can't have a double $.You could always just replace it with$post .= $_POST[$post];or$post1 = $_POST[$post]; Quote Link to comment Share on other sites More sharing options...
j3rmain3 Posted November 15, 2006 Author Share Posted November 15, 2006 I have nearly finished creating a rating system but i am stuck on one last thingI am about to use UPDATE to add data to my databases but i have a problem trying to write the query here is what i want to do:UPDATE doc_rate SET tech_rating = $_POST[$post] WHERE $fileID = $ID [b]my problem is the $ID is part of another table(doc_data).[/b] How do i get $fileID from the doc_rate table look for a matching ID in the doc_data table.J3RMAIN3 Quote Link to comment Share on other sites More sharing options...
j3rmain3 Posted November 15, 2006 Author Share Posted November 15, 2006 [quote author=mgallforever link=topic=115058.msg468310#msg468310 date=1163591899]You can't have a double $.You could always just replace it with$post .= $_POST[$post];or$post1 = $_POST[$post];[/quote]mgallforever: I thought that is how i use variable variable? with double $And the error was mentioning the row under it, so i think it accepted the $$ ok. Quote Link to comment Share on other sites More sharing options...
j3rmain3 Posted November 15, 2006 Author Share Posted November 15, 2006 I have created a form which should allow me to add values into a database. I am using dropdown menus to input the values. I am having trouble moving the values into the database. This is supposed to be a rating system.Here is the coding for the form[code]<html><head><title>Brainstorm Table</title></head><body><?phpif (!isset($_POST['submit'])){?><?php$host = "myserver";$user = "myself";$pass = "password";$db = "help";$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 doc_data ORDER BY session ";$result = mysql_query($query) or die ("ERROR:Unable To Run Query".mysql_error());echo "<h3><font face=Verdana>Department: Technical</h3>";if (mysql_num_rows($result) > 0) { echo "<form name=ratings method=POST action=btable.php>"; echo "<table border=1 cellpadding=3 cellspacing=3>"; echo "<tr>"; echo "<td><font face=Verdana size=-1><b>Session</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Title of Brainstorm Idea</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Inventor Name</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Rating</b></font></td>"; echo "</tr>"; while ($row=mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['session']."</center></td>"; echo "<td><font face=Verdana size=-1><a href=http://www.mysite.com/$row[url]><font face=Verdana size=-1>".$row['idea']. "</td>"; echo "<td><font face=Verdana size=-1>".$row['inventor_name']."</td>"; echo "<td><select name=rates> <option value= selected> <option value=1 name=$row[idea]tech>1 - Poor <option value=2 name=$row[idea]tech>2 - Fair <option value=3 name=$row[filename]tech>3 - Average <option value=4 name=$row[filename]tech>4 - Good <option value=5 name=$row[filename]tech>5 - Excellent</select></td>"; echo "</tr>"; }echo "</table>";} else {echo "No Rows Found";}echo "<br>";echo "<input type=submit name=submit value=Submit><br><br>";echo "<b><font face=Verdana size=-1><a href=http://localhost/brainstorm/index.php>Back to Form</a>";?><?php} else {$host = "myserver";$user = "myself";$pass = "password";$db = "help";$conn = 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");$query = "SELECT * FROM doc_data ORDER BY session";$result = mysql_query($query) or die ("ERROR:Unable to Run Query".mysql_query());while ($row=mysql_fetch_assoc($result)){#$num = $row;#for ($i=1;$i<=$row;$i++) {$posttech = $row['filename']."tech";# $postfin = $row['filename']."fin";$postt = $_POST[$posttech];# $postf = $_post[$postfin];$query1 = "UPDATE doc_rate SET tech_rating=$_POST[$postt] WHERE $rate_id = $doc";$result = mysql_query($result) or die ("ERROR:Unable To Run Query".mysql_query()); }#$row['filename'] = empty($_POST[$postt])}?></body></html>[/code]Here is the coding for the table which the results are supposed to be displayed in:[code]<html><head><title>Brainstorm Table</title></head><body><?php$host = "myserver";$user = "myself";$pass = "password";$db = "help";$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 doc_data ORDER BY session ";$result = mysql_query($query) or die ("ERROR:Unable To Run Query".mysql_error());if (mysql_num_rows($result) > 0) { echo "<table border=1 cellpadding=3 cellspacing=3>"; echo "<tr>"; echo "<td><font face=Verdana size=-1><b>Session</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Title of Brainstorm Idea</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Inventor Name</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Technical Rating</b></font></td>"; echo "<td><font face=Verdana size=-1><b>Finance Rating</b></font></td>"; echo "</tr>"; while ($row=mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td><p align=center><font face=Verdana size=-1>".$row['session']."</center></td>"; echo "<td><font face=Verdana size=-1><a href=http://www.mysite.com/$row[url]><font face=Verdana size=-1>".$row['idea']."</td>"; echo "<td><font face=Verdana size=-1>".$row['inventor_name']."</td>"; #$num = $row; #for ($i=1;$i<=$row;$i++) { # $posttech = $row['filename']."tech"; # $postfin = $row['filename']."fin"; # $postt = $_post[$posttech]; # $postf = $_post[$postfin]; #} #echo "<td><font face=Verdana size=-1>".${$postt}"</td>"; #echo "<td><font face=Verdana size=-1>".${$postf}"</td>"; #echo "<td><font face=Verdana size=-1>"$row['filename']."fin</td>"; echo "</tr>"; }echo "</table>";} else {echo "No Rows Found";}echo "<br>";echo "<b><font face=Verdana size=-1><a href=http://localhost/brainstorm/index.php>Back to Form</a>";?></body></html>[/code]Can anyone help me work out how to place the data into the table.Here are the problems i have encountered:1. I have placed $_POST in a loop but that didnt seem to work. This is the way i done the loop:[code]while ($row=mysql_fetch_assoc($result)){ for ($i=1;$i<=$row;$i++) { $posttech = $row['filename']."tech"; $postfin = $row['filename']."fin"; $postt = $_post[$posttech]; $postf = $_post[$postfin]; }[/code]Should this work?2. Do i record the ratings by creating another table in MySQL. I thought i had to, but then i created a foreign key so that i could match the $rate_id from the rating table to the $id in the doc table. Is this right?I stopped this because i was confused on how to populate the FK with the $id from the doc table.3. I was using UPDATE so that the rating did not have to be placed in numerically. It could be placed in anywhere in the database. This is the coding i was using:[code]$update = "UPDATE doc_rate SET tech_rating = $postf WHERE $rate_id = $id [/code]$id is supposed to come from another table which is doc_data, thats is why i added a FK in doc_rate. But like i said above i do not know how to populate the FK with data from another table.Someone help me plz ???J3RMAIN3 Quote Link to comment 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.