Textbox problem with onclick # - php

I'm just trying to display a table in client side from database as a distinct value from every column. Here i have fetched the value by using "select distinct ...." code and put this value in a single textbox
here is the code...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function onClick()
{
alert(document.form.thirdparty.value);
}
</script>
</head>
<body>
<p> </p>
<form name="form" method="get" >
<?php
$con=mysql_connect('localhost','root','');
mysql_select_db('database',$con);
$res = mysql_query("SELECT count(*) as count FROM tablename") or die(mysql_error());
while ($row = mysql_fetch_array($res)) {
$val=$row['count'];
} ?>
<input name="fino" type="text" id="fino" size="5" value="<?php echo $val." docs" ?>" style="border-style:hidden; color:#0083fa;" />
<table width="1474" height="270" border="0" >
<tr>
<td width="180" height="41">
<input name="Item" type="DocumentType" id="textfield5" value="    Item"size="30" /> </td>
<td width="180" height="41">
<label>
<td width="180" height="41"> <input type="text" name="textfield8" id="textfield8" style="visibility:hidden" /></td>
</label>
<label>
<td width="180" height="41"> <input type="text" name="textfield9" id="textfield9" style="visibility:hidden"/></td>
</label>
</td>
</tr>
<tr>
<td>
<?php
$a=mysql_query("select distinct language from tablename");
$c=0;
$i=1;
$x=1;
while($row = mysql_fetch_array($a))
{
$b=$row['language'];
$i=$b;
$d=mysql_query("select count(*) as count from tablename where language='$i' ");
while ($row = mysql_fetch_array($d)) {
$e=$row['count'];
$cal=round(($e/$val)*100);
}
?>
//in this textbox am using onclick function
<input type="text" size="30" style="height:<?php echo $cal.px?>"value="<?php echo "$i"." "." "." "."$e"." docs" ?>"name="language" id="textfield"onClick="onClick();" />
<?php
$i++;
$c++;
}
?> </td>
<td>
<?php
$con=mysql_connect('localhost','root','');
mysql_select_db('database',$con);
$a1=mysql_query("select distinct Subject from tablename");
$c1=0;
$i1=1;
while($row = mysql_fetch_array($a1))
{
$b1=$row['Subject'];
$i1=$b1;
$d1=mysql_query("select count(*) as count from tablename where Subject='$i1' ");
while ($row = mysql_fetch_array($d1)) {
$e1=$row['count'];
$cal1=round(($e1/$val)*100);
}
?>
<input type="text" size="30" style="height:<?php echo $cal1.px?>" value="<?php echo "$i1"." "." "." "."$e1"." docs" ?>"name="item" id="textfield2" />
<?php
$i++;
$c++;
}
?> </td>
<td>
<label>
<td> <input type="text" name="textfield12" id="textfield12" style="visibility:hidden" /></td>
</label>
<label>
<td> <input type="text" name="textfield13" id="textfield13" style="visibility:hidden" /></td>
</label>
<label>
<td> <input type="text" name="textfield14" id="textfield14" style="visibility:hidden" /></td>
</label>
<label>
<td> <input type="text" name="textfield15" id="textfield15" style="visibility:hidden" /> </td>
</label>
</form>
</td>
</tr>
</table>
<blockquote>
<p align="center"> </p>
</blockquote>
</body>
</html>

EDIT:
The following is a sample where the value of the textbox is displayed in an alert box.
As the others have said, cannot suggest anything other than this without seeing code.
Example
<input type = 'text' id = 'myTextBox' onclick='alert(this.value)' />

First don't call your function onclick better name is something like LanguageClick.
Second, don't give same id to all elements.. if you don't have real use for it just omit the ID it won't break anything.
Third, proper event is onfocus as user can reach the textbox by pressing Tab key, which won't trigger the click event.
Code would look like this:
<input type="text" size="30" style="height:<?php echo $cal.px?>;" value="<?php echo "$i"." "." "." "."$e"." docs" ?>" name="language" onfocus="LanguageClick(this);" />
And the JavaScript code:
function LanguageClick(oTextbox) {
var sValue = oTextbox.value;
alert("You wrote: " + sValue);
}
As you pass this to the function, you have reference to the textbox element and you can read its value property.

