Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

questions regards to qid=1585634

Status
Not open for further replies.

phpdonkey

Technical User
Mar 3, 2011
25
0
0
NL
thread216-1585634
hi! i was actually following along with the thread213-1585634
since i am doing the very same thing. im also a newby in the programming world, and i had some questions about this dropdown menu:


I also need to find a way to have 5 text fields populate dynamically from the user selection of a drop down menu value. I have seen many numbers of threads about this even other websites, but none are working for me. untill i came accros this website with the repective posts .
I have a drop down menu that is dynamically filled with the company names from a mySQL database. (this works) What I need is for the text input fields (aTitle, aStory, aFooter, aGraphic, visiblePage.(visiblePage is an enum value in db for my radio buttons to swtich it visible or hidden)) to fill with the information that belongs to the record in that table and have it loaded id from the drop down selection.

my db table about look like this :
aboutId | aboutTitle | aboutStory | aboutGraphic | aboutFooter | visiblePage

since i like DW i use it to help me along the way , i have managed to get this far while following lesSje and vacunita. i dont want to be a copy cat i just want to learn php much better since i want to make my own website with it.
can anyone tell me what i am doing wrong and how to populate my inputs based on what information i have in my about table?

my code look like this :

php:
Code:
<?php require_once('../Connections/db_config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_db_config, $db_config);
$query_rsAbout = "SELECT aboutId, aboutTitle, aboutStory, aboutGraphic, aboutFooter, visiblePage FROM about ORDER BY aboutId ASC";
$rsAbout = mysql_query($query_rsAbout, $db_config) or die(mysql_error());
$row_rsAbout = mysql_fetch_assoc($rsAbout);
$totalRows_rsAbout = mysql_num_rows($rsAbout);

?>


html form + js :
Code:
<head>
<script type="text/javascript">
	function selectItem(selObj)
	{
		var aboutItemArray=new Array();
		aboutItemArray.<?php echo $row['aboutId']; ?> = new Array();
		aboutItemArray.<?php echo $row['aboutId']; ?>.aboutTitle=<?php echo $row['aboutTitle'];?> 
		aboutItemArray.<?php echo $row['aboutId']; ?>.aboutStory=<?php echo $row['aboutStory'];?> 
		aboutItemArray.<?php echo $row['aboutId']; ?>.aboutFooter=<?php echo $row['aboutFooter'];?> 
		aboutItemArray.<?php echo $row['aboutId']; ?>.aboutGraphic=<?php echo $row['aboutGraphic'];?> 
		aboutItemArray.<?php echo $row['aboutId']; ?>.visiblePage=<?php echo $row['visiblePage'];?> 
		

	
		
		
		var id = selObj.options[selObj.selectedIndex].value;
		document.getElementById('aboutTitle').value = aboutItemArray[id]['aboutTitle'];
		document.getElementById('aboutStory').value = aboutItemArray[id]['aboutStory'];
		document.getElementById('aboutFooter').value = aboutItemArray[id]['aboutFooter'];
		document.getElementById('aboutGraphic').value = aboutItemArray[id]['aboutGraphic'];
		document.getElementById('visiblePage').value = aboutItemArray[id]['visiblePage'];
		
	}

</script>
    
</head>



    <form name="aboutForm" method="POST" action="<?= $_SERVER['PHP_SELF']?>">
    <select name="about" class="aboutListmenu" id="about" onchange="selectItem(this)">
	 <?php do
	 {
	?>
    <option value="<?php echo $row_rsAbout['aboutId']?>"
	<?php if (!(strcmp($row_rsAbout['aboutId'], $row_rsAbout['aboutId'])))
	{
		   echo "selected=\"selected\"";} ?>>
			 <?php echo $row_rsAbout['aboutTitle']?></option>
				 <?php
    }
	
				 while ($row_rsAbout = mysql_fetch_assoc($rsAbout));
				 $rows = mysql_num_rows($rsAbout);
				           if($rows > 0) 
						   {
							   mysql_data_seek($rsAbout, 0);
							   $row_rsAbout = mysql_fetch_assoc($rsAbout);
							}
					?></select>
                    
     
			<label>About Title:</label>
			<input name="aboutTitle" type="text" id="aboutTitle" />
			  		
		  <label>About Story:</label>
		<textarea name="aboutStory" id="aboutStory" cols="20" rows="5"></textarea>
				
			<label>Footer text:</label>
			<input name="aboutFooter" type="text" id="aboutFooter" value="" />
			
        <label>Current Preview Graphic:</label>
        <img name="aboutGraphic" src="../content/about/<?php echo $row_rsAbout['aboutGraphic']; ?>" class="floatLeft_padding35" />
     

			
	<label><input type="radio" name="1" value="1" />Visible</label>
	<label><input  type="radio" name="0" value="0" />Hidden</label>
			
		<input name="submit" type="submit" id="Submit" value="Submit" />
		
        
          <input type="hidden" name="status" value="" />
		<input type="hidden" name="MM_update" value="">
    </form>

 
your correct. but still some of the fields should be populated i tihnk. i already changed them heheh , still its not working though. is JS also case sensitive and has the array also the be the same order like in php Variables?

Code:
$jsArr.="aboutItemArray[$row_rsAbout[aboutId]]= new Array();        		
	aboutItemArray[$row_rsAbout[aboutId]].[green]AboutTitle[/green]='$row_rsAbout[[red]aboutTitle[/red]]'; // first in the array 
	aboutItemArray[$row_rsAbout[aboutId]].[green]AboutStory[/green]='$row_rsAbout[[red]aboutStory[/red]]'; // 2nd in the array 
	aboutItemArray[$row_rsAbout[aboutId]].[green]AboutFooter[/green]='$row_rsAbout[[red]aboutFooter[/red]]';// 3rd in the array 
	aboutItemArray[$row_rsAbout[aboutId]].[green]AboutGraphic[/green]='$row_rsAbout[[red]aboutGraphic[/red]]';// 4th in the array 
	aboutItemArray[$row_rsAbout[aboutId]].[green]VisiblePage[/green]='$row_rsAbout[[red]visiblePage[/red]]';"; // 5th in the array

Code:
function populate_fields(dropObj)
	{
		var [green]AboutTitle[/green]=document.getElementById('[red]aboutTitle[/red]');
		var [green]AboutStory[/green]=document.getElementById('[red]aboutStory[/red]');
		var [green]AboutFooter[/green]=document.getElementById('[red]aboutFooter[/red]');
		var [green]AboutGraphic[/green]=document.getElementById('[red]aboutGraphic[/red]');
		var [green]VisiblePage[/green]=document.getElementById('[red]visiblePage[/red]');
		
		[green]AboutTitle[/green].value=aboutItemArray[dropObj.value].aboutTitle;
		[green]AboutStory[/green].value=aboutItemArray[dropObj.value].aboutStory;
		[green]AboutFooter[/green]AboutFooter.value=aboutItemArray[dropObj.value].aboutFooter;
		[green]AboutGraphic[/green].src=aboutItemArray[dropObj.value].aboutGraphic;
		[green]VisiblePage[/green].value=aboutItemArray[dropObj.value].visiblePage;
	}

[green]Green[/green] is the JS variable right? and [red]red[/red] is the one from php..

wow this error checking thing is a huge timesaver and can help me sooo much . thanks for that tip buddy! i have cleared the error cache and i see some errors i have a longtext field in the db for the aboutStory <textarea> saying unternimated string in the page source in FF at line 17. i guess thats whats messing up everything below the code too. right?


about the graphic...the graphic is only a bit of text example:
about_1.png in the db so i pull it down as text and put the url infront of it with static text ../content/about/ , i have seen othe rpeople do it like this and it looks fine to me doing it like this right? .. perhaps you know a better way?.. if so i would like to know. first i will try get the the text fields populated. from there on i will expand things. so i can keep track of it while learning it piece by piece.

radiobuttons :
<input type="radio" name="visiblePage" value="1" />Visible</label>
<input type="radio" name="visiblePage" value="0" />Visible</label>

im not sure how to fix this but maybe you can explain a bit further please..




 
i made a typo but you can disregard it
Code:
  AboutFooterAboutFooter.value=aboutItemArray[dropObj.value].aboutFooter;

shoudl be AboutFooter.value=aboutItemArray[dropObj.value].aboutFooter;
 
firefox (FF i call it) source code:
Code:
the problem is an unterminated literal string at line 17 and that the part i color in red what FF highlite's. the code looks like its ended with    ';  but i see and know there are line breaks in my content and also commas in the database longtext text field. 
is this a cause?

actual source:
Code:
<script type="text/javascript">
var aboutItemArray=new Array();
      aboutItemArray[1]= new Array();       		
	aboutItemArray[1].AboutTitle='About me title name here';
	[red]aboutItemArray[1].AboutStory='Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.[/red]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. ';
	aboutItemArray[1].AboutFooter='some text';
	aboutItemArray[1].AboutGraphic='about_1.png';
	aboutItemArray[1].VisiblePage='1';
	aboutItemArray[2]= new Array();       		
	aboutItemArray[2].AboutTitle='About title 2 ';
	aboutItemArray[2].AboutStory='Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 
';
	aboutItemArray[2].AboutFooter='some text2';
	aboutItemArray[2].AboutGraphic='about_2.png';
	aboutItemArray[2].VisiblePage='1';
	//Function to populate the inputs, using the valye from the dropdown to access the values from the array. 

	function populate_fields(dropObj)
	{
		var AboutTitle=document.getElementById('aboutTitle');
		var AboutStory=document.getElementById('aboutStory');
		var AboutFooter=document.getElementById('aboutFooter');
		var AboutGraphic=document.getElementById('aboutGraphic');
		var VisiblePage=document.getElementById('visiblePage');
		
		AboutTitle.value=aboutItemArray[dropObj.value].aboutTitle;
		AboutStory.value=aboutItemArray[dropObj.value].aboutStory;
		AboutFooter.value=aboutItemArray[dropObj.value].aboutFooter;
		AboutGraphic.src=aboutItemArray[dropObj.value].aboutGraphic;
		VisiblePage.value=aboutItemArray[dropObj.value].visiblePage;
	}

</script>
[code]
 
hmm i seem to have found the problem, it lies with the data.. as soon as i have ENTERs in my database longtext field i get this error. "unterminated literal string" this means i cannot use enters in my page content. that should not be. how can i fix it so i can use the enterkey when writing my data and also some
alphanumeric , and special characters in it, i dont want the ' " and those for obvious reasons but the % $ € and # signs cannot hurt a db or do they?. anyway i do now get undefined values for all my textfields aboutTitle aboutFooter aboutStory and a error on visiblePage it says its null . sorry if i ask to much but i always say if you dont ask , you dont know or learn. right? .. by the way i took a look at your blog, nicely done i can see huge skills here . anyway.. do you understand what i try to explain
 
ok now since i wrote a few threads after another and it might be confusing. i will wrap it up so its easier to see what i have done now and what should be corrected..

Code:
mysql_select_db($database_db_config, $db_config);
$query_rsAbout = "SELECT aboutId, aboutTitle, aboutStory, aboutFooter, aboutGraphic, visiblePage FROM about";
$rsAbout = mysql_query($query_rsAbout, $db_config) or die(mysql_error());
$row_rsAbout = mysql_fetch_assoc($rsAbout);
$totalRows_rsAbout = mysql_num_rows($rsAbout);
//$ws_rsAbout = mysql_num_rows($rsAbout);
$dd="";
$jsArr="";
do { 

//I build the dropdown values into the $dd variable and output it later where its supposed to go.
//This allows me to create the Javascript array that will populate inputs and graphics.
$dd.="<option value='$row_rsAbout[aboutId]'>$row_rsAbout[aboutTitle]</option>";

//build the array with the required values 
 $jsArr.="aboutItemArray[$row_rsAbout[aboutId]]= new Array();       		
	aboutItemArray[$row_rsAbout[aboutId]].AboutTitle='$row_rsAbout[aboutTitle]';
	aboutItemArray[$row_rsAbout[aboutId]].AboutStory='$row_rsAbout[aboutStory]';
	aboutItemArray[$row_rsAbout[aboutId]].AboutFooter='$row_rsAbout[aboutFooter]';
	aboutItemArray[$row_rsAbout[aboutId]].AboutGraphic='$row_rsAbout[aboutGraphic]';
	aboutItemArray[$row_rsAbout[aboutId]].VisiblePage='$row_rsAbout[visiblePage]';
	";
	}
	 while ($row_rsAbout = mysql_fetch_assoc($rsAbout));
	$rows = mysql_num_rows($rsAbout);
	if($rows > 0)
		{
		mysql_data_seek($rsAbout, 0);
		$row_rsAbout = mysql_fetch_assoc($rsAbout);
		}

Code:
<script type="text/javascript">
var aboutItemArray=new Array();
      <?php echo $jsArr; ?>
//Function to populate the inputs, using the value from the dropdown to access the values from the array. 

	function populate_fields(dropObj)
	{
		var AboutTitle=document.getElementById('aboutTitle');
		var AboutStory=document.getElementById('aboutStory');
		var AboutFooter=document.getElementById('aboutFooter');
		var AboutGraphic=document.getElementById('aboutGraphic');
		var VisiblePage=document.getElementById('visiblePage');
		
		AboutTitle.value=aboutItemArray[dropObj.value].aboutTitle;
		AboutStory.value=aboutItemArray[dropObj.value].aboutStory;
		AboutFooter.value=aboutItemArray[dropObj.value].aboutFooter;
	
		AboutGraphic.src=aboutItemArray[dropObj.value].aboutGraphic;
	
[blue]//  my db for visiblePage is a ENUM can i retrieve it also like this?
// i get an error on this , not sure why but it says value is NULL and its been set to 1 as default for all records i have [/blue]

		VisiblePage.value=aboutItemArray[dropObj.value].visiblePage;
	}
</script>

Code:
dd:
<select name="aboutSelect" class="aboutListmenu" onChange="populate_fields(this);">       <option value="">-- Select --</option>
   <?php echo $dd; ?>
   </select>

inputs:
 <input name="aboutTitle" type="text" id="aboutTitle" value="" />
 <textarea name="aboutStory" id="aboutStory" cols="20" rows="5"></textarea>
 <input name="aboutFooter" type="text" id="aboutFooter" value="" />

radio:
<label><input   type="radio" name="visiblePage" value="1" />Visible</label>
<label><input   type="radio" name="visiblePage" value="0" />hidden</label>

graphic:
  <img src="" class="floatLeft_padding35" id="aboutGraphic"/>

Code:
free db memory at the end of the page
<?php
mysql_free_result($rsAbout);
?>

with this i get the erros i colored in [blue]blue[/blue]
and have my text fields filled up with undefined so they dont recive anything.. how can i fix this issue first so i can get atleast my textfields populated and radio and graphic displaying.?
 
@vacunita ..
hi i really want to thank you for all your effords you took for me. its realy cool. i went out and looking some more deeper into the code and now i am able to populate my inputs. just not yet the radio buttons and the graphic. so i am more then halfway on the right path . phew . coding is hard esspecially when your new. ;).

