Jump to content

Getting Info from TextBox


JakeSilver

Recommended Posts

I am having trouble getting the info from a automatically created textbox... Basically the text boz is gererated with the name set to its ID.. code is as follows:

<?$sectionquery=mysql_query("SELECT * FROM `section` ORDER BY 'id' ASC");

while($data=mysql_fetch_object($sectionquery)){

echo "<p>$data->name<input type='text' value='' name='$data->id' size='4'></p> ";

 

I am retrieving the info int the same way... shown below

 

$numsec=mysql_query("SELECT * FROM `section` ORDER BY 'id' ASC")or die (mysql_error()); 

while($secdata=mysql_fetch_object($numsec)){
$secid=$secdata->id;
$navvalue= $_GET['$secid->id'];

mysql_query("UPDATE `thinkweb_advanced`.`section` SET `nav` = '$navvalue' WHERE `section`.`id` =$secid LIMIT 1")or die (mysql_error());

echo "Updated";

 

However, The info in the textbox is not being added into my database??

 

any idea?

 

Thanks, Jake ;D

Link to comment
https://forums.phpfreaks.com/topic/112908-getting-info-from-textbox/
Share on other sites

i could be wrong but I'm not sure this is written with correct syntax

 

yours:

mysql_query("UPDATE `thinkweb_advanced`.`section` SET `nav` = '$navvalue' WHERE `section`.`id` =$secid LIMIT 1")or die (mysql_error());

 

mine:

mysql_query("UPDATE [thinkweb_advanced.section] SET nav=".$navvalue."' WHERE section.id='".$secid."'LIMIT 1")or die (mysql_error());

his syntax should work.

 

First step in debugging mysql is to echo the query back to STDOUT to make sure it is what you think it is.  For this reason, I consider it good practice to structure queries in the form:

 

$query = "My mysql query";
$result = mysql_query($query);

 

So add this to the second file's while loop and verify the final string is correct.

echo "UPDATE `thinkweb_advanced`.`section` SET `nav` = '$navvalue' WHERE `section`.`id` =$secid LIMIT 1<br>";

 

 

Mbeals - I have just echoed the query and your right $navvalue has no value which would explain a great deal.. However, I do not know how i am able to retireve the info that is in the textbox any ideas?

 

ag3nt42 - Im sorry if my syntax is lame :P i taught myself from reading scripts... poorly structured perhaps  ;D

i learned through practice too.  mostly w3

 

Your issue is

$navvalue= $_GET['$secid->id'];

 

php interprets single quotes as string literals, so it is physically looking for the $_GET key named $secid->id and not the dereferenced value. 

 

try:

$id = secid->id;
$navvalue= $_GET[$id];

 

or

$navvalue= $_GET[$secid->id];

 

and see what happens.  Might also be worth adding an echo secid->id; to make sure it is what you think it is.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.