PHP form not submitting until all the info entered - php

I am submitting an HTML form using php and I have these fields in my form:
Name:(varchar)
Address:(varchar)
FAX:(int)
PHONE:(int)
EMAIL:(varchar)
plus a primary ID that gets added on its own.
Now my form doesn't get submitted until I enter the fax field? Does anyone know why is it happening?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<body>
<?php
require_once('../../public_html/input.php');
require_once('../../public_html/nauth.php');
require_once('../../public_html/mysql.php');
if (isset($_GET['more']))
{
$more = $_GET['more'];
$new = 8;
}
if (isset($_POST['submit']))
{
$more = 4;
$new = 8;
$name = $_SESSION['username'];
$dbc = mysqli_connect(cname, chost, cpwd, cdb);
$com_name = mysqli_real_escape_string($dbc, trim($_POST['com_name']));
$com_address = mysqli_real_escape_string($dbc, trim($_POST['com_address']));
$com_phone = mysqli_real_escape_string($dbc, trim($_POST['com_phone']));
$com_fax = mysqli_real_escape_string($dbc, trim($_POST['com_fax']));
$source_id = $_POST['source'];
$com_email = mysqli_real_escape_string($dbc, trim($_POST['com_email']));
$entered_by = $name;
$query = "select * from company_customers where name='$com_name'";
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data) == 0) //to check if the name already exists
{
$query="insert into company_customers(name,address,phone,fax,email,entered_by,source_id) values('$com_name','$com_address','$com_phone','$com_fax','$com_email','$entered_by','$source_id')";
mysqli_query($dbc, $query);
$query = "select * from company_customers where name='$com_name'";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
$id = $row['id']; //to add the company id in the contacts table
$i = 0;
while (!empty($_POST['name' . $i]))
{
$name = $_POST['name' . $i];
$designation = $_POST['desig' . $i];
$phone = $_POST['phone' . $i];
$query = "insert into contacts(name,designation,id,phone) values('$name','$designation','$id','$phone')";
mysqli_query($dbc, $query);
$i++;
}
mysqli_close($dbc);
echo 'Added';
require_once('option.php');
exit();
}
else echo 'company already entered';
}
else if (isset($_POST['more']))
{
$more = $_POST['count'];
$new = $more + 4;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<fieldset><legend>Company Profile</legend>
<label for="com_name">Company Name:</label><input type="text" name="com_name" value="<?php if(isset($_POST['more'])) echo $_POST['com_name']; ?>"/><br />
<label for="com_address">Company Address:</label><input type="text" name="com_address" value="<?php if(isset($_POST['more'])) echo $_POST['com_address']; ?>" /><br />
<label for="com_phone">Company Phone:</label><input type="text" name="com_phone" value="<?php if(isset($_POST['more'])) echo $_POST['com_phone']; ?>" /><br />
<label for="com_fax">Company Fax:</label><input type="text" name="com_fax" value="<?php if(isset($_POST['more'])) echo $_POST['com_fax']; ?>" /><br />
<label for="com_email">Company Email:</label><input type="text" name="com_email" value="<?php if(isset($_POST['more'])) echo $_POST['email']; ?>" /><br />
<?php
$dbc = mysqli_connect(cname, chost, cpwd, cdb);
$query = "select * from source";
$data = mysqli_query($dbc, $query);
$number_row = mysqli_num_rows($data);
$source[0] = '';
$source_id[0] = '';
$i = 1;
while ($row = mysqli_fetch_array($data))
{
$source[$i] = $row['src'];
$source_id[$i] = $row['source_id'];
$i++;
}
echo '<label for="source">Source</label><select name="source">';
for ($i = 0; $i <= $number_row; $i++)
echo '<option value="' . $source_id[$i] . '">' . $source[$i] . '</option>';
echo '</select>';
?>
</fieldset>
<fieldset><legend>Company Contact</legend>
<?php
for ($i = 0; $i < $more; $i++)
{
?>
<label for="<?php echo 'name' . $i; ?>">Name:</label><input type="text" name="<?php echo 'name' . $i; ?>" value="<?php if (isset($_POST['more'])) echo $_POST['name' . $i]; ?>" />
<label for="<?php echo 'desig' . $i; ?>">Designation:</label><input type="text" name="<?php echo 'desig' . $i; ?>" value="<?php if (isset($_POST['more'])) echo $_POST['desig' . $i];?>" />
<label for="<?php echo 'phone' . $i;?>">Phone:</label><input type="text" name="<?php echo 'phone' . $i;?>" value="<?php if (isset($_POST['more'])) echo $_POST['phone' . $i]; ?>" /><br />
<?php
}
?>
<input type="hidden" name="count" value="<?php echo $new; ?>" />
<input type="submit" name="more" value="more" />
</fieldset>
<input type="submit" name="submit" value="ADD" />
</form>
</body>
</html>

Try setting the column to allow null values in mysql. E.g.
ALTER TABLE company_customers CHANGE fax fax INT(11) NULL

Related

PHP Random Math Quiz Evaluation issue

EDIT: When I print the $answer variable by itself it always returns the correct answer of the current question.
I am currently coding a PHP script that produces a simple, but completely random math quiz. How it works is that is gets two random numbers between 0-9 and a random operator from '-', '+', '*'. The user must enter into the text box the answer of the shown question. From here it's pretty straightforward to understand.
However, the issue I am having is that no matter what the user enters the only questions that are validated as correct are ones where the answer is 0.
Here is my code so far.
<?php
require 'functions.php';
$body = "";
$score = 0;
$count = 0;
if(isset($_POST['submit']))
{
$firstDigit = $_POST['lho'];
$secondDigit = $_POST['rho'];
$operator = $_POST['op'];
$userAnswer = $_POST['answer'];
$count = $_POST['count'];
$score = $_POST['score'];
$answer = evaluate($firstDigit, $secondDigit, $operator);
if($answer == $userAnswer)
{
$count++;
$score++;
$body .= "\n<h1>Congratulations!</h1>\n\n";
$body .= "$score out of $count";
}
else
{
$count++;
$body .= "\n<h1>Sorry!</h1>\n\n";
$body .= "$score out of $count";
}
}
header( 'Content-Type: text/html; charset=utf-8');
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
?>
<?php
include("./header.php");
?>
<h1>Math Quiz</h1> <br /> <br />
<?php
print $body;
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h3><?php echo $firstDigit; ?> <?php echo $operator; ?> <?php echo $secondDigit; ?> = ?
<input type="text" name="answer" size="2" /></h3>
<p><input type="submit" name="submit" value="Try It!" />
<input type="hidden" name="lho" value="<?php echo randdigit(); ?>" />
<input type="hidden" name="rho" value="<?php echo randdigit(); ?>" />
<input type="hidden" name="op" value="<?php echo randop(); ?>" />
<input type="hidden" name="score" value="<?php echo $score++; ?>" />
<input type="hidden" name="count" value="<?php echo $count++; ?>" /></p>
</form>
<?php
include("./footer.php");
?>
My evaluate function is this:
function evaluate($d1, $d2, $op) {
switch($op) {
case '+' : // addition
$result = $d1 + $d2;
break;
case '-' : // subtraction
$result = $d1 - $d2;
break;
case '*' : // multiplication
$result = $d1 * $d2;
break;
default : // Unidentified, return safe value
$result = 0;
}
return $result;
}
Here is the randop() function and the randdigit() function:
/* Return a number in the range 0-9 inclusive
*/
function randdigit() {
return mt_rand(0,9);
} // end functionranddigit()
function randop(){
$ops = array('+', '-', '*');
// pick a random index between zero and highest index in array.
$randnum = mt_rand(0,sizeof($ops)-1);
return $ops[$randnum]; // Use the index to pick the operator
}
First on the 48th line :
<h3><?php echo $firstDigit; ?> <?php echo $operator; ?> <?php echo $secondDigit; ?> = ?
When you first load the form and until it has been submitted once,
$firstDigit, $operator, $secondDigit
Aren't set.
Then, this line wich is the equation to solve is filled with the old equation that needed to be solved AND your hidden fields are filled with new numbers, invisible to the user using randdigit() and randop().
<input type="hidden" name="lho" value="<?php echo randdigit(); ?>" />
<input type="hidden" name="rho" value="<?php echo randdigit(); ?>" />
<input type="hidden" name="op" value="<?php echo randop(); ?>" />
Here is the code that works well for me :
<?php
require 'functions.php';
$body = "";
$score = 0;
$count = 0;
$newFdigit = randdigit();
$newSdigit = randdigit();
$newOperator = randop();
if(isset($_POST['submit']))
{
$firstDigit = $_POST['lho'];
$secondDigit = $_POST['rho'];
$operator = $_POST['op'];
$userAnswer = $_POST['answer'];
$count = $_POST['count'];
$score = $_POST['score'];
$answer = evaluate($firstDigit, $secondDigit, $operator);
if($answer == $userAnswer)
{
$count++;
$score++;
$body .= "\n<h1>Congratulations!</h1>\n\n";
$body .= "$score out of $count";
}
else
{
$count++;
$body .= "\n<h1>Sorry!</h1>\n\n";
$body .= "$score out of $count";
}
}
header( 'Content-Type: text/html; charset=utf-8');
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
?>
<h1>Math Quiz</h1> <br /> <br />
<?php
print $body;
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h3><?php echo $newFdigit; ?> <?php echo $newOperator; ?> <?php echo $newSdigit; ?> = ?
<input type="text" name="answer" size="2" /></h3>
<p><input type="submit" name="submit" value="Try It!" />
<input type="hidden" name="lho" value="<?php echo $newFdigit ?>" />
<input type="hidden" name="rho" value="<?php echo $newSdigit; ?>" />
<input type="hidden" name="op" value="<?php echo $newOperator; ?>" />
<input type="hidden" name="score" value="<?php echo $score++; ?>" />
<input type="hidden" name="count" value="<?php echo $count++; ?>" /></p>
</form>

how to use php retrieve data from postgresql and showing in html

I was trying to retrieve data from PostgreSQL database, In PHP.
Retrieving the data is fine but it does not work when it is linked with HTML.
When I click on find button in HTML interface, it did not really retrieve data from PostgrSQL.
Can anybody help?
PHP
$host = "host=sv4gis";
$dbname = "dbname=survey";
$credentials = "user=sde password=dfd54f";
$objectid = "";
$jobno = "";
$unit = "";
$coordinate = "";
$name = "";
$northing = "";
$easting = "";
$elev = "";
$db = pg_connect( "$host $dbname $credentials" );
if(!$db){
echo "Error : Unable to open database\n";
} else {
echo "Opened database successfully\n";
}
function getPosts() {
$posts = array();
$posts[0] = $_POST['objectid'];
$posts[1] = $_POST['jobno'];
$posts[2] = $_POST['unit'];
$posts[3] = $_POST['coordinate'];
$posts[4] = $_POST['name'];
$posts[5] = $_POST['northing'];
$posts[6] = $_POST['easting'];
$posts[7] = $_POST['elev'];
return $posts;
}
// Selection Operation
if (isset($_POST['search'])) {
$data = getPosts();
$sql = "SELECT * FROM monu_from_Lst WHERE OBJECTID = $data[0]";
$ret = pg_query($db, $sql);
if($ret) {
if(pg_num_rows($ret)) {
while($row = pg_fetch_array($ret)) {
echo $objectid = $row['objectid'];
echo $jobno = $row['jobno'];
echo $unit = $row['unit'];
echo $coordinate = $row['coordinate'];
echo $name = $row['name'];
echo $northing = $row['northing'];
echo $easting = $row['easting'];
echo $elev = $row['elev'];
}
echo "Operation done successfully\n";
// pg_close($db);
}else{
echo 'No Data For This Id';
}
} else {
echo 'Result Error';
}
}
HTML
<form action="php_insert_update_delete_search.php" method="post">
<input type="number" name="objectid" placeholder="OBJECTID" value="<?php echo $objectid;?>">
<input type="text" name="jobno" placeholder="JOB#" value="<?php echo $jobno;?>">
<input type="text" name="unit" placeholder="UNIT" value="<?php echo $unit;?>">
<input type="text" name="coordinate" placeholder="COORDINATE" value="<?php echo $coordinate;?>">
<input type="text" name="name" placeholder="NAME" value="<?php echo $name;?>">
<input type="number" name="northing" placeholder="NORTHING" value="<?php echo $northing;?>">
<input type="number" name="northing" placeholder="NORTHING" value="<?php echo $northing;?>">
<input type="number" name="easting" placeholder="EASTING" value="<?php echo $easting;?>">
<input type="number" name="elev" placeholder="ElEVATION" value="<?php echo $elev;?>">
<div>
<input type="submit" name="search" value="Find">
</div>
</form>
Your code seems to be fine. The problem might be with
<form action="php_insert_update_delete_search.php" method="post">
If you are posting the file to itself try using
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
Make sure your query runs successfully. if your query does not run successfully
try following
$sql = "SELECT * FROM \"monu_from_Lst\" WHERE objectid= $data[0]";
I have working code as following
<?php
$host = "host=localhost"; // use your hostname
$dbname = "dbname=blogsitedb"; // use your dbname
$credentials = "user=postgres password=admin"; // use your credentials
$objectid = "";
$jobno = "";
$unit = "";
$coordinate = "";
$name = "";
$northing = "";
$easting = "";
$elev = "";
$db = pg_connect("$host $dbname $credentials");
if(!$db)
{
echo "Error : Unable to open database\n";
}
else
{
echo "Opened database successfully\n";
}
function getPosts()
{
$posts = array();
$posts[0] = $_POST['objectid'];
$posts[1] = $_POST['jobno'];
$posts[2] = $_POST['unit'];
/*
$posts[3] = $_POST['coordinate'];
$posts[4] = $_POST['name'];
$posts[5] = $_POST['northing'];
$posts[6] = $_POST['easting'];
$posts[7] = $_POST['elev'];
*/
return $posts;
}
// Selection Operation
if(isset($_POST['search']))
{
$data = getPosts();
$sql = "SELECT * FROM \"monu_from_Lst\" WHERE objectid= $data[0]";
$ret = pg_query($db, $sql);
if($ret)
{
if(pg_num_rows($ret))
{
while($row = pg_fetch_array($ret))
{
echo $objectid = $row['objectid'];
echo $jobno = $row['jobno'];
echo $unit = $row['unit'];
/*echo $coordinate = $row['coordinate'];
echo $name = $row['name'];
echo $northing = $row['northing'];
echo $easting = $row['easting'];
echo $elev = $row['elev'];*/
}
echo "Operation done successfully\n";
// pg_close($db);
}
else
{
echo 'No Data For This Id';
}
}
else
{
echo 'Result Error';
}
}
?>
<!DOCTYPE Html>
<html>
<head>
<title>PHP INSERT UPDATE DELETE SEARCH</title>
</head>
<body>
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
<input type="number" name="objectid" placeholder="OBJECTID" value="<?php echo $objectid;?>"><br><br>
<input type="text" name="jobno" placeholder="JOB#" value="<?php echo $jobno;?>"><br><br>
<input type="text" name="unit" placeholder="UNIT" value="<?php echo $unit;?>"><br><br>
<input type="text" name="coordinate" placeholder="COORDINATE" value="<?php echo $coordinate;?>"><br><br>
<input type="text" name="name" placeholder="NAME" value="<?php echo $name;?>"><br><br>
<input type="number" name="northing" placeholder="NORTHING" value="<?php echo $northing;?>"><br><br>
<input type="number" name="northing" placeholder="NORTHING" value="<?php echo $northing;?>"><br><br>
<input type="number" name="easting" placeholder="EASTING" value="<?php echo $easting;?>"><br><br>
<input type="number" name="elev" placeholder="ElEVATION" value="<?php echo $elev;?>"><br><br>
<div>
<!-- Input For Find Values With The given objectid -->
<input type="submit" name="search" value="Find">
</div>
</form>
</body>
</html>

why this code dosen't update the data

I can't update the data on this code . it just return to the main page without any update . and i am sure about the connection data on connection file .
and all the column in the data bas is correct
so what is the problem please
<?
include "../include/config.php";
echo "<a href='del_update.php'>Delete</a>"
?>
<div class="articleall">
<?
$id = $_REQUEST['do'];
if($_REQUEST['do'] == 'remove'){
$gid= $_GET['id'] ;
$de = mysql_query("delete from article where id='$gid'");
if($de){
echo "Delete doen";
echo '<meta http-equiv="refresh" content="2; url=del_update.php"/>';
exit ;
}
}
#############################################
if($_REQUEST['do'] == 'update'){
$gid2 = $_GET['id'];
$sel = mysql_query("select * from article where id='$gid2'");
$row2 = mysql_fetch_assoc($sel);
$id2 =$row2['id'];
$name2= $row2['name'];
$auther2= $row2['auther'];
$text2 = $row2['text'];
####################################### post
$postid = $_POST['id'];
$postname = $_POST['name'];
$postauther = $_POST['auther'];
$posttext = $_POST['text'];
if($_POST['del_update']){
if($postname ==''){
echo "it is empty";
echo '<meta http-equiv="refresh" content="2; url=del_update.php"/>';
exit ;
}
else {
$update = mysql_query("update article set
name ='$postname',
auther='$postauther'
where id ='$postid'
");
if(isset($update)){
echo "update done ";
echo '<meta http-equiv="refresh" content="2; url=del_update.php"/>';
exit ;
}
}
}
?>
<form action="del_update.php?do=update" method="post" >
title : <input type="text" class="name" name="name" value="<?=$name2; ?>"></br>
auther : <input type="text" class="name" name="auther" value="<?=$auther2;?>"></br>
date : <input type="text" class="name" name="date" value=""></br>
<input type="hidden" class="name" name="id" value=""></br>
text : <textarea value="" id="elm1" name="elm1" rows="15" cols="80" style="width: 80%">
<? echo $text2; ?>
</textarea>
<input type="submit" class="botton" value="update" name="go"><br>
</form>
<?
}
?>
<?
$query = mysql_query("select * from article order by id desc ");
while ($row = mysql_fetch_assoc($query)
){
$id = $row['id'];
$name = $row['name'];
echo "
<div class='shortarticle'>
<h3>$name ||
<a href='?do=remove&id=$id'>Delete</a>||
<a href='?do=update&id=$id'>Update</a>
</h3>
</div>
</div> ";
}
?>

How to remain stick to a php page?

I am passing the level of the question through query string to the page. Next, I am prompting user to give the answer from the option. Now, if the answer is correct, score is incremented. Now the issue is that if the answer is wrong, I am not getting any thing in browser.
<?php
session_start();
if ( isset($_POST['submit']))
{
$qid = $_POST['qid'];
$answer = $_POST['answer'];
// $range= $_POST['range'] ;
$dbc = mysqli_connect('localhost','root','1234','islamic')
or die('unable to connect');
$query = "select * from question where qid = '$qid' ";
$result = mysqli_query($dbc,$query);
$row = mysqli_fetch_array($result);
if ( $answer == $row['answer'])
{
// echo 'Congrats, Your answer is correct.'.$_COOKIE['username'];
#$score = ++$_COOKIE['score'];
setcookie('score',$score);
}
#$page = ++$_COOKIE['page'];
if ( #$page == 4)
{
echo 'score is '.$_COOKIE['score'];
setcookie('score',0);
setcookie('page',0);
echo 'Go to Home ';
exit();
}
setcookie('page',$page);
}
if ( isset($_GET['level']))
{
$_SESSION['level'] = $_GET['level'];
}
$level = $_SESSION['level'];
$dbc = mysqli_connect('localhost','root','1234','islamic')
or die('unable to connect');
// $query = "Select * from question";
// $result = mysqli_query($dbc,$query);
// $num_rows = mysqli_num_rows($result);
$range = rand(0,6);
$query = "select * from question where level = '$level' limit $range,1";
$result = mysqli_query($dbc,$query);
while ( ($row = mysqli_fetch_array($result)) )
{
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h3> <?php echo $row['sawal']; ?></h3>
<form method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="radio" name=" answer" value="A" ><?php echo $row['A']; ?><br>
<input type="radio" name=" answer" value="B" ><?php echo $row['B']; ?><br>
<input type="radio" name=" answer" value="C" ><?php echo $row['C']; ?><br>
<input type="radio" name=" answer" value="D" ><?php echo $row['D']; ?><br>
<input type="hidden" name = "qid" value="<?php echo $row['qid'] ?>">
<!-- <input type="hidden" name = "range" value="<?php $range ?>"> -->
<input type="submit" name="submit" value="ANSWER"/>
</form>
</body>
</html>
<?php
}
mysqli_close($dbc);
?>
You script doesn't display anything if the database query returns no results.
Get rid of the while and simply use $row = mysqli_fetch_array($result);

Only updating half the data to MySQL table

The code below is for updating data in a MySQL table. It was written by pulling all the data from one query but I have tried to adapt it to pull data from two queries to improve the ordering. Now only some of the records update when the submit button is clicked and I'm not sure how to fix it.
The original code was:
if(isset($_POST['submit'])){
$password = $_POST['password'];
$total = $_POST['total'];
$park_id = $_POST['park_id'];
if($password=="****"){
for($i =1; $i<=$total; $i++){
$ride_id = $_POST['ride_id'.$i];
$name = $_POST['ride_name'.$i];
$type = $_POST['type'.$i];
$topride = $_POST['topride'.$i];
$info = $_POST['info'.$i];
$speed = $_POST['speed'.$i];
$height = $_POST['height'.$i];
$length = $_POST['length'.$i];
$inversions = $_POST['inversions'.$i];
$query = "update tpf_rides set name='$name',type='$type'";
if($topride!=""){$query .= ",top_ride=$topride";}
if($info!=""){$query .= ",info='$info'";}
if($height!=""){$query .= ",height=$height";}
if($length!=""){$query .= ",length=$length";}
if($speed!=""){$query .= ",speed=$speed";}
if($inversions!=""){$query .= ",inversions=$inversions";}
$query .= " where ride_id=".$ride_id." and park_id=".$park_id;
mysql_query($query);
}
header('location:index.php?msg=Successfully Updated.');
}else{
echo "Enter Correct Password.";
}
}
if(isset($_GET['id'])){
$id = $_GET['id'];
$sql = "select name from tpf_parks where park_id=".$id;
$result = mysql_fetch_array(mysql_query($sql));
echo '<h2>'.$result['name'].'</h2>';
$qry = "select * from tpf_rides where park_id=".$id;
$res = mysql_query($qry);
$no = mysql_num_rows($res);
$x = 0;
if($no>0){ ?>
<form action="" method="post">
<input type="hidden" value="<?=$no?>" name="total">
<input type="hidden" value="<?=$id?>" name="park_id">
<table> <?php
while($row = mysql_fetch_array($res)){ $x++;
echo '<input type="hidden" value="'.$row['ride_id'].'" name="ride_id'.$x.'">';
echo '<tr><td>Name : </td><td><input type="text" name="ride_name'.$x.'" value="'.$row['name'].'"></td></tr>';
echo '<tr><td>Type : </td><td><input type="text" name="type'.$x.'" value="'.$row['type'].'"></td></tr>';
echo '<tr><td>Top Ride : </td><td><input type="text" name="topride'.$x.'" value="'.$row['top_ride'].'"></td></tr>';
echo '<tr><td>Info : </td><td><input type="text" name="info'.$x.'" value="'.$row['info'].'"></td></tr>';
if($row['type']!="Roller Coaster"){
echo '<tr><td>Speed : </td><td><input type="text" name="speed'.$x.'" value="'.$row['speed'].'"></td></tr>';
echo '<tr><td>Height : </td><td><input type="text" name="height'.$x.'" value="'.$row['height'].'"></td></tr>';
echo '<tr><td>Length : </td><td><input type="text" name="length'.$x.'" value="'.$row['length'].'"></td></tr>';
echo '<tr><td>Inversions : </td><td><input type="text" name="inversions'.$x.'" value="'.$row['inversions'].'"></td></tr>';
}
echo '<tr><td colspan="2"><hr></td></tr>';
} ?>
<tr><td>Password :</td><td><input type="password" value="" name="password" id="password"></td></tr>
<tr><td></td><td><input onclick="return check()" type="submit" value="Save" name="submit"></td></tr>
</table>
</form>
<?php
}else{
echo "No Rides in this park.";
}
}else{
if(isset($_GET['msg'])){echo $_GET['msg'].'<br>';}
$qry = "select * from tpf_parks order by name";
$res = mysql_query($qry);
?>
Select Park : <select name="park" onChange="getdata(this.options[this.selectedIndex].value)">
<option value="">Select Park</option>
<?php
while($row = mysql_fetch_array($res)) { ?>
<option value="<?=$row['park_id']?>"><?=$row['name']?></option>
<? } ?>
</select>
<?php } ?>
and the new code where I altered the queries is here:
if(isset($_POST['submit'])){
$password = $_POST['password'];
$total = $_POST['total'];
$park_id = $_POST['park_id'];
if($password=="*****"){
for($i =1; $i<=$total; $i++){
$ride_id = $_POST['ride_id'.$i];
$name = $_POST['ride_name'.$i];
$type = $_POST['type'.$i];
$topride = $_POST['topride'.$i];
$info = $_POST['info'.$i];
$speed = $_POST['speed'.$i];
$height = $_POST['height'.$i];
$length = $_POST['length'.$i];
$inversions = $_POST['inversions'.$i];
$query = "update tpf_rides set name='$name',type='$type'";
if($topride!=""){$query .= ",top_ride=$topride";}
$query .= ",info='$info'";
if($height!=""){$query .= ",height=$height";}
if($length!=""){$query .= ",length=$length";}
if($speed!=""){$query .= ",speed=$speed";}
if($inversions!=""){$query .= ",inversions=$inversions";}
$query .= " where ride_id=".$ride_id." and park_id=".$park_id;
mysql_query($query);
}
header('location:index.php?msg=Successfully Updated.');
}else{
echo "Enter Correct Password.";
}
}
if(isset($_GET['id'])){
$id = $_GET['id'];
$sql = "select name from tpf_parks where park_id=".$id;
$result = mysql_fetch_array(mysql_query($sql));
echo '<h2>'.$result['name'].'</h2>';
$qry = "SELECT * FROM tpf_rides
WHERE park_id = $id AND type LIKE '%Roller Coaster%' ORDER BY name ASC";
$res = mysql_query($qry);
$qry2 = "SELECT * FROM tpf_rides
WHERE park_id = $id AND type NOT LIKE '%Roller Coaster%' ORDER BY name ASC";
$res2 = mysql_query($qry2);
$qry3 = "SELECT * FROM tpf_rides WHERE park_id = $id";
$res3 = mysql_query($qry2);
$no = mysql_num_rows($res3);
$x = 0;
$xx = 0;
if($no>0){ ?>
<form action="" method="post">
<input type="hidden" value="<?=$no?>" name="total">
<input type="hidden" value="<?=$id?>" name="park_id">
<table> <?php
while($row = mysql_fetch_array($res)){ $x++;
echo '<input type="hidden" value="'.$row['ride_id'].'" name="ride_id'.$x.'">';
echo '<tr><td>Name : </td><td><input type="text" name="ride_name'.$x.'" value="'.$row['name'].'"></td></tr>';
echo '<tr><td>Type : </td><td><input type="text" name="type'.$x.'" value="'.$row['type'].'"></td></tr>';
echo '<tr><td>Top Ride : </td><td><input type="text" name="topride'.$x.'" value="'.$row['top_ride'].'"></td></tr>';
echo '<tr><td>Info : </td><td><input type="text" name="info'.$x.'" value="'.$row['info'].'"></td></tr>';
echo '<tr><td>Speed : </td><td><input type="text" name="speed'.$x.'" value="'.$row['speed'].'"></td></tr>';
echo '<tr><td>Height : </td><td><input type="text" name="height'.$x.'" value="'.$row['height'].'"></td></tr>';
echo '<tr><td>Length : </td><td><input type="text" name="length'.$x.'" value="'.$row['length'].'"></td></tr>';
echo '<tr><td>Inversions : </td><td><input type="text" name="inversions'.$x.'" value="'.$row['inversions'].'"></td></tr>';
echo '<tr><td colspan="2"><hr></td></tr>';
}
while($row2 = mysql_fetch_array($res2)){ $xx++;
echo '<input type="hidden" value="'.$row2['ride_id'].'" name="ride_id'.$xx.'">';
echo '<tr><td>Name : </td><td><input type="text" name="ride_name'.$xx.'" value="'.$row2['name'].'"></td></tr>';
echo '<tr><td>Type : </td><td><input type="text" name="type'.$xx.'" value="'.$row2['type'].'"></td></tr>';
echo '<tr><td>Top Ride : </td><td><input type="text" name="topride'.$xx.'" value="'.$row2['top_ride'].'"></td></tr>';
echo '<tr><td>Info : </td><td><input type="text" name="info'.$xx.'" value="'.$row2['info'].'"></td></tr>';
echo '<tr><td colspan="2"><hr></td></tr>';
}
?>
<tr><td>Password :</td><td><input type="password" value="" name="password" id="password"></td></tr>
<tr><td></td><td><input onclick="return check()" type="submit" value="Save" name="submit"></td></tr>
</table>
</form>
<?php
}else{
echo "No Rides in this park.";
}
}else{
if(isset($_GET['msg'])){echo $_GET['msg'].'<br>';}
$qry = "select * from tpf_parks order by name";
$res = mysql_query($qry);
?>
Select Park : <select name="park" onChange="getdata(this.options[this.selectedIndex].value)">
<option value="">Select Park</option>
<?php
while($row = mysql_fetch_array($res)) { ?>
<option value="<?=$row['park_id']?>"><?=$row['name']?></option>
<? } ?>
</select>
<?php } ?>
After testing what is not getting amended, it is data from both the LIKE and NOT LIKE queries being skipped so perhaps a record count problem?
Any ideas what I have done wrong?
Are you sure your column type has value 'Roller Coaster' or not?
Sorry to post as an answer as I have no rights no comment.

Categories