Jump to content

Form Help


herghost

Recommended Posts

Hi All,

 

I am not sure if this is an HTML or PHP question but thought I would try in here first:

 

I have this

 

<form id="banddisco" name="banddisco" method="post" action="do/banddiscodo.php">

  <table border="0">
  <tr>
    <td width="216">Album Name</td>
    <td width="216"><input name="albumname" type="text" id="albumname" size="60"></td>
  </tr>
  <tr>
    <tr>
    <td width="216" valign="top">Tracks Names (One Per Line)</td>
    <td width="216"><textarea name="tracks" cols="60" rows="30" id="tracks"></textarea></td>
  </tr>
  

</table>


  <br />
  <br />

		        
			    
  <input type="submit"  name="Submit" value="Go" />
</form>

 

Which is a simple form for entering an albbum name and then the tracks. Is it possibe to add a line break at the end of each line in the tracks field? Basically when echoed from the database I want them one line after another.

 

Cheers

Link to comment
Share on other sites

What gnawz is saying on using the n tag, is when you echo, use "\n" to create a new line.

 

When printing out each row, use the \n character in double quotes:

foreach ( $track_names_array as $value ) {
echo $value . "\n";
}

 

This way will have a result of :

 

sometrack

another track

Beetles Track

 

The text area will have line breaks.

 

I hope this is what you are looking for.

Link to comment
Share on other sites

Ok, so I am currently showing the results like so:

 

<?php 

$sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10";
$result = mysql_query($sql ,$con);
while($myrow = mysql_fetch_array($result))
{

echo "<table width ='90%'>";
echo "<tr>";
echo "<td>";
echo  $myrow['albumname'];
echo "</td>";
echo "<td>";
echo  $myrow['tracks'];
echo "</td>";


echo "</table>";
}
?></p>

 

and they are being stored in a database like so:

 

<?php
   //Start session
   session_start();
   
   //Include database connection details
   require_once('../include/database.php');
   
   //Array to store validation errors
   $errmsg_arr = array();
   
   //Validation error flag
   $errflag = false;
   
   
   //Function to sanitize values received from the form. Prevents SQL injection
   function clean($str) {
      $str = @trim($str);
      if(get_magic_quotes_gpc()) {
         $str = stripslashes($str);
      }
      return mysql_real_escape_string($str);
   }
   
   //Sanitize the POST values
   $userid = $_SESSION['SESS_USERID'];
   $albumname = clean($_POST['albumname']);
   $tracks = clean($_POST['tracks']);
  
   
   
   $sql = mysql_query("SELECT * FROM banddisco WHERE userid = '$userid'");
if(mysql_num_rows($sql) == 0)
{
   //Create INSERT query
   $qry = "INSERT INTO banddisco
   (userid, albumno, albumname, tracks) 
   
   VALUES
   ('$userid', '', '$albumname', '$tracks')";
}


   
    $result = mysql_query($qry) or die(mysql_error());


   //Check whether the query was successful or not
   if($result) {
      header("location: ../member_home.php?disco=1");
      exit();
   }else {
      die(mysql_error());
      
   }
   
   ?>

 

What would I have to do to save them to an array so I can display using /n?

 

Guess this has moved to an php question now!

Link to comment
Share on other sites

<?php
session_start();

include('include/database.php');
$userid = $_GET['userid'];
$_SESSION['bandid'] = $userid;
?>

<?php 

$sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10";
$result = mysql_query($sql ,$con);
while($myrow = mysql_fetch_array($result))
{

echo "<table width ='90%'>";
echo "<tr>";
echo "<td>";
echo  $myrow['albumname'];
echo  "\n";
echo "</td>";
echo "<td>";
echo  $myrow['tracks'];
echo  "\n";
echo "</td>";


echo "</table>";
}
?></p>

 

Table in loop? Gap in my knowledge I think!

Link to comment
Share on other sites

Something like:

 

echo '<br><h5>These are your results</h5></br>';//showing featured listings		
	echo '<table border=1 table width="980" align="center">'; 
	echo "<tr>"; 
	$count = 5;//rows
	$l = 0;
		for($i=0;$i<mysql_num_fields($listing);$i++) 
		{ 
			echo "<th>"; 
			echo mysql_field_name($listing, $i); 			
			echo "</th>";
		} 

		while($l < $count) 
		{ 
		$row=mysql_fetch_row($listing);
			echo "<tr>"; 
			for($j=0;$j<$i;$j++) 

			{ 

			echo "<td>"; 
			echo $row[$j]; 
			echo "</td>"; 
			} 
			echo "</tr>"; 
			$l++;
		} 


	echo "</tr>"; 
	echo "</table>"; 

 

 