can i ask somemore questions?
how can activate the radiobutton currentelly set by the db so if the enum switch is set to 1 ,i want the visible radio button be selected.
my graphic is a just plain text in my db TEXTfield (about_1.png)
and the actual picture is storred in folder ../content/about/about_1.png since i made a folder where i have my admin pages to mange my site like this about page BUT the pictures are in the root/content.cout folder but in my code i acces it in the same folder as the page runs, right? how can i have it display it..
 
hi, i've done some searching here and there but i dont know how to populate my radio buttons the way i should do it now with the JS involved. i know how i can do this with php :
Code:
<p class="rb1"><label><input type="radio" id="visiblePage" name="visiblePage" value="1"[red]<?php 
	if ($row_rsAbout['visiblePage'] == 1) { echo " checked"; } 
	?> />[/red]Visible</label></p>
				<p class="rb0"><label><input type="radio" id="visiblePage" name="visiblePage" value="0"[red]<?php 
	if ($row_rsAbout['visiblePage'] == 0) { echo " checked"; } 
	?> />[/red]Hidden</label></p>
does anyone know how can i use the values from the jsArray to populate the 2 radio buttons... ?

 
Glad its starting to get there. I guess you solved the line break issues, which were definitely the root of the problem.

For the radio buttons, you'll have to check what the value is in your DB, and set the checked or unchecked status of the radio accordingly.

