nomadsoul Posted July 21, 2009 Share Posted July 21, 2009 Hi, hope you all are well. I'm not sure if this question goes here or in the mysql forum: I just finished my basic update.php page. I even used a straight connection instead of an include() but no matter what, my form does not show. I know the connection is good because I've been using it in the insert.php script. TIA <?php $con = mysql_connect("MySQL.host.com","uname","pword"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb-language", $con); ?> <? $query=" SELECT * FROM words WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $topic=mysql_result($result,$i,"topic"); $eword=mysql_result($result,$i,"eword"); $cword=mysql_result($result,$i,"cword"); $spanw=mysql_result($result,$i,"spanw"); ?> <form action="updated.php" method="post"> <input type="hidden" name="id" value="<? echo $id; ?>"> Topic: <input type="text" name="topic" value="<? echo $topic; ?>"><br> English: <input type="text" name="eword" value="<? echo $eword; ?>"><br> Chinese: <input type="text" name="cword" value="<? echo $cword; ?>"><br> Spanish: <input type="text" name="spanw" value="<? echo $spanw; ?>"><br> <br> <input type="Submit" value="Update"> </form> <? ++$i; } ?> Link to comment https://forums.phpfreaks.com/topic/166769-wheres-my-form/ Share on other sites More sharing options...
kenrbnsn Posted July 21, 2009 Share Posted July 21, 2009 Always use long tags, "<?php", to start PHP instead of short tags, "<?". That could be one of your problems. Also, why are you making one form per record? You should have just one form. Try something like this: <?php $con = mysql_connect("MySQL.host.com","uname","pword") or die('Could not connect to the database<br>' . mysql_error()); $rs = mysql_select_db("mydb-language", $con) or die("Could not select db<br>" . mysql_error()); $query=" SELECT * FROM words WHERE id='$id'"; // where is $id coming from??? $result=mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); $num=mysql_numrows($result); if ($num > 0) { echo "<form action='updated.php' method='post'>\n"; while($rw = mysql_fetch_assoc($rs)) { echo 'Topic <input type="text" name="topic[" . $rw['id'] . "] value="' . $rw['topic'] . '"><br>' . "\n"; echo 'English<input type="text" name="eword[" . $rw['id'] . "] value="' . $rw['eword'] . '"><br>' . "\n"; echo 'Chinese<input type="text" name="cword[" . $rw['id'] . "] value="' . $rw['cword'] . '"><br>' . "\n"; echo 'Spanish<input type="text" name="spanw[" . $rw['id'] . "] value="' . $rw['spanw'] . '"><br>' . "\n"; echo "<br>\n"; } echo '<input type="submit" value="Update" name="submit">' . "\n"; echo "</form>\n"; } ?> Where is the variable $id being set before the line: <?php $query=" SELECT * FROM words WHERE id='$id'"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/166769-wheres-my-form/#findComment-879385 Share on other sites More sharing options...
nomadsoul Posted July 21, 2009 Author Share Posted July 21, 2009 Ken, Sure enough: echo isset($variable) ? 'yes' : 'no'; returned 'no' I hope that's the problem. Let me work on this a bit. Please check back if you can. Thanks for the hasty relpy Link to comment https://forums.phpfreaks.com/topic/166769-wheres-my-form/#findComment-879409 Share on other sites More sharing options...
nomadsoul Posted July 22, 2009 Author Share Posted July 22, 2009 I used your script and put the $id = $_POST["id"]; variable where it belongs (I hope)but I still don't get form output. Here is the updated.php page. Perhaps I need to use the id field in my Update query? <?php $id = $_POST["id"]; $con = mysql_connect("MySQL.myhost.com","myuname","mypword"); if (!$con) { die('Could not connect: ' . mysql_error()); } // some code mysql_select_db("xfirstcybercontact-language", $con); $query="UPDATE words SET topic='$topic', eword='$eword', cword='$cword', spanw='$spanw' WHERE id='$id'"; @mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); echo "Record Updated"; mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/166769-wheres-my-form/#findComment-880253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.