So I have this order form template I'm trying to install locally via MAMP. I've got MySQL server running just fine on MAMP, but when I go to install the app, I get "MySQL extension needs to be loaded for our site to work!"
I think I have to somehow go into the code for this form and change some info, but I'm not even sure if that is what I need to do. Can anyone point me in the right direction?
I pasted the code of what I think is the correct php file I need to edit, but wow I'm lost...
<?php ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>OrderNow - PHP Order form Installation Script</title>
<link href="style.css" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Arvo:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="logo-main"><img src="../img/logo-main.png" alt=""></div>
<?php
include("../common/config/config.php");
$flag=0;
if(defined('MYSQL_DB_HOST') || defined('MYSQL_DB_NAME') || defined('MYSQL_DB_USERNAME') || defined('MYSQL_DB_PASSWORD'))
{
// if database is connected go to site link
if($_GET['step'] == '')
{
step_4();
}
}
?>
<?php
$step = (isset($_GET['step']) && $_GET['step'] != '') ? $_GET['step'] : '';
switch($step){
case '1':
step_1();//Agree license
break;
case '2':
step_2();//Version check
break;
case '3':
step_3();//Create Database
break;
case '4':
step_4();//Goto site
break;
default:
step_1();
}
function step_1(){
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['agree'])){
header('Location:index.php?step=2');
exit;
}
else if($_SERVER['REQUEST_METHOD'] == 'POST' && !isset($_POST['agree'])){
echo '<div class="error-msg"><span>You must agree to the license.</span></div>';
}
?>
<div class="licence-agree"><h1>license agreement</h1>
<p>By clicking the check box, you agree to the Terms & Conditions.</p>
<form action="index.php?step=1" method="post">
<p>
<input type="checkbox" name="agree" />
I agree to the license
</p>
<input type="submit" value="Continue" />
</form>
</div>
<?php
}
function step_2(){
$pre_error ="";
if($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['pre_error'] ==''){
header('Location:index.php?step=3');
exit;
}
if($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['pre_error'] != '')
echo $_POST['pre_error'];
if (phpversion() < '5.0') {
$pre_error = 'You need to use PHP5 or above for our site!<br />';
}
if (ini_get('session.auto_start')) {
$pre_error .= 'Our site will not work with session.auto_start enabled!<br />';
}
if (!extension_loaded('mysql')) {
$pre_error .= 'MySQL extension needs to be loaded for our site to work!<br />';
}
if (!extension_loaded('gd')) {
$pre_error .= 'GD extension needs to be loaded for our site to work!<br />';
}
if (!is_writable('../common/config/config.php')) {
$pre_error .= 'config.php needs to be writable for our site to be installed!';
}
?>
<div class="version-details">
<table width="100%">
<tr>
<td>PHP Version:</td>
<td><?php echo phpversion(); ?></td>
<td><?php echo (phpversion() >= '5.0') ? 'Ok' : 'Not Ok'; ?></td>
</tr>
<tr>
<td>Session Auto Start:</td>
<td><?php echo (ini_get('session_auto_start')) ? 'On' : 'Off'; ?></td>
<td><?php echo (!ini_get('session_auto_start')) ? 'Ok' : 'Not Ok'; ?></td>
</tr>
<tr>
<td>MySQL:</td>
<td><?php echo extension_loaded('mysql') ? 'On' : 'Off'; ?></td>
<td><?php echo extension_loaded('mysql') ? 'Ok' : 'Not Ok'; ?></td>
</tr>
<tr>
<td>GD:</td>
<td><?php echo extension_loaded('gd') ? 'On' : 'Off'; ?></td>
<td><?php echo extension_loaded('gd') ? 'Ok' : 'Not Ok'; ?></td>
</tr>
<tr>
<td>config.php</td>
<td><?php echo is_writable('../common/config/config.php') ? 'Writable' : 'Unwritable'; ?></td>
<td><?php echo is_writable('../common/config/config.php') ? 'Ok' : 'Not Ok'; ?></td>
</tr>
</table>
<form action="index.php?step=2" method="post">
<input type="hidden" name="pre_error" id="pre_error" value="<?php echo $pre_error;?>" />
<input type="submit" name="continue" value="Continue" />
</form>
</div>
<?php
}
function step_3(){
$sitename="";$database_host="";$database_name="";$table_prefix="";$database_username="";$database_password="";$username="";$admin_password="";$email="";
if (isset($_POST['submit']) && $_POST['submit']=="Install!") {
$sitename=isset($_POST['sitename'])?$_POST['sitename']:"";
$email=isset($_POST['email'])?$_POST['email']:"";
$database_host=isset($_POST['database_host'])?$_POST['database_host']:"";
$database_name=isset($_POST['database_name'])?$_POST['database_name']:"";
$table_prefix=isset($_POST['table_prefix'])?$_POST['table_prefix']:"";
$database_username=isset($_POST['database_username'])?$_POST['database_username']:"";
$database_password=isset($_POST['database_password'])?$_POST['database_password']:"";
$username=isset($_POST['admin_name'])?$_POST['admin_name']:"";
$admin_password=isset($_POST['admin_password'])?$_POST['admin_password']:"";
define('PREFIX', $table_prefix);
if (empty($username) || empty($admin_password) || empty($database_host) || empty($database_username) || empty($database_name)) {
echo "<div class='error-msg'><span>All fields are required! Please re-enter.</span></div>";
}
elseif(filter_var($email, FILTER_VALIDATE_EMAIL)==false)
{
echo "<div class='error-msg'><span>Enter a valid email ID.</span></div>";
}
else
{
$connection = mysql_connect($database_host, $database_username, $database_password);
if($connection==false)
{
echo "<div class='error-msg'>Could not connect to database. Check your username and password then try again.\n</div>";
}
else
{
if(!mysql_select_db($database_name, $connection))
{
echo "<div class='error-msg'>Could not select database.\n</div>";
}
$f=fopen("../common/config/config.php","w");
$database_inf=
"<?php
define('MYSQL_DB_HOST', '".$database_host."');
define('MYSQL_DB_NAME', '".$database_name."');
define('MYSQL_DB_USERNAME', '".$database_username."');
define('MYSQL_DB_PASSWORD', '".$database_password."');
define('TABLE_PREFIX', '".$table_prefix."');
define('SITE_LINK', '');
?>";
if (fwrite($f,$database_inf)>0)
{
fclose($f);
}
// include("../settings.php");
include("tables.php");
if(!empty($tableArray))
{
for ($t = 0; $t < count($tableArray); $t++)
{
if(!empty($tableArray[$t]['table_create']))
{
mysql_query($tableArray[$t]['table_create'], $connection);
}
if(!empty($tableArray[$t]['table_insert']))
{
mysql_query($tableArray[$t]['table_insert'], $connection);
}
}
mysql_query($query1, $connection);
mysql_query($query2, $connection);
mysql_query($query3, $connection);
mysql_query("UPDATE `".PREFIX."administrator` SET Name='".$sitename."',email='".$email."',username='".$username."',password='".$admin_password."',order_mail_to='".$email."' ", $connection);
mysql_close($connection);
}
header("Location:index.php?step=4");
}
}
}
?>
<div class="db-details">
<h1>Database Connection</h1>
<form method="post" action="index.php?step=3">
<p>
<label for="database_name">Site Name</label>
<input type="text" name="sitename" size="30" value="<?php echo $sitename; ?>">
</p>
<p>
<label for="database_name">Database Name</label>
<input type="text" name="database_name" size="30" value="<?php echo $database_name; ?>">
</p>
<p>
<label for="database_name">Table Prefix</label>
<input type="text" name="table_prefix" size="30" value="<?php echo $table_prefix; ?>_">
</p>
<p>
<label for="database_host">Database Host</label>
<input type="text" name="database_host" value='localhost' size="30">
</p>
<p>
<label for="database_username">Database Username</label>
<input type="text" name="database_username" size="30" value="<?php echo $database_username; ?>">
</p>
<p>
<label for="database_password">Database Password</label>
<input type="text" name="database_password" size="30" value="<?php echo $database_password; ?>">
</p>
<h3>Admin Details</h3>
<p>
<label for="username">Admin Username</label>
<input type="text" name="admin_name" size="30" value="<?php echo $username; ?>">
</p>
<p>
<label for="password">Admin Password</label>
<input name="admin_password" type="password" size="30" maxlength="15" value="<?php echo $admin_password; ?>">
</p>
<p>
<label for="database_name">Email</label>
<input type="text" name="email" size="30" value="<?php echo $email; ?>">
</p>
<p>
<label> </label>
<input type="submit" name="submit" value="Install!">
</p>
</form>
</div>
<?php
}
function step_4(){
?>
<p align="center">Site home page</p>
<p align="center">Admin page</p>
<?php
}
?>
<div class="copy-right">© 2016 OrderNow Responsive Order Form.</div>
</body>
</html>
<?php
ob_end_flush();?>
I believe the web app 'OrderNow v1.4' uses PHP 5+ and as the MySQL extension is removed in PHP 7+ (instead, either the MySQLi or PDO_MySQL extension is to be used.) and that is why you are not able to run the web app .
I suggest you to download the older version of MAMP from here or you can download the Additional PHP versions version which are PHP 4 or below as the MySQL extension is deprecated as of PHP 5.5.0
Related
Been trying for hours anyways this form suppose to take my email that is being displayed and on submit inserts the details include email into database.
Instead of taking my 'email' it is taking my user id(auto increment) from user table and update that into feedback table.
feedback.php
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$name='';$feedback=''; $topic=''; $details='';
$action =(isset($_POST['submit']) ? $_POST['submit'] : null);
if($action!=null) {
$name =(isset($_POST['name']) ? $_POST['name'] : null);
$feedback =(isset($_POST['feedback']) ? $_POST['feedback'] : null);
$topic =(isset($_POST['topic']) ? $_POST['topic'] : null);
$details =(isset($_POST['details']) ? $_POST['details'] : null)
if($details==null) {
echo "<br><p style='text-align:center;color:red'>Please fill up all text fields!</p>";
}
else {
$query="insert into feedback values('','$email','$name','$feedback','$topic','$details','',null)";
$result=mysql_query($query);
echo "<br><p style='text-align:center;color:blue'>Successfully submit the feedback to system </p>";
$feedback=''; $topic=''; $details='';
}
if( mysql_error()!="") {
echo "<font style='text-align:center;color:red'>" . mysql_error() . "</font><br>";
}
}
?>
<form method="post" action="user_feedback.php">
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$query="select * from user where id=$email";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
?>
<br>
<table cellpadding="5">
<tr><td style="width:150px">User Email</td><td><input type="text" name="email" value="<?php echo $row['email'] ?>" disabled style="width:200px;" ></td></tr>
<tr><td>User Name</td><td><input type="text" name="name" value="<?php echo $name ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback</td>
<td>
<select name="feedback" style="height:32px">
<option <?php if($feedback=="Inquiry") { echo 'selected'; } ?> >Inquiry</option>
</select>
</td>
</tr>
<tr><td>Feedback Topic</td><td><input type="text" name="topic" value="<?php echo $topic ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback Details</td><td><textarea type="comment" name="details" value="<?php echo $details ?>" style="width:500px;" ></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Submit" class="tall"></td></tr>
</table>
</form>
Fixed it by using suggestion because there is was mixed up of login session between id and email on login page it self.
<?php
//echo("{$_SESSION['id']}"."<br />");
$email =(isset($_SESSION['id']) ? $_SESSION['id'] : null);
$name='';$feedback=''; $topic=''; $details='';
$action =(isset($_POST['submit']) ? $_POST['submit'] : null);
if($action!=null) {
$name =(isset($_POST['name']) ? $_POST['name'] : null);
$feedback =(isset($_POST['feedback']) ? $_POST['feedback'] : null);
$topic =(isset($_POST['topic']) ? $_POST['topic'] : null);
$details =(isset($_POST['details']) ? $_POST['details'] : null);
if($topic==null || $details==null) {
echo "<br><p style='text-align:center;color:red'>Please fill up all text fields!</p>";
}
else {
$query="insert into feedback values('','$email','$name','$feedback','$topic','$details','',null)";
$result=mysql_query($query);
echo "<br><p style='text-align:center;color:blue'>Successfully submit the feedback to system </p>";
$feedback=''; $topic=''; $details='';
}
if( mysql_error()!="") {
echo "<font style='text-align:center;color:red'>" . mysql_error() . "</font><br>";
}
}
?>
<form method="post" action="user_feedback.php">
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$query="select * from user where id=$email";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
?>
<br>
<table cellpadding="5">
<tr><td style="width:150px">User Email</td><td><input type="text" name="email" value="<?php echo $row['email'] ?>" disabled style="width:200px;" ></td></tr>
<tr><td>User Name</td><td><input type="text" name="name" value="<?php echo $name ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback</td>
<td>
<select name="feedback" style="height:32px">
<option <?php if($feedback=="Inquiry") { echo 'selected'; } ?> >Inquiry</option>
</select>
</td>
</tr>
<tr><td>Feedback Topic</td><td><input type="text" name="topic" value="<?php echo $topic ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback Details</td><td><textarea type="comment" name="details" value="<?php echo $details ?>" style="width:500px;" ></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Submit" class="tall"></td></tr>
</table>
</form>
I'm fetching the data from database for a particular record using email id in the hidden field.
If I try to add as input type="text" it is not working for me, can any one check this.
Here is my code.
Index.php:
<?php
session_start();
$username = $_SESSION['username'];
if($username) {
?>
<h3> Welcome <?php echo $username; ?></h3>
<?php
} else {
echo "no";
}
?>
<html>
<body>
<table class="table table-hover">
<form action="personalinfo.php" METHOD="POST">
<input type="hidden" value="<?php echo $username;?>" name="email">
<tr>
<th><label for="first_name">Name</label></th>
</tr>
<?php
include "personalinfo.php";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
<input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
echo "</tr>";
}
echo "</table>";
?>
</form>
</body>
</html>
personalinfo.php :
<?php
$connection = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("accountant", $connection);
$result = mysql_query("SELECT * FROM registered where email='$username'");
?>
In index.php, if I use like this in while condition 'first_name';?> name="first_name"/> so that I can update the record but if i remove this
echo "<td>" . $row['first_name'] . "</td>";
and if I add like this instead of that echo
<?php echo $row->first_name;?>
it gives error as
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\index\index.php on line 44
You have an error in your syntax try using this code
<?php
session_start();
?>
<?php
$username = $_SESSION['username'];
if($username) {
?>
<h3> Welcome <?php echo $username; ?></h3>
<?php
} else {
echo "no";
}
?>
<html>
<body>
<table class="table table-hover">
<form action="personalinfo.php" METHOD="POST">
<input type="hidden" value="<?php echo $username;?>" name="email">
<tr>
<th><label for="first_name">Name</label></th>
</tr>
<tr>
<?php
include "personalinfo.php";
while($row = mysql_fetch_array($result)) {
?>
<tr>
<input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
</tr>
<?php }?>
</table>
</form>
</body>
</html>
You are getting error because there's a HTML tag in php code.
This line has issue, as it was written in PHP code:
<input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
Try replacing the code with this :
<?php
include "personalinfo.php";
while($row = mysql_fetch_array($result)) {
?>
<tr>
<input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
<!-- //or this can be used <input type="text" name="first_name" value="<?php echo $row->first_name;?>" />
-->
</tr>
<?php
}
?>
</table>
I'm working in a simple WP plugin, my first one, and I don't know the right way to handle wp_options table using update_options function. I have this code in my plugin:
<form name="frequent_traveler_form" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<input type="hidden" name="frequent_traveler_hidden" value="Y">
<?php echo "<h4>" . __('Common Settings') . "</h4>"; ?>
<p><?php _e("Default Conversion Value: "); ?><input type="text" name="ft_default" value="<?php echo $ft_default; ?>" size="5"></p>
<p><?php _e("From Date: "); ?><input type="text" id="frequent_traveler_from_date" name="frequent_traveler_from_date" value="<?php echo $frequent_traveler_from_date ?>" class="datepicker" /></p>
<p><?php _e("To Date: "); ?><input type="text" id="frequent_traveler_to_date" name="frequent_traveler_to_date" value="<?php echo $frequent_traveler_to_date; ?>" class="datepicker" /></p>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save') ?>" />
</p>
</form>
What I need to do is "always", add new values to some config option at wp_options so any time I load the plugin config I should able to create as many options as I want using the same form. This is what I did and I'm not tested yet:
if ($_POST['ft_default'] && $_POST['frequent_traveler_from_date'] && $_POST['frequent_traveler_to_date'] && $_POST['ft_default'] != "" && $_POST['frequent_traveler_from_date'] != "" && $_POST['frequent_traveler_to_date'] != "") {
$ft_options = array(
'ft_default' => $_POST['ft_default'],
'frequent_traveler_from_date' => $_POST['frequent_traveler_from_date'],
'frequent_traveler_to_date' => $_POST['frequent_traveler_to_date']
);
update_option('ft_options', $ft_options);
}
Is that right? How I do that?
UPDATE
This is what I have in frequent-traveler.php (the main plugin file) among other functions:
function frequent_traveler_admin_actions()
{
add_options_page("Frequent Traveler Configuration", "Frequent Traveler Config", 'manage_options', "ftconfig", "frequent_traveler_admin");
}
add_action('admin_menu', 'frequent_traveler_admin_actions');
function frequent_traveler_admin()
{
include('ft_admin.php');
}
And this is the code at ft_admin.php :
<?php
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
?>
<div class="wrap">
<?php echo "<h2>" . __('Frequent Traveler Configuration') . "</h2>"; ?>
<form name="frequent_traveler_form" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<input type="hidden" name="frequent_traveler_hidden" value="Y">
<?php echo "<h4>" . __('Common Settings') . "</h4>"; ?>
<p><?php _e("Default Conversion Value: "); ?><input type="text" name="ft_default" value="<?php echo $ft_default; ?>" size="5">
<?php _e("From Date: "); ?><input type="text" id="frequent_traveler_from_date" name="frequent_traveler_from_date" value="<?php echo $frequent_traveler_from_date ?>" class="datepicker" />
<?php _e("To Date: "); ?><input type="text" id="frequent_traveler_to_date" name="frequent_traveler_to_date" value="<?php echo $frequent_traveler_to_date; ?>" class="datepicker" /></p>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save') ?>" />
</p>
</form>
</div>
<div class="wrap">
<table class="widefat">
<thead>
<tr>
<td>Conversion Value</td>
<td>From Date</td>
<td>To Date</td>
</tr>
</thead>
<tfoot>
<tr>
<td>Conversion Value</td>
<td>From Date</td>
<td>To Date</td>
</tr>
</tfoot>
<tbody>
<?php
global $wpdb;
if ($_POST['ft_default'] && $_POST['frequent_traveler_from_date'] && $_POST['frequent_traveler_to_date'] && $_POST['ft_default'] != "" && $_POST['frequent_traveler_from_date'] != "" && $_POST['frequent_traveler_to_date'] != "") {
$ft_options = array(
'ft_default' => $_POST['ft_default'],
'frequent_traveler_from_date' => $_POST['frequent_traveler_from_date'],
'frequent_traveler_to_date' => $_POST['frequent_traveler_to_date']
);
update_option('ft_options', $ft_options);
}
$config_options = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "options");
foreach ($config_options as $cop) {
?>
<tr>
<td><?php echo $cop->ft_default ?></td>
<td><?php echo $cop->from_date ?></td>
<td><?php echo $cop->to_date ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<script>
jQuery(document).ready(function() {
jQuery('.datepicker').datepicker({
dateFormat: 'dd/mm/yy'
});
});
</script>
I tried this gist code by writing the code at ft_admin.php top just below wp_enqueue_script and wp_enqueue_style calls and this is what doesn't work, what I did wrong?
UPDATE 2
I've added this code to ft_admin.php file:
<?php
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
add_action('admin_init', 'add_meta_boxes', 1);
function add_meta_boxes()
{
add_meta_box('repeatable-fields', 'Promotions', 'repeatable_meta_box_display');
}
function repeatable_meta_box_display()
{
echo "I'm here";
}
And nothing is showed, what is wrong in that code?
I want to make it so the select boxes user selects stays selected encase validation fails later in my form the rest of the form works perfect but I cant seem to figure how to do this for select boxes without changing all the names can someone please help I have created this which contains just my form checkboxes and the action I will be doing later on so you can see what I require
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div id="desert_l">
<label for="hnumber"><div class="bookerror"></div>Desert Choice </label>
</div>
<div id="desert_f">
<table width="275">
<tr>
<td width="113">
<label>
<input type="checkbox" name="desgroup[]" value="Vanila Cheesecake"<?php if (isset($dessgroup) && ($dessgroup == "Vanila Cheesecake"))
{
echo ' checked="checked""';
}
?> />
Vanilla Cheesecake</label></td>
<td width="94"><input type="checkbox" name="desgroup[]" value="Carrot Cake"<?php if (isset($dessgroup) && ($dessgroup == "Carrot Cake"))
{
echo ' checked="checked""';
}
?> />
Carrot Cake</td>
<td width="52"><input type="checkbox" name="desgroup[]" value="Jelly"<?php if (isset($dessgroup) && ($dessgroup == "Jelly"))
{
echo ' checked="checked""';
}
?> />
Jelly</td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="desgroup[]" value="Fruit Cheesecake"<?php if (isset($dessgroup) && ($dessgroup == "Fruit Cheesecake"))
{
echo ' checked="checked""';
}
?> >
Fruit Cheesecake</label></td>
<td><input type="checkbox" name="desgroup[]" value="Fruit Flan"<?php if (isset($dessgroup) && ($dessgroup == "Fruit Flan"))
{
echo ' checked="checked""';
}
?> />
Fruit Flan</td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="desgroup[]" value="Fruit Platter"<?php if (isset($dessgroup) && ($dessgroup == "Fruit Platter"))
{
echo ' checked="checked""';
}
?> />
Fruit Platter</label></td>
<td><input type="checkbox" name="desgroup[]" value="Chocolate Cake"<?php if (isset($dessgroup) && ($dessgroup == "Chocolate Cake"))
{
echo ' checked="checked""';
}
?>/>
Chocolate Cake</td>
<td> </td>
</tr>
</table>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
<p><span class="bookerror">
<?php
$dessgroup = $_POST['desgroup'] ;
if (isset ($_POST['submit']))
{
if (isset ($dessgroup))
{
echo "<h2>Desert Choice</h2>";
// Show Deserts Selected
for($i=0; $i < count($dessgroup); $i++)
{
echo $dessgroup[$i]."</br>";
}}
else
{
echo "You Must Select At Least 1 Desert" ;
}
}
?>
</span></p>
<p>Please Choose The Number Specified In Your Menu Choice<br />
</p>
</div>
</form>
Instead of
<input type="checkbox" name="desgroup[]" value="Vanila Cheesecake"<?php if (isset($dessgroup) && ($dessgroup == "Vanila Cheesecake"))
{
echo ' checked="checked""';
}
?> />
try
<input type="checkbox" name="desgroup[]" value="Vanila Cheesecake"<?php if (isset($_POST['desgroup']) && is_array($_POST['desgroup']) && in_array("Vanila Cheesecake", $_POST['desgroup']))
{
echo ' checked="checked""';
}
?> />
It would save you a lot of typing though if you would use arrays consequently.
$arr = array('possible value 1', 'possible value 2');
foreach ($arr as $val) {
?>
<input type="checkbox" name="desgroup[]" value="<?php echo $val; ?>"<?php if (isset($_POST['desgroup']) && is_array($_POST['desgroup']) && in_array($val, $_POST['desgroup']))
{
echo ' checked="checked""';
}
?> />
<?php
}
Try this
<input type="checkbox" name="desgroup[]" value="Vanila Cheesecake" <?php echo ((isset($dessgroup) && ($dessgroup == "Vanila Cheesecake")))?'checked="checked"':''; ?> />
Im getting crazy with this problem.
I try to use ajax to send data from a form in a way that I have not to reload all webpage (my webpage contain some queries for generate index menu that produce traffic); I create sendForm method, which handle form datas and pass it to php page to process.
This is the js code:
function sendForm(){
var http = false;
http = new XMLHttpRequest();
var ser = $(":input").serialize();
http.open("POST", "http://localhost/redir.php" ,true);
http.onreadystatechange= handleResponse();
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", ser.length);
http.setRequestHeader("Connection", "close");
http.send(ser);
return true;
}
My form data contain a variable numbers of inputs because there's some php code inside a for cycle.
<form name="form" id="form" class="table table-hover" method="post">
<?php while(.....)) { ?>
<tr style="line-height:40px">
<td><?php echo $home;?></td>
<td><?php echo $vis;?></td>
<td><input type="text" name="goal_h[]" class="input-mini"
<?php if ($sq[16] == "2"){ ?>
readonly value="<?php echo $goal_h;?>"
<?php }else if ($sq[16] == "3"){
?> readonly value="-"
<?php } else echo "value=\"-\"";
?> id="goal_h<?php echo $i?>[]" maxlength="2" size="2" />
<input type="hidden" name="id_sub" value="<?php echo $id_sub;?>" />
<input type="hidden" name="id" id="id" value="<?php echo $id_d;?>" />
<input type="hidden" name="data_gg" value="<?php echo $data_gg;?>" />
<input type="hidden" name="n_gg" value="<?php echo $n_gg;?>" />
<input type="hidden" name="id_p_home[]" id="idphome<?php echo $i?>" value="<?php echo $tmp_id_p;?>" />
<input type="hidden" name="id_p_vis[]" id="idpvis<?php echo $i?>" value="<?php echo $sq[10];?>" />
</td>
<td>
<input type="text" name="goal_v[]" class="input-mini" <?php if ($sq[16] == "2"){ ?> readonly value="<?php echo $goal_v;?>" <?php }else if ($sq[16] == "3"){ ?> readonly value="-" <?php } else echo "value=\"-\""; ?> id="goal_v<?php echo $i?>[]" maxlength="2" </td>
<td><input type="checkbox" <?php if ($sq[16] == "2"){ ?> checked <?php } ?> id="sosp<?PHP echo $i?>" name="sosp[]" value="<?PHP echo $i?>" onclick="cambiaStato(<?php echo $i?>);"/></td>
<td><input type="checkbox" <?php if ($sq[16] == "3"){ ?> checked <?php } ?> id="nd<?PHP echo $i?>" name="nd[]" value="<?PHP echo $i?>" onclick="cambiaStato(<?php echo $i?>);"/>
</td>
</tr>
<tr style="line-height:40px">
<td><input type="submit" id="submit" name="submit" value="AGGIORNA IL PUNTEGGIO" onclick="sendForm()" /></td>
<td colspan="5"></td>
</tr>
<?php } ?>
</form>
this code works if I don't use with ajax and simply use an action=name_of_file.php, but when I try to use sendForm() method, in redir.php file I lose $_POST variables.
$home_id_p=$_POST['id_p_home'];
$vis_id_p=$_POST['id_p_vis'];
$goal_home=$_POST['goal_h'];
$goal_vis= $_POST['goal_v'];
$sosp= (isset($_POST['sosp'])) ? $_POST['sosp'] : "99";
$nd= (isset($_POST['nd'])) ? $_POST['nd'] : "99";
and then I need to loop on $home_id_p.
I tried also wihout serialize(), and also with serializeArray() :
var ser = $(":input").serializeArray();
but with this I'm not able to send it, because I get an error "invalid argument" in
http.send(ser)
Any idea?
Thanks