Code:
var myRadios=document.getElementsByName('visiblePage');

if(aboutItemArray[dropObj.value].visiblePage==0){
myRadios[0].checked=true;
}

if(aboutItemArray[dropObj.value].visiblePage==1){
myRadios[1].checked=true;
}

for the graphics, you'll need to include the necessary path information for the image.src property.

Code:
AboutGraphic.src="../content/about/" + aboutItemArray[dropObj.value].aboutGraphic;

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
hi! sorry for my late reply ive been busy a few days, but the code was exactely what i was been looking for to make an if statement for my radios and a var for my graphic.
im sure the code works flawlessly , thank you so much!

i will try it out later and get back later to keep you feedback ;).


 
@vacunita .. it works great i have now my edit form setup for loading my dynamic data. now is my question ... can i use php or should i use js for having an image selected trough browse and then subit it with all the other input data , then send it back to mysql with just this one page ? im thinking how to do this but its in php...:

Code:
// my from , the same as the old one just added [red]enctype="multipart/form-data[/red] :

 <form name="aboutForm" method="POST" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data">

Code:
<?php
// upload image 
if ($_FILES["aboutGraphic"]["error"] > 0)
  {
  echo "Error: " . $_FILES["aboutGraphic"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["aboutGraphic"]["name"] . "<br />";
  echo "Type: " . $_FILES["aboutGraphic"]["type"] . "<br />";
  echo "Size: " . ($_FILES["aboutGraphic"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["aboutGraphic"]["tmp_name"];
  }
?>

Code:
<?php
// save uploaded aboutGraphic to tmp_name on server

if ((($_FILES["aboutGraphic"]["type"] == "image/gif")
|| ($_FILES["aboutGraphic"]["type"] == "image/jpeg")
|| ($_FILES["aboutGraphic"]["type"] == "image/pjpeg"))
&& ($_FILES["aboutGraphic"]["size"] < 250000))
    //250KB max
  {
  if ($_FILES["aboutGraphic"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["aboutGraphic"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["aboutGraphic"]["name"] . "<br />";
    echo "Type: " . $_FILES["aboutGraphic"]["type"] . "<br />";
    echo "Size: " . ($_FILES["aboutGraphic"]["size"] / 1024) . " Kb<br />";
    echo "Temp aboutGraphic: " . $_FILES["aboutGraphic"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["aboutGraphic"]["name"]))
      {
      echo $_FILES["aboutGraphic"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["aboutGraphic"]["tmp_name"],
      "upload/" . $_FILES["aboutGraphic"]["name"]);
      echo "Stored in: " . "../content/about/" . $_FILES["aboutGraphic"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>



is this a good approach? its pure php and it will upload the image to the folder "../content/about/ if it doesnt exists then page uploads it to my server folder but i also want the filename from the aboutGraphic (example: about_1.png) to be stored as text into the row aboutGraphic database field aboutGraphic so i dont need to make a extra field. will it work? and if so i need it to be javascript so i can use other values of the form aswell. ( aboutTitle etc..) when i hit the submit button
 
Not sure I understand. You are uploading a file. Javascript can't do anything about it, it can't upload files in any way. That's all the browser, and the server side script that receives the file.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
ok i see, what i want to have is now the form displays all the data from the database fields into the inputs and also displaying the graphic. i have an upload input and a browse button.
Code:
<input name="aboutUpload" type="text" class="aboutUpload" id="aboutUpload" value="" />
			  
<input name="Button" type="button" class="Browse" id="Browse" value="Browse File" />

when i click the browse button i want to be able to select a file then click "ok", so it will display the the selected file name in the aboutUpload field but NOT yet uploaded. it will upload if the form is submitted. i want to implement this into the current array so i can have everyting working , sending my input value and picture to the server and update the db. basiacally its a simple form. what do you tihnk i should do to achieve this? so far im almost there accept the file upload part. that will send the variables from that page (edit_about.php, this is what i am trying to get working since i started this toppic). directely in the the mysql db.

some of my other pages i have done with a var reciving file but i think this is much more convenient this way. so i came up with the idea of having drop downs and 1 form for taking data out of the db and put it back after i change it.
make sence vacunita?
 
Unfortunately its not possible. due to security features, you have no way of knowing the actual path to the file being uploaded to be able to set it as the image src. That's because web sites should not be messing around with the clients file system.

Imagine the nightmare it would be If websites could simply ask you for a file and then be able to access the file system unrestricted.

You best bet is to just have a pre-made (image-changed) icon so when the user changes the graphic you can show that icon in place of the image until its uploaded.


some of my other pages i have done with a var reciving file but i think this is much more convenient this way. so i came up with the idea of having drop downs and 1 form for taking data out of the db and put it back after i change it.
That's a good approach. It should work as long as you know what needs to be changed, and that all the data is still consistent.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
hmm, im not sur eif you understood what i ment.
i have drew a picture about what im trying to achieve.
i actually dont want the users path but i want to get the picture name + extention ( example about_1.png ) and have the name put back into the jsArr so i process it back the the server as text, and also have the picture been uploaded in ../content/about/

, can you follow what i try to explain. ;)
obviously im not a native english speaker but i am trying to do my best haha. sorry about that.
 
 http://www.mediafire.com/?xdko5h15knmoz9n
i think you though that i wanted to have a page acces my local harddisk to display this picture on the page in runtime or something. but thats not what i want coz i know about those risks. still thanks for the notice about that. I only thought if there is a way i can grab the picturename+extentoin , put that into the array jsArr and submit it as text into the db aboutGraphic field and also have the picture been uploaded. i think my picture i upped helped out understand what i mean.

 
Oh, I see now. The js array will be a one way deal. It gets its data from the DB only. So your form submission and PHP should take care of putting it back into the DB. Where it can be retrieved again fvor the array and the dropdown.

In other words, the Js array is only used by Js, and Js can't access the server's DB.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
ok :( hahah so how can i achieve this.. can you lend me a hand once more please.. not all im just diying to get this webby to work so i use it hehe.
 
Basically you'll want to take the values from your form now in PHP and craft your insert query.

Code:
[green]//Check that the form has been submitted[/green]
if(isset($_POST['submit'])){
$val_aboutId=mysql_real_escape_string($_POST['aboutSelect']);
$val_aboutTitle=mysql_real_escape_string($_POST['aboutTitle']);
$val_aboutStory=mysql_real_escape_string($_POST['aboutStory']);
...
$sql="UPDATE mytablename SET aboutTitle=$val_aboutTitle, aboutStory=$val_aboutStory, ... WHERE aboutId=$val_aboutId";
$res=mysql_query($sql);

}


For more specific advice about the PHP side of things, forum434 may be a good place to ask.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
i know how to update the page basically i do the same as i did my other page. the only thing is when updating it it updates the wrong id from the db.
Code:
 <input name="aboutId" type="hidden" id="aboutId" value="<?php echo $row_rsAbout['aboutId']; ?>" />
         <input type="hidden" name="MM_update" value="aboutForm" />

this is a problem coz the fields are done by JS and i need to have the hidden aboutId value been processed by php with the CURRENT selected id from the dropdown. so instrad of :

<input name="aboutId" type="hidden" id="aboutId" value="<?php echo $row_rsAbout['aboutId']; ?>" />
<input type="hidden" name="MM_update" value="aboutForm" />

i should have:

<input name="aboutId" type="hidden" id="aboutId" value="the_cyrrent_id_from_DD" />

coz if i use it like above it will take the id nr1 of the db. no matter what item i choose in the dropdown ...

 
Just use the Id from the select box, instead of your hidden input, which is now pretty useless.

$_POST['aboutSelect'] now holds that ID.

Alternatively, you could set the ID of the hidden field along with everything else in the JS.
Code:
var hidden_aboutId=document.getElementById('aboutId');
        ...
        hidden_aboutId.value=dropObj.value



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top