Related

Use php to insert drop select form element

I am attempting to create a drop down box with php that pulls states from an array that is populated with state names. I have saved my file with the .php extension and have added code to attempt to create a drop down menu from my array that I am creating. For some reason, the drop down menu is not working.
<!DOCTYPE html>
<html>
<head>
<style>
</style>
<script type="text/javascript">
//create function to be called upon submission
function verify(event) {
var hasError = false;
var check1=document.getElementById("saws").value;
var check2=document.getElementById("pliers").value;
var check3=document.getElementById("planers").value;
var ok = [];
ok[0] = check1.search(/^$|\d+/);
ok[1] = check2.search(/^$|\d+/);
ok[2] = check3.search(/^$|\d+/);
for (i = 0; i < ok.length; i++) {
if (ok[i] !== 0) {
hasError = true;
alert("Invalid input.");
event.preventDefault();
}
}
if (hasError) return false;
else return true;
}
</script>
<title>l6p2</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
</head>
<body>
<h1>Lab 6, part 2 </h1>
<form action = "/formtest.php" method="post" onsubmit= "return verify(event)">
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody id="tbody">
<tr>
<td>Saw</td>
<td>$15.99</td>
<td><input type="text" name="saws" id="saws" size="2" /></td>
</tr>
<tr>
<td>Pliers</td>
<td>$12.99</td>
<td><input type="text" name="pliers" id="pliers" size="2" /></td>
</tr>
<tr>
<td>Planer</td>
<td>$79.99</td>
<td><input type="text" name="planers" id="planers" size="2" /></td>
</tr>
</tbody>
</table>
<p>
<label> First Name:
<input type="text" name="fname" size ="30" />
</label>
<br />
<br />
<label> Last Name:
<input type="text" name="lname" size ="30" />
</label>
<br />
<br />
<label> Shipping Address:
<input type="text" name="address" size ="30" />
</label>
<br />
<br />
<label> City:
<input type="text" name="csz" size ="30" />
</label>
<br />
<br />
<?php
$states = array('Alabama','Alaska','Arizona','California','Florida','Georgia');
echo '<label> State:';
echo '<select name="state">';
for ($i = 0; $i < count($states); $i++) {
echo '<option>' . $states[$i] . '</option>';
}
echo '</select>';
echo '</label>';
?>
</p>
<h3>Payment Method</h3>
<p>
<label>
<input type="radio" name="payment" value="visa" checked = "checked" />
Visa
</label>
<label>
<input type="radio" name="payment" value="mc" />
Master Card
</label>
<label>
<input type="radio" name="payment" value="amex" />
American Express
</label>
<br />
</p>
<p>
<input type="Submit" value="Submit Order" />
</p>
</form>
<h3>Links</h3>
Home
</body>
</html>
This is the part that is not working correctly:
<?php
$states = array('Alabama','Alaska','Arizona','California','Florida','Georgia');
echo '<label> State:';
echo '<select name="state">';
for ($i = 0; $i < count($states); $i++) {
echo '<option>' . $states[$i] . '</option>';
}
echo '</select>';
echo '</label>';
?>
Just use a simple foreach in this case:
foreach ($states as $state) {
echo '<option value="'.$state.'">' . $state . '</option>';
}
Your array is basic and doesn't need any special magic to make it work.
I think that the problem is the count on the loop, you need to know the array length, so try the sizeof($states) instead.
for ($i = 0; $i < sizeof($states); $i++) {
Another thing: you had to put some value on the "option" to get that on the back-end side. Like this:
echo '<option value="'.$states[$i].'">' . $states[$i] . '</option>';
And the last: You don`t need to put the "select" inside the "label". You can use the "for" attribute on the label to reference the select id.
This is all the code:
<?php
$states = array('Alabama','Alaska','Arizona','California','Florida','Georgia');
echo '<label for="state"> State: </label>';
echo '<select name="state" id="state">';
for ($i = 0; $i < sizeof($states); $i++) {
echo '<option value="'.$states[$i].'">' . $states[$i] .
'</option>';
}
echo '</select>';
?>
Good luck. :)

Multiple dynamics insert

I have the form below with them I can add more rows to insert more values in the mysql table.
<head>
<link rel="stylesheet" type="text/css" href="css/default.css"/>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<form action="process" class="register" method="POST">
<p>
<input type="button" value="Add Passenger" onClick="addRow('dataTable')" />
<input type="button" value="Remove Passenger" onClick="deleteRow('dataTable')" />
</p>
<table id="dataTable" class="form" border="1">
<tbody>
<tr>
<p>
<td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td>
<td>
<label>Name</label>
<input type="text" required="required" name="BX_NAME[]">
</td>
<td>
<label for="BX_age">Age</label>
<input type="text" required="required" class="small" name="BX_age[]">
</td>
<td>
<label for="BX_gender">Gender</label>
<select id="BX_gender" name="BX_gender[]" required="required">
<option>....</option>
<option>Male</option>
<option>Female</option>
</select>
</td>
<td>
<label for="BX_birth">Berth Pre</label>
<select id="BX_birth" name="BX_birth[]" required="required">
<option>....</option>
<option>Window</option>
<option>No Choice</option>
</select>
</td>
</p>
</tr>
</tbody>
</table>
<div class="clear"></div>
<input class="submit" type="submit" value="Confirm »" />
<div class="clear"></div>
</form>
</body>
Now, I want pass the variable (for example: BX_NAME[]) with two different values to insert.php page:
If I have two rows in the form, How to create the insert?
How to build a php script to crate dynamics insert?
If I got it, you want to inset your rows in database with one query. If no tell me to delete this answer.
You'll get each variable in PHP side with it's index. for example:
chk[0], BX_Name[0], ..., chk[1], BX_Name[1], ...
here you must manage them and generate your query.
$insert = array();
for($i=0; $i < count($_POST['chk']); $i++)
{
$chk = isset($_POST['chk'][$i]) ? $_POST['chk'][$i] : '';
$BX_Name = isset($_POST['BX_Name'][$i]) ? $_POST['BX_Name'][$i] : '';
// instead of '' you must put default value which your db expect
...
$insert[] = "({$chk}, {$BX_Name}, ...)";
}
$values = implode(', ', $insert);
$query = "INSERT INTO `tbl_test` (`chk`, `bx_name`, ...) VALUES $values";
//execute it

Using one form to fill in two other forms

OK so I have two different types of forms and I want to use one form to submit them both. I am using a auto-responder form for form1 fields= first, last and email. My second form is a contact me form fields= name. email and a body field. I am trying to use both these forms at one shot. I have a form that will post fields to each form (INDEX.PHP) the problem is I am not sure how to set up form one to post fields into form1 and form2 the way I want. I want to use the fields that match from form index.php to both the other forms (form1, form2). so name and email will go to both forms and the body field will go to form2. The main form will post first and last in the name field of form2....also as you can see from form 1 and 2 each form has a some sort of redirect page I need to work around.?
I have main form:
Index.php
<html>
<head>
<title>Main Form</title>
</head>
<body>
<h2>Winner Aution Item Request Form</h2>
<p><span class="error"><FONT><font color="red">* required field.</font></span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
First Name: <input type="text" name="first_name" value="<?php echo $first_name;?>">
<FONT><font color="red"> *</font>
<br>
Last Name: <input type="text" name="last_name" value="<?php echo $last_name;?>"> <FONT><font color="red"> *</font>
<br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<FONT><font color="red"> *</font>
<br><br><i><b>Copy and paste auction item name below.</b></i><br>
Product Name: <input type="text" name="product_Name" rows="1" cols="10">
<?php echo $product_Name;?><FONT><font color="red"> *</font>
<input type="Submit" value="Submit" name="submit"></input>
</form>
</body>
</html>
the above form was found on a website and was pretty close to what I want it to do but not exactly....
Form1
<?php session_start(); ?>
<html>
<head>
<title>autoresponder</title>
</head>
<body>
<center>
<table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;">
<tr><td>
<form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
<strong><font color="#660000">Your First Name:</font></strong>
<input type="text" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#660000">Your Last name:</font></strong>
<input type="text" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#000066">Email address:</font></strong><br>
<input type="text" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
<input type="image" src="http://blog.jeremyahenry.com/mailermanager/images/go-button.gif" name="submit" value="Submit"><br>
<input type="hidden" name="r" value="4">
<input type="hidden" name="a" value="sub">
<input type="hidden" name="ref" value="none">
<br>
<font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes
<input type="RADIO" name="h" value="0" checked="checked">No<br>
</font>
</form>
</td></tr>
</table>
</center>
</body>
</html>
Form 2
<?php session_start(); ?>
<html>
<head>
<title>request form</title>
<style>p{font:10pt arial;}</style>
</head>
<body>
<form action="contact_me/process.php" method=post>
<table align=left border=0 height=300>
<tr>
<td nowrap>
<p> Your name:
<input maxlength=25 name=name size=25>
</td>
</tr>
<tr>
<td nowrap>
<p> Your email:
<input name=from size=25 maxlength=25>
</td>
</tr>
<tr>
<td colspan=2>
<center>
<p align=center>Enter your Auction item Name below:
<br>
<textarea cols=50 name=message rows=7></textarea>
<p align=center>
<input type=submit value="Send Message">
<input type=reset value=Reset name="reset">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
ass you can see from the code I was going to use sessions. But not to familiar with it even though I have experience with php I am still quite new to it and need help. I want to pars form data to both forms. and the product name to form two. any help on this would be greatly appreciated.. I hope this is clear enough for some one out there to help.....
Ok New code Three forms 1.main form submits information to form1 and form2.
I have set up using a session so I have: session.php
<?php
session_start();
// store session data
$_SESSION['af_first_name'] = $af_first_name;
$_SESSION['af_last_name'] = $af_last_name;
$_SESSION['af_email'] = $af_email;
$_SESSION['cf_address'] = $cf_item_name;
?>
That handles variables.
My new code for index.php
<?php
// including the session file
require_once("session_start.php")
?>
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
?>
</head>
<body>
<h2>Winner Aution Item Request Form</h2>
<p><span class="error"><FONT><font color="red">* required field.</font></span></p>
<form name="form1">
First Name: <input type="text" name="$af_first_name" id="af_first_name" value="<?php if(isset($_SESSION['af_first_name'])){echo stripslashes($_SESSION['af_first_name']); unset($_SESSION['af_first_name']); } ?>" /><br>
Last Name: <input type="text" name="$af_last_name" id="af_last_name" value="<?php if(isset($_SESSION['af_last_name'])){echo stripslashes($_SESSION['af_last_name']); unset($_SESSION['af_last_name']); } ?>" /><br>
E-Mail: <input type="text" name="$af_email" id="af_email" value="<?php if(isset($_SESSION['af_email'])){echo stripslashes($_SESSION['af_email']); unset($_SESSION['af_email']); } ?>" /><br>
</form>
<form name="form2">Copy and Paste Auction Name Below!<br>
Product Name <br><input type="text" name="$cf_item_name" id="cf_item_name" value="<?php if(isset($_SESSION['cf_item_name'])){echo stripslashes($_SESSION['cf_item_name']); unset($_SESSION['cf_item_name']); } ?>" /><br>
<input type="Submit" value="Submit" name="submit" onsubmit="form2.submit(); form3.submit();"></input>
That form takes input and sets to session. Session.php picks it up and places it in variable form. From here I used a strip for the underscores. and when it goes to form1 and form2 varables pick it up and fill in the form. Here is my new form1
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
stripZlashes($_SESSION['_mf']);
endif;
// including the session file
require_once("session_start.php")
?>
<center>
<table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;"> <tr><td>
<form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
<strong><font color="#660000">Your First Name:</font></strong>
<input type="text" id="$af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#660000">Your Last name:</font></strong>
<input type="text" id="$af_last_name" value="<?php echo (!empty($_SESSION['_af']['af_last_name'])?$_SESSION['_af']['af_last_name']:'') ?>" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#000066">Email address:</font></strong><br>
<input type="text" id="$af_email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
<input type="image" src="http://newsletter.jeremyahenry.com/images/go-button.gif" name="submit" value="Submit"><br>
<input type="hidden" name="r" value="4">
<input type="hidden" name="a" value="sub">
<input type="hidden" name="ref" value="none">
<br>
<font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes
<input type="RADIO" name="h" value="0" checked="checked">No<br>
</font></form>
</td></tr></table>
</center>
<?php
if(!empty($_SESSION['_mf'])):
unset($_SESSION['_mf']);
endif;
?>
form2:
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
stripZlashes($_SESSION['_mf']);
endif;
// including the session file
require_once("session_start.php")
?>
<form action="process.php" method=post>
<table align=left border=0 height=300>
<tr>
<td nowrap>
<p> Your name:
<input maxlength=25 name="af first name" id="af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" size=25> />
</td</tr>
<tr>
<td nowrap>
<p> Your email:
<input name=af email id="af email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" size=25 maxlength=25> />
</td></tr>
<tr>
<td colspan=2>
<center>
<p align=center>Enter your Auction item Name below:
<br>
<input name="cf item name" id="cf item name" value="<?php echo (!empty($_SESSION['_cf']['cf_item_name'])?$_SESSION['_cf']['cf_item_name']:'') ?>" rows="1" />
<p align=center>
<input type=submit value="Send Message">
</td></tr></table>
</form>
</center>
Ok now i have an issue with it submitting correctly...
<form name="form1">
<input type="text" value="" name="somename" onkeyup="form2.somename.value=this.value" />
</form>
<form name="form2">
<input type="text" value="" name="somename" />
</form>
check out the above code. hope this could be helpful. Or if this is not the result which you require. so you can be brief with your requirements in reply.
I don't know the usage or need of your implementation: maybe it is like a 3 step registration form?
It could be done in different ways without complicating it too much.
You could put all three forms in the same page and only showing the right one
according to th data being posted to the same page. It is the old way of doing things.
With Ajax calls, templates and javascript it could be don simpler but it depends on
your experience.
on each element you can mention as per their relevent events, such as
Ex. onkeyup="form2.elementname.value=this.value"

cant get PHP_SELF to post checkbox

i was trying to get my check box to output "Korting is ... %" at the bottom of the page depending on which check box is checked e.g. 2th and 3th boxes are checked it would output "Korting is 15%" but i cant seem to get it to work. can someone please help me
thank you in advance
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="nl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>XXL Computer winkel</title>
</head>
<body>
<h3>php lab 04</h3>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<form name="orderform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr>
<td>
Korting:<br />
<input type="checkbox" name="korting" value="15" /> Student 15% <br/>
<input type="checkbox" name="korting" value= "10" /> Senior 10% <br/>
<input type="checkbox" name="korting" value= "5" /> klant 5% <br/>
<hr/>
<img src="images/Lab4/1.jpg" width="200px" height="200px" alt=" "/>
<td/>
</tr>
<tr>
<td>
Toshiba Satellite A100-510 basisprijs 999.99
</td>
</tr>
<tr>
<td><!-- Shopping cart begin-->
<input type="hidden" name="toshibaproduct" value="001"/>
<input type="hidden" name="toshibamerk" value="Toshiba"/>
<input type="hidden" name="toshibamodel" value="Sattelite A100-510"/>
Aantaal: <input type="text" size=2 maxlenght=3 name="toshibaaantal" value="0"/>
<input type="hidden" name="toshibaprijs" value="999.99"/>
<input type="image" src="images/Lab4/2.jpg" border=0 value="bestellen"/>
<hr/>
</td><!--Shopping Cart END -->
</tr>
</form>
</table>
</body>
</html>
You need to use a name ending in [] such as name="korting[]". Then you can use $_POST['korting'] which will be an array containig the values of the checked checkboxes.
Note that $_POST['korting'] will not be set at all if no checkbox is checked!
Use radio instead of checkbox if you want one option to be selected
Do not use PHP_SELF, it is a security hole. Instead: <form action="">
Access the value with $_POST['korting']
To sum up all values, make your form like this:
<input type="checkbox" name="korting[]" value="15" /> Student 15% <br/>
<input type="checkbox" name="korting[]" value= "10" /> Senior 10% <br/>
<input type="checkbox" name="korting[]" value= "5" /> klant 5% <br/>
and the processing like that:
<?php
$korting = 0;
if (isset($_POST['korting']) && is_array($_POST['korting'])) {
$korting = array_sum($_POST['korting']);
}
echo 'Korting is ' . $korting . '%';
?>

submitting a form that has a picture into a mysql server using php

I am making a form that allows a user to create a page that has a qr code to link it to the page. I am only having one problem, I cant get the picture to upload to the database and display after the form has been submitted. it displays the file name of the photo just not the photo.
here is my form code
<?php
ob_start();
session_start();
<html>
<head>
</head>
<title>create </title>
<center> <font size="+5"> Create </center>
<body background="">
<p
<table align="center" cellpadding="0" border="0" cellspacing="1">
<form name="createTeaOffer" action="submit.php" method="get">
<tr> <td> <font size="+3"> Headline:</td> <td> <input type="text" name="hea"> </td> </tr>
<br />
<tr> <td> <font size="+3"> Photo: </td> <td> <input type="file" name="pho"> </td> </tr>
<br />
<tr> <td><font size="+3">Description: </td> <td><input name="des" type="textarea"> </td> </tr>
<br />
<tr> <td><font size="+3">Contact Method: </td> <td> <input name="con" type="radio" value="email" name="email" >Email <input type="radio" value="phone" method="get" name="phone"> Phone </td> </tr>
<br />
<tr> <td><font size="+3">Email or Phone: </td> <td> <input name="ema" type="text"> </td> </tr>
<br />
<tr> <td><font size="+3">Location: </td> <td> <input name="loc" type="text"> </td> </tr>
<br />
<tr> <td><font size="+3">Expiration (yyyy-mm-dd): </td> <td> <input name="exp" type="date"> </td> </tr>
<br />
<tr> <td><font size="+3">Distance: </td> <td> <input name="dis" type="text"> </td></tr>
<br />
</font></table>
<input type="submit">
</form>
</body>
</html>
and here is my submit code
<?php
ob_start();
session_start();
$template = <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><!--TITLE--></title>
</head>
<body>
This page belongs to user $myusername<p><p>
QR Code: <img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=http%3A%2F%2Fwww.url....%2F"<!--PAGENAME-->"&choe=UTF-8" title="Link to Google.com"><p>
Headline: <!--COMMENT--><p>
Photo: <!--PHOTO--><p>
Description: <!--DESC--><p>
Contact By: <!--CONBY--><p>
Contact information: <!--EMP--><p>
Location: <!--LOC--><p>
page expires on: <!--EXP--><p>
Distance: <!--DIS--><p>
<p>
Webpage URL: <!--PAGENAME-->
<p>
Please click Here to go back to the homepage.
</body>
</html>
EOD;
//handle the posted form
if(isset($_POST['hea1'])&&isset($_POST['pho1'])){
//replace the areas of the template with the posted values
$page = str_replace('<!--TITLE-->',htmlentities($_POST['hea1']),$template);
$page = str_replace('<!--COMMENT-->',htmlentities($_POST['hea1']),$page);
$page = str_replace('<!--PHOTO-->',htmlentities($_POST['pho1']),$page);
$page = str_replace('<!--PAGENAME-->',htmlentities($_POST['wp1']),$page);
$page = str_replace('<!--DESC-->',htmlentities($_POST['des1']),$page);
$page = str_replace('<!--CONBY-->',htmlentities($_POST['con1']),$page);
$page =
str_replace('<!--EMP-->',htmlentities($_POST['ema1']),$page);
$page = str_replace('<!--LOC-->',htmlentities($_POST['loc1']),$page);
$page = str_replace('<!--EXP-->',htmlentities($_POST['exp1']),$page);
$page = str_replace('<!--DIS-->',htmlentities($_POST['dis1']),$page);
//create a name for the new page
$pagename = md5($_POST['hea1']).'.html';
//db connect & select
$db=mysql_connect('localhost','streich','U4iwcjn3Hi&d');
mysql_select_db('streich_users');
//check if page already exists
// $result = mysql_query('SELECT page_url from pages WHERE url="'.mysql_real_escape_string($pagename).'"');
// if(mysql_num_rows($result)>=1){
// $notice = '<p>Page already created <b>./pages/'.$pagename.'</b></p>';
// }else{
//inset new page into db
mysql_query('INSERT into pages (`page_name`,`disc`,`page_url`,`username`,
`start_date`,`end_date`,`location`,`email`,`phone`,`photo`)VALUES(
"'.mysql_real_escape_string(htmlentities($_POST['hea1'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['dis1'])).'",
"'.$pagename.'","'.$myusername.'","'.mysql_real_escape_string(htmlentities($_POST['crd1'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['exp1'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['loc1'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['ema1'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['pho1'])).'")');
//put the created content to file
file_put_contents('./tearoffer/'.$pagename,$page);
//make a notice to show the user
$notice = '<p>New Page created <b>./page/'.$pagename.'</b></p>';
$fulllink = 'url/'.$pagename.'';
//header("location:/tearoffer/$pagename");
echo $fulllink;
?>
<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=http%3A%2F%2Fwww.url......%2Fpages%2F<? echo $pagename ?>&choe=UTF-8" title="Link"><p>
<?
// }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Make page example</title>
<style type="text/css">
.prevpage {
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
color: #093;
background-color: #333;
}
body {
}
</style>
</head>
<body>
<?php
//if the notice is set then display it
if(isset($notice)){echo $notice;} ?>
<ul><li class="prevpage"><b>Headline:</b> <?php echo $_GET['hea']; ?></li>
<li class="prevpage"></li>
<li class="prevpage"><b>Photo:</b> <?php echo $_GET['pho']; ?></li>
<li class="prevpage"></li>
<li class="prevpage"><b>Description:</b> <?php echo $_GET['des']; ?></li>
<li class="prevpage"></li>
<li class="prevpage"><b>Contact by:</b> <?php echo $_GET['con']; ?></li>
<li class="prevpage"></li>
<li class="prevpage"><b>E-Mail or Phone:</b> <?php echo $_GET['ema']; ?></li>
<li class="prevpage"></li>
<li class="prevpage"><b>Location:</b> <?php echo $_GET['loc']; ?></li>
<li class="prevpage"></li>
<li class="prevpage"><b>Expiration (yyyy-mm-dd):</b> <?php echo $_GET['exp']; ?></li>
<li class="prevpage"></li>
<li class="prevpage"><b>Distance:</b> <?php echo $_GET['dis']; ?></li>
</ul>/
<form method="POST" action="">
<input name="hea1" type="hidden" value="<?php echo $_GET['hea']; ?>">
<input name="pho1" type="hidden" value="<?php echo $_GET['pho']; ?>">
<input name="des1" type="hidden" value="<?php echo $_GET['des']; ?>">
<input name="crd1" type="hidden" value="<?php echo date("Y-m-d"); ?>">
<input name="con1" type="hidden" value=<?php echo $_GET['con']; ?>>
<input name="ema1" type="hidden" value=<?php echo $_GET['ema']; ?>>
<input name="loc1" type="hidden" value=<?php echo $_GET['loc']; ?>>
<input name="exp1" type="hidden" value=<?php echo $_GET['exp']; ?>>
<input name="dis1" type="hidden" value=<?php echo $_GET['dis']; ?>>
<input name="tst1" type="hidden" value="Thank you for using pages.">
<?php
echo '<input type="hidden" name="wp1" value="' . htmlspecialchars($pagename) . '" />'."\n";
?>
<input type="submit" value="submit preview">
</form>
</body></html>
This is a general answer, I can't really explain the actual code, but you can't upload an image to a "database" because databases are (normally) text based unless you use image encoding. If you mean uploading to your site's filesystem, refer to this tutorial http://www.w3schools.com/php/php_file_upload.asp and add the image URL to your database. You can then use <?php echo '<img src="' . $imageURL . '">' ?> to echo the image on the user's profile.
Also like dagon said, you have some problems with your html for example you put the title in the body section when it should be in the head section. I would also recommend using a $_POST request, not a $_GET request because it's more secure. Get better at the basics of html, there are plenty of resources available. The use of the font tag would make a normal web developer cry in pain because it's not even supposed to be used any more. Learn CSS, dude (put <style>td { font-size:15px }</style> in the head section).
Finally, calling a form field name things like "loc" and "con" are terrible ways to name a field. If you're the only one writing the code, then why should you make the names so confusing?

Categories