I'am Generating a PDF with the help oh HTML and PHP. But the text in textarea in getting overflowed. The text in printing only in a single line.
My HTML Code is
<html>
<head>
<title>registration form</title>
</head>
<h2 ALIGN="CENTER">Registration form</h2>
<form action="pro1.php" method="post">
<table border="0" align="center">
<tbody>
<tr>
<td><label for="id">Id: </label></td>
<td><input id="id" maxlength="50" name="name" type="text" /></td>
</tr>
<tr>
<td><label for="name">Name: </label></td>
<td><input id="name" maxlength="50" name="name" type="text" /></td>
</tr>
<tr>
<td><label for="course">Course: </label></td>
<td><input id="course" maxlength="50" name="course" type="text" /></td>
</tr>
<tr>
<td><label for="branch">Branch: </label></td>
<td><input id="branch" maxlength="50" name="branch" type="text" /></td>
</tr>
<tr>
<td><label for="rolln0">Rollno: </label></td>
<td><input id="rollno" maxlength="50" name="rollno" type="text" /></td>
</tr>
<tr>
<td><label for="email">Email_Address:</label></td>
<td><input id="email" maxlength="50" name="email" type="text" /></td>
</tr>
<tr>
<td><label for="username">User_Name:</label></td>
<td><input id="username" maxlength="50" name="username" type="text" /></td>
</tr>
<tr>
<td><label for="aboutus">About Us:</label></td>
<td valign="middle" align="center"><textarea wrap="wrap" rows ="1" cols ="1" name = "aboutus"></textarea></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input id="password" maxlength="50" name="password"
type="password" /></td>
</tr>
<tr>
<td align="right"><input name="Submit" type="Submit" value="Add" /></td>
</tr>
</tbody>
</table>
</form>
</html>
and my PHP Code is
require('fpdf/fpdf.php');
$pdf = new FPDF();
//var_dump(get_class_methods($pdf));
$pdf -> AddPage();
$pdf->SetFont("Arial","B",16);
$pdf->Cell(0,10,"Welcome {$pro_name}",1,1);
$pdf->Cell(50,10,"Name: ",1,0);
$pdf->Cell(50,10,$pro_name,1,1);
$pdf->Cell(50,10,"Branch: ",1,0);
$pdf->Cell(50,10,$pro_branch,1,1);
$pdf->Cell(50,10,"Roll No: ",1,0);
$pdf->Cell(50,10,$pro_rollno,1,1);
$pdf->Cell(50,10,"Email: ",1,0);
$pdf->Cell(50,10,$pro_email,1,1);
$pdf->Cell(50,10,"About Us: ",1,0);
$pdf->Cell(50,10,$pro_aboutus,1,1);
$pdf->output();
}
?>
please help me, and tell me what should i do so that my text area prints within the a4. Thank You In Advance
Use MultiCell rather than Cell.
As it says, "This method allows printing text with line breaks."
Example:
$this->MultiCell(60,5,$txt);
Full example here
MultiCell documentation here
Related
I am trying to make a sign-up form where a user enters their name into a time slot. Then the names are saved into a text file but it is not being saved into the text file.
HTML form party
<form action="writeit.php" method="POST" name="nameform">
<table style="width:20%">
<tr>
<th>Time</th>
<th colspan="2">Name</th>
</tr>
<tr>
<td>8:00am</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>9:00am</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>10:00am</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>11:00am</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>12:00pm</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>1:00pm</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>2:00pm</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>3:00pm</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>4:00pm</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>5:00pm</td>
<td><input type="text" name="name" id="name"></td>
</tr>
</table>
<br></br>
<input type="submit" name="submit" value="Save">
</form>
the writeit.php file
<?php
$names = $_POST['name'];
$filename = "signup.txt";
$file = fopen($filename, "a");
fwrite($file, $names);
fclose($file);
?>
I have my login table in mysql is like this
id
fname
lname
email
contactno
userid
password
acctype
status
Now my form is like this
<form name="frm" method="post" action="registerform.php">
<table id="new-account" class="create-an-account" width="100%" border="1" cellspacing="10px" cellpadding="10px">
<tr>
<td width="45%">
<label for="firstname">First Name</label>
<input type="text" style="width:230px;" name="Firstname" id="Firstname" /></td>
<td width="10%"></td>
<td width="45%">
<label for="lastname">Last Name:</label>
<input type="text" style="width:230px;" name="LastName" id="LastName" />
</td>
</tr>
<tr>
<td>
<label for="">Account Type</label>
<select class="select" name="at" id="ValidSelection" style="width:245px;" >
<option value="0">Select Account Type</option>
<option value="agent">agent</option>
<option value="admin">admin</option>
</select>
</td>
</tr>
<tr>
<td><label for="">Email Id:</label></td>
</tr>
<tr>
<td><input type="text" name="email" id="ValidEmail" style="width:230px;"/></td>
</tr>
<tr>
<td><label for="">Contact Number</label></td>
</tr>
<tr>
<td><input type="text" name="contact" id="ValidNumber" style="width:230px" /></td>
</tr>
<tr>
<td><label for=""><strong>Choose Your Login Id:</strong></label>
<input type="text" style="width:230px;" name="LoginId" id="LoginId"/>
</td>
</tr>
<tr>
<td><label for=""><strong>Password: <br /></strong></label></td>
</tr>
<tr>
<td><input type="password" style="width:230px;" name="Password" id="ValidPassword" /></td>
</tr>
<tr>
<td><label for="">Confirm Password:</label></td>
</tr>
<tr>
<td>
<input type="password" style="width:230px;" name="ConfirmPassword" id="ValidConfirmPassword"
/>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="signup" value="Create Account" style="margin-top:20px" /></td>
</tr>
</table>
and for insert data my php code is like this
<?php
if(isset($_REQUEST['signup'])) {
mysql_query("insert into login (`fname`,`lname`,`email`,`contactno`,`userid`,`password`,`acctype`,`status`) values('".$_REQUEST['Firstname']."','".$_REQUEST['LastName']."','".$_REQUEST['email']."','".$_REQUEST['contact']."','".$_REQUEST['LoginId']."','".$pswd."','".$_REQUEST['at']."','active')");
}
?>
Now here when I am reloading the page it is automatically inserting the last entered values to the database. So here can someone kindly tell me what is the issue here? Any help and suggestions are welcome.
If you reload the page after submitting a form, it will keep the POST data. To solve this follow the below things :
You can redirect to some other page after inserting the data, use header("location:new_page.php")
You can unset REQUEST, use unset($_REQUEST) after insert
after inserting the $_POST data use redirect to avoid this situation .
even you can redirect to same page like this :-
header('Location: '.$_SERVER['PHP_SELF']);
exit;
I have recently created a contact form with PHP mailer which is finally working. However the success message is breaking my page and displaying in the top left corner instead of underneath the form. As you can see below.
This is the HTML:
<form method="POST">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="number" type="text" autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example#domain.com" autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
</table>
<input type="submit" value="Submit" name="submit">
<?php
if ($success) {
echo $success;
}
?>
</form>
It also creates a huge blank white area in the middle of my page under the form. Does anyone know why this is? or how I would go about debugging it?
You should put this in a div or a span
<div style="text-align:center;"> <?php
if ($success) {
echo $success;
}
?>
</div>
Try following code:
<form method="POST">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="number" type="text" autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example#domain.com" autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
<?php
if ($success) {?>
<tr><td colspan="2">
<?php echo $success; ?>
</td></tr>
<?php }
?>
</table>
<input type="submit" value="Submit" name="submit">
</form>
I'm new to PHP and after looking on the web for the last hour I couldn't find out what was wrong with my code so I come to you. Im trying to have a place to update my data collected from a from. I get this error. Undefined index: id in /Users/mm1/Desktop/php/backend form/edit_ac.php on line 12. Here is what I have so far. Can someone please help..
<?php require("database.php"); ?>
<?php require("functions.php"); ?>
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$id= mysql_prep($_GET['id']);
$last= mysql_prep($_POST['last']);
$first= mysql_prep($_POST['first']);
// update data in mysql database
$sql="UPDATE $tbl_name SET first='{$first}', last='{$last}' WHERE id='{$id}'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='edit_info.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
Here is the form (I know it all isn't complete I'm just trying to get it to work first.)
<?php require("database.php"); ?>
<?php // Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<form name="form1" method="post" action="edit_ac.php">
<table width="700" border="0" cellpadding="5">
<tr>
<td colspan="2" class="center"><h3>PARTICIPANT IDENTIFICATION</h3></td>
</tr>
<tr>
<td width="218">First</td>
<td width="456"><input name="first" type="text" maxlength="50" id="first" value="<? echo $rows['first']; ?>" /></td>
</tr>
<tr>
<td width="218">Last</td>
<td width="456"><input name="last" type="text" maxlength="50" id="last" value="<? echo $rows['last']; ?>" /></td>
</tr>
<tr>
<td width="218">Middles</td>
<td width="456"><input name="middle" type="text" maxlength="50" id="middle" value="<? echo $rows['middle']; ?>"/></td>
</tr>
<tr>
<td>Address</td>
<td><input name="address" type="text" maxlength="50" id="address" value="<? echo $rows['address']; ?>"/></td>
</tr>
<tr>
<td>City</td>
<td><input name="city" type="text" maxlength="50" id="city" value="<? echo $rows['city']; ?>"/></td>
</tr>
<tr>
<td>State</td>
<td><input name="state" type="text" maxlength="15" id="state" value="<? echo $rows['state']; ?>"/></td>
</tr>
<tr>
<td>Zip</td>
<td><input name="zip" type="text" maxlength="15" id="zip" value="<? echo $rows['zip']; ?>" /></td>
</tr>
<tr>
<td>Home Phone</td>
<td><input name="home_phone" type="text" id="home_phone" value="<? echo $rows['home_phone']; ?>" /></td>
</tr>
<tr>
<td>Daytime Phone</td>
<td><input name="daytime_phone" type="text" id="daytime_phone" value="<? echo $rows['daytime_phone']; ?>" /></td>
</tr>
<tr>
<td>Email Address</td>
<td><input name="email_address" type="text" id="email_address" value="<? echo $rows['email_address']; ?>" /></td>
</tr>
<tr>
<td>Birthday</td>
<td><input name="month" type="text" id="month" size="3" maxlength="2" value=""/> / <input name="day" type="text" id="day" size="3" maxlength="2" value=""/> / <input name="year" type="text" id="year" size="5" maxlength="4" value=""/></td>
</tr>
<tr>
<td>Social Security Number</td>
<td><input name="ss_1" type="text" id="ss_1" size="5" maxlength="3" value=""/> - <input name="ss_2" type="text" id="ss_2" size="5" maxlength="2" value=""/> - <input name="ss_3" type="text" id="ss_3" size="5" maxlength="4" value="" /></td>
</tr>
<tr>
<td colspan="2" class="center"><h3>PHOTO IDENTIFICATION </h3></td>
</tr>
<tr>
<td>Type of ID</td>
<td>
<input type="text" name="type_of_id" id="type_of_id" value=""/></td>
</tr>
<tr>
<td>ID Number</td>
<td>
<input type="text" name="id_number" id="id_number" value="" /></td>
</tr>
<tr>
<td>Issuing Jurisdiction</td>
<td><input type="text" name="issuing_state" id="issuing_state" value=""/></td>
</tr>
<tr>
<td>Expiration Date</td>
<td><input type="text" name="expiration_date" id="expiration_date" value=""/></td>
</tr>
<tr>
<td>Issue Date</td>
<td><input type="text" name="issue_date" id="issue_date" value="" /></td>
</tr>
<tr>
<td colspan="2" class="center"><h3>ESTABLISHING YOUR ACCOUNT</h3></td>
</tr>
<tr>
<td colspan="2" class="center">Designate Account Type</td>
</tr>
<tr>
<td>
Acount Type
</td>
<td>
<label>
<input type="radio" name="traditional" value="1" id="traditional" />
Traditional</label>
<br />
<label>
<input type="radio" name="roth" value="1" id="roth" />
Roth</label>
<br />
<label>
<input type="radio" name="sep" value="1" id="sep" />
SEP</label>
<br />
<label>
<input type="radio" name="simple" value="1" id="simple" />
SIMPLE</label>
<br /></td>
</tr>
<tr>
<td colspan="2" class="center">Fund Your Account</td>
</tr>
<tr>
<td colspan="2"><input name="rollover" type="radio" value="1" id="rollover" />I will rollover cash from an existing IRA or qualified retirement plan
</td>
</tr>
<tr>
<td>Prior Custodian Plan Name</td>
<td><input name="prior_plan_name" type="text" maxlength="50" id="prior_plan_name" value=""/></td>
</tr>
<tr>
<td>Expected Rollover Amount</td>
<td><input name="rollover_amount" type="text" maxlength="50" id="rollover_amount" value=""/></td>
</tr>
<tr>
<td colspan="2"><input name="transfer" type="radio" value="1" id="transfer" /> I will transfer assets from another IRA and have attached a TRANSFER AUTHORIZATION form </td>
</tr>
<tr>
<td colspan="2"><input name="contribution" type="radio" value="1" id="contribution"/> I have attached a contribution check as follows</td>
</tr>
<tr>
<td>IRA Cash Contribution for the Year</td>
<td><input name="cash_contributions_1" type="text" id="cash_contributions_1" value=""/></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_1" type="text" id="amount_1" value=""/></td>
</tr>
<tr>
<td>IRA Cash Contribution for the Year</td>
<td><input name="cash_contributions_2" type="text" id="cash_contributions_2" value="" /></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_2" type="text" id="amount_2" value="" /></td>
</tr>
<tr>
<td>Employer OR Employee (circle one) SEP/SIMPLE Contribution for the Year</td>
<td><input name="employer_contributions" type="text" id="employer_contributions" value="" /></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_3" type="text" id="amount_3" value="" /></td>
</tr>
<tr>
<td></td>
<td style="text-align:right"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</table>
<?php
// close connection
mysql_close();
?>
Add the id into the form as a hidden field.
<input type="hidden" name="id" value="<?php print $rows['id'] ?>">
An undefined index simply means that the index of a certain array doesn't exist. So in this case $_GET has not index of id.
Perhaps you should be checking if the variables are set before anything.
if(!empty($_GET['id']) && !empty($_POST['last']) && !empty($_POST['first'])){
// other code
}
You may also be using the wrong superglobal, like GeoPhoenix said, are you sure it's not $_POST['id'] you're looking for?
If you aren't including the parameters in the call to the page you are getting errors because you turned error reporting all the way up in the first few lines:
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
Often PHP (and therefore PHP tutorials) assume a lower setting where PHP will either throw a warning or ignore index errors on arrays. Therefore when you hit:
$id= mysql_prep($_GET['id']);
$last= mysql_prep($_POST['last']);
$first= mysql_prep($_POST['first']);
It throws an error, but your references might assume it fails quietly.
Your form appears to provide the ID number in the id_number instead of just id. So switching to $id=mysql_prep($_GET['id_number']); is likely to get more effective results.
Since you are new to PHP I also strongly suggest changing your PHP library away from the old mysql lib to either mysqli or PDO. Changes people are suggesting will likley get you the results you expect but not fix the multiple SQL Injection vulnerabilities this script has.
I don't see anything in your form that has the name "id".
If your using $_get['id'] you must have a link or submit button that tranfers to a url that looks like this.
<a href="phpfile.php?id=PUT_VALUE_HERE>
Notice the url has the variable name id after the question mark and you tell what the variable is after the =.
Otherwise if your not going to put your variable in a url. You use $_POST['id'].
In order for $_POST['id'] to work you need an input in your form that has the name attribute set to id. For example
<input name="id" type="text">
I do not see anything in your form with a name attribute set to "id".
some of my code in addUser.php it pure html
addUser.php
<form action="process/addNewUser.php" method="POST" id="userForm">
<table width="79%" border="0" cellspacing="6" cellpadding="1"
class="tabcont">
<tr>
<td width="47%" align="right">Title:</td>
<td width="53%">
<select name="title"><option value='0'>- - select - -</option>
</select>
</td>
</tr>
<tr>
<td width="47%" align="right">
First Name:</td>
<td width="53%"><input type="text" id="firstname" name="firstName" class="required" /></td>
</tr>
<tr>
<td align="right">Middle Name:</td>
<td><input type="text" id="middlename" name="middleName" class="name" /></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input name="password" value="" readonly="readonly"
id="password" class="required" " /></td>
</tr>
<tr>
<td align="right" colspan="2">
<input name="addNewUser" type="submit" class="submit" id="submit" value="Submit" />
</td>
</tr>
</table>
</form>
addNewUser.php
Here i am doing validations and displaying error messages and if it is success sending him to another page.
But i want to show an error message on addUser.php instead of validations page. Please give me a sample code how i can do it.
addNewUser.php
Add the message in the session
$_SESSION["ErrorMsg"]="Name already exists";
And in your addUser.php , you put the following code in the place you need to show the msg :
if($_SESSION["ErrorMsg"])
{
echo $_SESSION["ErrorMsg"];
$_SESSION["ErrorMsg"]="";
}