Odd Mysql, php and input box's error.

Status
Not open for further replies.

phin

Ars Tribunus Militum
1,547
okay now tell me if this is not an odd error.

i am pulling values from a mysql table to be put into input box's on a modify form.

i pull the info as follows.

Code:
  $database = mysql_connect($mysql_hostname, $mysql_username, $mysql_password);
  mysql_select_db($mysql_database, $database);

  $query = @mysql_query("SELECT * FROM $mysql_tablename WHERE day = \"$thedate\"", $database);
	
   while ($row = mysql_fetch_array($query)) {
	 $tdate = $row['day'];
	 $eventname = $row['eventname'];
	 $performer1name = $row['performer1name'];
	 $performer1pic = $row['performer1pic'];
	 $performer1links = $row['performer1links'];
	 $performer1bio = $row['performer1bio'];
	 $performer1info = $row['performer1info'];
	 $performer2name = $row['performer2name'];
	 $performer2pic = $row['performer2pic'];
	 $performer2links = $row['performer2links'];
	 $performer2bio = $row['performer2bio'];
	 $performer2info = $row['performer2info'];
	 $performer3name = $row['performer3name'];
	 $performer3pic = $row['performer3pic'];
	 $performer3links = $row['performer3links'];
	 $performer3bio = $row['performer3bio'];
	 $performer3info = $row['performer3info'];
	 $bannerpic1 = $row['bannerpic1'];
	 $bannerpic2 = $row['bannerpic2'];	
	 $bannerpic3 = $row['bannerpic3'];
	 $bannerpic4 = $row['bannerpic4'];
	 }


and it seems to pull correctly, if i just do an

Code:
 echo "$eventname";

boom it pops it up perfect...

BUUUUUUT.....

if i do this...

Code:
<? echo"<input type=text name=eventname size=25 maxlength=200 value=$eventname>"; ?>

it only puts the first word in.

so lets say the $eventname is Ars Technica. when i just plain echo the feild. it pops up Ars Technica. BUT if i put it in an input box it will just say Ars

any ideas? i am lost :confused:
 

FriarPuck

Ars Praefectus
4,053
Subscriptor
You need to put quotes around the data in the value attribute of the input tag. 1) it's the standard 2) If you don't put quotes around the data and the data is comprised of 2 words (eg. Hello World) then only the data before the space is going to be displayed.

So, in other words change your code to...

Code:
 <? echo"<input type=text name=eventname size=25 maxlength=200 value=\"$eventname\">"; ?>

...Or...

Code:
 <? echo"<input type=text name=eventname size=25 maxlength=200 value='$eventname'>"; ?>

...and all should work fine.
 
Yet another way :) to do it is if you want to get used to using the print() and printf() functions (which will come in handy later), is to do it:
Code:
<? print("<input blah=blah value=".$eventname.">");   ?>
Or if you want to do it another way:
Code:
<? printf("<input blah=blah value=%s>", $row["eventname"]);   ?>

Where %s gets replaced by the variable (which can be your $eventname, or as I've put: $row["eventname"], either or it doesn't much matter)

Anyway I'm probably conufusing the issue, but at the heart of it, hit up php.net and read about the print functions and get used to using them over 'echo' function (in my opinion).
 
Status
Not open for further replies.