////////OR

 

echo '<table border = "1" bordercolor="#000000">';
  			echo '<tr>';
			//displaying the headings
		echo '</tr>';
		echo '<tr>';
			echo '<td width="20" height="20">';
				echo '<b>Fld1</b>';
			echo '</td>';
			echo '<td width="20" height="20">';
				echo '<b>Fld2</b>';
			echo '</td>';
			echo '<td width="20" height="20">';
				echo '<b>Fld3</b>';
			echo '</td>';
			echo '<td width="20" height="20">';
				echo '<b>Fld4</b>';
			echo '</td>';
			echo '<td width="20" height="20">';
				echo '<b>Fld5</b>';
			echo '</td>';
			echo '<td width="20" height="20">';
				echo '<b>Fld6</b>';
			echo '</td>';
		echo '</tr>';
	//getting the database fields
      while($row = mysql_fetch_array($query))
  		  {
		echo '<tr>';
			echo '<td>';
				$name = $row["Fld1"];
				echo $name. "<br>";
			echo '</td>';
			echo '<td>';
				$add = $row["Fld2"];
				echo $add. "<br>";
			echo '</td>';
			echo '<td>';
				$email = $row["Fld3"];
				echo $email. "<br>";
			echo '</td>';
			echo '<td>';
				$web = $row["Fld4"];
				echo ('<b><a href="'.$web.'">'.$web.'</a></b>');
			echo '</td>';
			echo '<td>';
				$tel = $row["Fld5"];
				echo $tel. "<br>";
			echo '</td>';
			echo '<td>';
				$loca = $row["Fld6"];
				echo $loca. "<br>";
			echo '</td>';
			echo '<td>';
		  }
  		echo '</table><br/>';
	}				

 

Hope it helps....

Link to comment
Share on other sites

Thanks,

 

I have this error:

 

These are your results


Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 41

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50

 

and this is my code

 

<?php
session_start();

include('include/database.php');
$userid = $_GET['userid'];
$_SESSION['bandid'] = $userid;
?>



//$sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10";
//$result = mysql_query($sql ,$con);
//while($myrow = mysql_fetch_array($result))
//{

//echo "<table width ='90%'>";
//echo "<tr>";
//echo "<td>";
//echo  $myrow['albumname'];
//echo  "\n";
//echo "</td>";
//echo "<td>";
//echo  $myrow['tracks'];
//echo  "\n";
//echo "</td>";


//echo "</table>";
//}
//

<?php

$sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10";
$result = mysql_query($sql ,$con);
echo '<br><h5>These are your results</h5></br>';//showing featured listings      
      echo '<table border=1 table width="980" align="center">';
      echo "<tr>";
      $count = 5;//rows
      $l = 0;
         for($i=0;$i<mysql_num_fields($userid);$i++)
         {
            echo "<th>";
            echo mysql_field_name($userid, $i);          
            echo "</th>";
         }
            
         while($l < $count)
         {
         $row=mysql_fetch_row($userid);
            echo "<tr>";
            for($j=0;$j<$i;$j++)
            
            {
            
            echo "<td>";
            echo $row[$j];
            echo "</td>";
            }
            echo "</tr>";
            $l++;
         }
         
         
      echo "</tr>";
      echo "</table>"; ?>

Link to comment
Share on other sites

Ignore Aove!

 

I have now had a long overdue brainwave and have this:

 

<?php

$sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10";
$result = mysql_query($sql ,$con);

echo '<br><h5>These are your results</h5></br>';//showing featured listings      
      echo '<table border=1 table width="980" align="center">';
      echo "<tr>";
      $count = 5;//rows
      $l = 0;
         for($i=0;$i<mysql_num_fields($result);$i++)
         {
            echo "<th>";
            echo mysql_field_name($result, $i);          
            echo "</th>";
         }
            
         while($l < $count)
         {
         $row=mysql_fetch_row($result);
            echo "<tr>";
            for($j=0;$j<$i;$j++)
            
            {
            
            echo "<td>";
            echo $row[$j];
            echo "</td>";
            }
            echo "</tr>";
            $l++;
         }
         
         
      echo "</tr>";
      echo "</table>"; ?>

 

However it still lists the tracks one after another and not on a seperate line, as well as displaying all the fields in the database. I can I get it to display just the fields `album` and `tracks`, with the tracks one per line?

 

Cheers

Link to comment
Share on other sites

/n only creates a new linebreak in the source - not necessarily the final image.

 

Html is non-white-space sensitive. You could format Hello like this:

 

<!-- HTML -->

H

e

l

l

o

<!-- End of HTML -->

 

And you still get: Hello.

 

To create a linebreak in html/final image, use a <br />

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.