Page not found when my submitting my php form - php

i have this form i built using php the form is supposed to search for a user in formation in my database, but when i fill in the search box and click ok it will try to load process.php instead of the search.php i assigned it to redirect to and for that reason it shows me "PAGE NOT FOUND" *** and for the refrence it is a wordpress plugin that i want to use on my website that i am trying to build
this is the code
add_action( 'admin_menu', 'addAdminMenu' );
function addAdminMenu(){
add_menu_page('ClassifiedBr Settings', 'ClassifiedBr', 'manage_options', 'classifiedbr_settings_page', 'classifiedbr_init', '', 3);
add_submenu_page('classifiedbr_settings_page','Classified Sub', 'Classified Sub','manage_options', 'classified_sub_slug', 'stracking_init');
}
function classifiedbr_init(){
echo '<form action="demo.php" method="post" />';
echo "<h1>Britchi Tracking</h1>";
echo '<p>';
echo 'Costumers Name (required) <br/>';
echo '<input type="text" name="cname" placeholder="Emmanuel John"/>';
echo '</p>';
echo '<p>';
echo 'Tracking number (required) <br/>';
echo '<input type="text" name="ctracking" placeholder="EEX28PDS"/>';
echo '</p>';
echo '<p>';
echo 'Email (required) <br/>';
echo '<input type="email" name="cemail" placeholder="Email"/>';
echo '</p>';
echo '<p>';
echo 'Recived Port (required) <br/>';
echo '<input type="text" name="crport" placeholder="Brazil Port"/>';
echo '</p>';
echo '<p>';
echo 'Delivered Port (required) <br/>';
echo '<input type="text" name="cdport" placeholder="Lagos Port"/>';
echo '</p>';
echo '<p>';
echo 'Current Location (required) <br/>';
echo '<input type="text" name="clocation" placeholder="Abuja" />';
echo '</p>';
echo '<p>';
echo 'Destination (required) <br/>';
echo '<input type="text" name="cdestination" placeholder="Total filling Station, Abuja"/>';
echo '</p>';
echo '<p><input type="submit" name="cregistered" value="Register"></p>';
echo '</form>';
}
function stracking_init(){
echo '<form action="search.php" method="post" />';
echo "<h1>Britchi Tracking</h1>";
echo '<p>';
echo 'Costumers Name (required) <br/>';
echo '<input type="text" name="search" placeholder="Emmanuel John"' . '" size="70"/>';
echo '</p>';
echo '<p><input type="submit" name="csearch" value="Search"></p>';
echo '</form>';
}
add_shortcode('TRACSEARCH', 'stracking_init');
?>
in this code I have 2 forms the first one (classifiedbr_init)sending to demo.php and the second one (strackinh_init) sending to search.php
as you can see the classifiedbr_init and the stracking_init functions will show on the admin page but only the stracking_init will show on the the frontend becouse i created a shortcode for it
this is the search.php code
<table border="">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>RecivedPort</th>
<th>DestinationPort</th>
<th>Location</th>
<th>Destination</th>
</tr>
<?php
$conn=mysqli_connect("localhost","root","","class");
$set=$_POST['search'];
if($set) {
$show="SELECT * FROM demo where fname='$set'";
$result=mysqli_query($conn, $show);
while($rows=mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>";
echo $rows['cname'];
echo "</td>";
echo "<td>";
echo $rows['ctracking'];
echo "</td>";
echo "<td>";
echo $rows['cemail'];
echo "</td>";
echo "<td>";
echo $rows['crport'];
echo "</td>";
echo "<td>";
echo $rows['cdport'];
echo "</td>";
echo "<td>";
echo $rows['clocation'];
echo "</td>";
echo "<td>";
echo $rows['cdestination'];
echo "</td>";
echo "</tr>";
echo "</br>";
}
}
else{
echo "nothing found";
}
?>
</table>
thanks as you help me out

Related

How to edit a database row value from a html table

so i have a form with like 6 fields(FirstName,LastName,etc),when the users submit the form,the values are saved in a database.In another page i have a table which shows those values from database,with same 6 cols + another one which contains 2 buttons(delete and edit),the delete one works perfect,but the edit buttons has some issues
The buttons code is this:
echo '<td>';
echo '<button>Modifica!</button>';
echo '<button>Sterge!</button>';
echo '</td>';
As you can see i have assigned rand id(this is the primary key for databse rows) to the var idang.
$idang=$_GET['idang'];
if(isset($idang)) {
$CerereSQL="SELECT * FROM `angajati` WHERE id='$idang'";
$rezultat=mysqli_query($con,$CerereSQL);
$rand=mysqli_fetch_assoc($rezultat);
I've made another variable with the global var $_GET['idang'],and then i have SELECTED the table angajati from database where the primary key from my db its equal with the primary key from the table row,which i've pushed the edit button.This method works for the delete button,and probably for the edit one too,but the real problem is that when i want to edit that row,it will link me to another page containing another form,with original values in the fields,and when i modify those fields with other values,it must change only that row,not the entire table,or the column.But i have no idea how to do that,except that it can be done with the UPDATE statement
The rest of the code,containing the form is:
echo '<table border=0 align=center cellspacing=10>';
echo '<form action="" method=post>';
echo '<tr>';
echo '<th>Nume:</th><td><input type="text" name=nume value="';
echo $num;
echo '"></td>';
echo '<td style=color:red>';
echo $err_nume;
echo $err_nume1;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>Prenume:</th><td><input type="text" name=prenume value="';
for($value=1;$value<count($nume);$value++) {
$c=$c."".$nume[$value];
}
echo $c;
echo '"></td>';
echo '<td style=color:red>';
echo $err_prenume;
echo $err_prenume1;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>CNP:</th><td><input type="text" name=cnp value="';
echo $cnp;
echo '"></td>';
echo '<td style=color:red>';
echo $err_cnp;
echo $err_cnp1;
echo $err_cnp2;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>Data angajare:</th><td><input type="text" name=data value="';
echo $rand['data'];
echo '"></td>';
echo '<td style=color:red>';
echo $err_data;
echo '</td>';
echo '</tr>';
$companii=array("S.C. 2K Telecom S.R.L.", "S.C. Accessnet International S.R.L.", "S.C. Ad Net Market Media S.A.", "S.C. Idilis S.R.L.", "S.C. Infratel Net S.R.L.");
echo '<tr>';
echo '<th>Compania:</th>';
echo '<td>';
echo '<select name=companie>';
//echo '<option value="alege">Alege compania</option>';
//if(!isset($_POST['companie'])){
echo '<option value='.$companie.'>'.$companie.'</option>';
$key=array_search($companie, $companii);
unset($companii[$key]);
//}
foreach($companii as $firme) {
echo '<option value="'.$rand['companie'].'"';
if(isset($_POST['companie']) && $_POST['companie'] == $firme) {echo " selected";}
echo ">$firme</option>";
}
echo '</select>';
echo '</td>';
echo '<td style=color:red>';
echo $err_companie;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>Functia:</th><td><input type="text" name=functie value="';
echo $rand['functie'];
echo '"></td>';
echo '<td style=color:red>';
echo $err_functie;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align=center><a href=tabel.php><input type=button name=button value=Inapoi!></a></td>';
echo '<td align=center><input type=submit name=submit value=Introducere! ></td>';
echo '<td align=center><input type=reset name=reset value=Resetare! ></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2" align=center>'.$up.'</td>';
echo '</tr>';
echo '</form>';
echo '</table>';
So this form contains the old values from the table row i've pressed the button,and i want to cahnge with new values.Any idea?
Here is basic example to update name column of your table. Get other fields and add in the query.
if(isset($_POST['submit'])) {
//echo "<pre>";print_r($_POST);exit; // to check your post data
$name = $_POST['nume'];
$query = "UPDATE table_name set name='$name' where id=$idang";
mysqli_query($query); //run the query
}
echo '<form action="abc.php" method=post>'; // add action
abc.php
If($_POST)
{
// fetch values from post
// update query
}
in else you can do if $_GET then insert.
I think from this you will get an idea to solve.

calculating the sum of an array php

Hi im currently doing making a website that sells games as a project but im having problems calculating the sum for the price of the games
I have this loop which displays the games added into the basket
cart.php
<?php
$count = 0;
while ($count < $numrow)
{
$row = $results -> fetch_assoc();
extract($row);
echo"<div>";
echo"<div class='recommended_games'>";
echo "<img src='images/".$gameIMG."' />";
echo "</div>";
echo '<div class="price_tag">';
echo '<div class="price_tag" name="price" method="POST">£'.$gamePrice. '</div>';
echo'</div>';
echo '<div id="update_form"><form action="updatebasket.php" method="POST" name="updateform">';
echo '<select name="quantity" id="quantity" />';
echo '<option value="1">1</option>';
echo '<option value="2">2</option>';
echo '<option value="3">3</option>';
echo '<option value="4">4</option>';
echo '<option value="5">5</option>';
echo '</select>';
echo '<input type="hidden" value="'.$gameID.'" name="gameid" id="gameid" />';
echo '<input type="submit" value="update" />';
echo '</form>';
echo '<div class="quantity_update">';
echo '<form action="remove_item.php" method="POST">';
echo '<input type="hidden" value="'.$gameID.'" name="gameid" id="gameid" />';
echo '<input type="submit" value="Remove Item" />';
echo '</form>';
echo '</div>';
echo '</div>';
echo"<img class='box1' src='Images/Grey-Banners.png' />";
echo"</div>";
$count = $count + 1;
}
echo '<div id="delete_all">';
echo '<form action="delete_cart.php" method="POST">';
echo '<input id="hide_button" type="submit" value="Clear All" />';
$a=array($gamePrice);
echo array_sum($a);
echo '</form>';
echo '</div>';
?>
this is where im trying to calculate the total price
$a=array($gamePrice);
echo array_sum($a);
The reason this doesnt work, is because $gamePrice never is an array (unless you didnt provide all code). In the loop, it gets set to a new value, after the loop only the last one is stored.
Based on some hints in your code, I guessing this is a cart and you're looping through the cart. An easy way to get a total is like this:
$total = 0;
while( $itemsThatWeLoop){
// Some code here
$total+= $gamePrice*$quantity;
}
You add a variable which increments with the product's price
To explain the while-only-last-value-saved:
$i=0;
while( $i<=10){
$i= $i+1;
}
echo $i;
Will give 10. All other iterations $i gets set to a new value. The original value is not saved

Is there a more efficient way to do this PHP code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
This code works and is fine, but I was wondering if there was an easier way to code something like this?
<?php
while($rows=mysql_fetch_array($result)){
$pid=$rows['id'];
$d = $rows['date'];
echo '<style>tr, td {border:0;} #dat{text-align:right;} #co {background-color:#33B533;} </style>';
echo '<div id="postd">';
echo '<table id="mdata">';
echo '<tr>';
echo '<td>';
echo '<a href="profile.php?name=';
echo $rows['name'];
echo '">' . $rows["name"] . '</a>';
echo '</td>';
echo '<td id="dat">';
echo $result7 = nicetime($d);
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo $rows['post'];
echo '</td>';
echo '<td id="dat">';
echo '<form method="post" action="delete.php">';
echo '<input type="hidden" value="';
echo $rows['id'] . '" name="id" />';
echo '<input id="sub" type="submit" name="delete" value="Delete" />';
echo '</form>';
echo '<form method="post" action="edit.php">';
echo '<input type="hidden" value="';
echo $rows['id'] . '" name="id" />';
echo '<input id="sub" type="submit" name="edit" value="Edit" />';
echo '</form>';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
$sql9 = "SELECT * FROM `like` WHERE postid='$pid' AND userid='$userid'";
$result9=mysql_query($sql9);
if($result9){
echo '<form method="post" action="like.php">';
echo '<input type="hidden" value="';
echo $rows['id'] . '" name="id" />';
echo '<input type="hidden" value="';
echo $userid . '" name="nid" />';
echo '<input id="sub" type="submit" name="like" value="Like" />';
echo '</form>';
}
echo '</td>';
echo '<td id="dat">';
if ($rows['like'] == 1) {
echo $rows['like'] . " Like";
} else if ($rows['like'] == 0) {
echo "";
} else {
echo $rows['like'] . " Likes";
}
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
$sql2="SELECT * FROM comments WHERE postid='$pid' ORDER BY date ASC";
$result2=mysql_query($sql2);
while($rows2=mysql_fetch_array($result2)){
$c = $rows2['date'];
echo '<table id="co" border="1px solid black" width="250px" align="center">';
echo '<tr>';
echo '<td>';
echo $rows2['name'];
echo '</td>';
echo '<td id="dat">';
echo $result4 = nicetime($c);
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo $rows2['comment'];
echo '</td>';
echo '</tr>';
echo '</table>';
}
echo '<form action="addcomment.php" method="post">';
echo '<table id="co" border="1px solid black" width="250px" align="center">';
echo '<tr>';
echo '<td>';
echo '<textarea id="target" type="text" name="com" placeholder="Comment"></textarea>';
echo '</td>';
echo '<td>';
echo '<input type="submit" name="submit" value="Post">';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<input type="hidden" value="';
echo $rows['id'] . '" name="id" />';
echo '<input type="hidden" name="name" value="Jon" />';
echo '</form>';
echo '<br/>';
}
?>
Basically I've created a Facebook type system. This spools the posts down in the order they are posted in the database. Check it out at http://bockhorst.comeze.com/Wall/wall.php Its still a work in progress. Also does anyone know a php compressor?
The more efficient way to do this is to use a proper development framework that provides some structure and cohesion to your code. What you have here is a stew of SQL, HTML, and code. It's extremely hard to maintain an application written like this.
Additionally you're using the woefully out of date mysql_query interface. Please, don't. It's terrible. You really should be using an ORM to handle your routine database interfacing, something like Doctrine or Propel. These make it easier to compose the queries correctly and deal with the data instead of being stuck trying to render all your application logic directly in SQL.
If you're dead-set on doing SQL by hand, PDO is the way to go.

Function not Inserting Values in wordpress

function name_to_match($nametocheck){
global $wpdb,$namematch,$nomatchfound;
$query="select * from currency";
$namematch=$wpdb->get_col($query,1);
//echo $namematch;
foreach($namematch as $namet){
//echo $name;
if($namet == $nametocheck){
echo "Name Already Exists<br />";
$nomatchfound=0;
}
}
}
function add_signal_form(){
global $wpdb,$insert,$nametocheck;
echo "<br /><br /><br />";
$nametocheck=trim($_POST['name']);
$sign=trim($_POST['sign']);
$status=$_POST['status'];
if(isset($_POST['submit'])){
//..................Function to call if name exist it will not add
name_to_match($nametocheck);
if($nomatchfound ==0){
echo "Match Found";}
else
{
$insert= $wpdb->insert('currency',array('name'=>$nametocheck,'sign'=>$sign,'status'=>$status));
if(!$insert){
echo "Currency Not Added Query Fails";
}
else
{
echo "Currency Successfully Added";
}
}
}
echo '<form name="form1" method="post" action="">';
echo '<div class="label">';
echo '<label for="name">Name</label>';
echo '<div class="field">';
echo '<input type="text" name="name" id="name">';
echo '</div>';
echo '<div class="label">';
echo '<label for="sign">Sign</label>';
echo '</div>';
echo '<div class="field">';
echo '<input type="text" name="sign" id="sign">';
echo '</div>';
echo '<div class="label">';
echo '<label for="status">Status</label>';
echo '</div>';
echo '<div class="field">';
echo '<select name="status" id="status">';
echo '<option value="1">Publish</option>';
echo '<option value="0">Draft</option>';
echo '</select>';
echo '</div>';
echo '<div class="submit">';
echo '<input type="submit" name="submit" id="submit" value="Save Currency">';
echo '</div>';
echo '</p>';
echo '</form>';
/*
echo "<form action='' name=form1\" id=\"form1\" method=\"post\">";
echo '<input type="text" name="text" id="text">';
echo '<input type="submit" name="submit" value="Add New Signal">';
//wp_dropdown_pages();
echo "</form>";
*/}
This function working properly if name exist it return exists but when it not exist nothing happen no else clause fire what is the problem. I am doing something wrong . i want after checking it submit the form and show success message when currency added but nothing happening i try whole the day long and at last i fails in it suggest me
As #akirk suggested, you're never setting $nomatchfound to true or 1 in your name_to_match function.
But there are some other things you could do to make the code clearer and quicker. For example, name_to_match could return a value, instead of setting a global variable. And you could use the database to check for $nametocheck, rather than looping over all the values in the table - it'll make your code shorter and it'll run quicker. So I'd change name_to_match to something like this:
function name_to_match($nametocheck){
global $wpdb;
$query = $wpdb->prepare("select count(*) from currency where name = %s", $nametocheck);
$matching_row_count = $wpdb->get_var($query);
return $matching_row_count;
}
Then the start of your add_signal_form function becomes
function add_signal_form(){
global $wpdb;
echo "<br /><br /><br />";
$nametocheck=trim($_POST['name']);
$sign=trim($_POST['sign']);
$status=$_POST['status'];
if(isset($_POST['submit'])){
$existing_rows = name_to_match($nametocheck);
if($existing_rows != 0){
echo "Match Found";
}
else {
$insert= $wpdb->insert('currency',array('name'=>$nametocheck,'sign'=>$sign,'status'=>$status));
if (!$insert) {
echo "Currency Not Added Query Fails";
}
else {
echo "Currency Successfully Added";
}
}
}

Can not get PHP to post info to database

I've written a script to post information into my database for I can't get it to post and need help pointing out what I'm missing.
my php post for looks like this:
$query = "SELECT * from departments";
$res = mysql_query($query);
echo '<div id="department" >';
echo '<form action="depedit.php" method="post">';
echo '<input type="text" placeholder="Search departments">';
echo '<br>';
echo '</form>';
echo '</div>';
echo '<div id="depadd">';
echo '<form>';
echo '<table width="0" border="0">';
echo '<tr>';
echo '<td>Name:</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo "<select name='depid'>";
while ($row = mysql_fetch_array($res)) {
echo "<option value='".$row['id']."'>".$row['depname']."</option>";
}
echo "</select>";
echo '</td>';
echo ' </tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo ' <tr>';
echo '<td><label class="limit">Select Limit for active courses in Learning Locker:</label></td>';
echo ' </tr>';
echo ' <tr>';
echo '<td>';
echo "<select name='courselimit'>";
echo "<option value='1'>1</option>";
echo "<option value='2'>2</option>";
echo "<option value='3'>3</option>";
echo "<option value='4'>4</option>";
echo "<option value='5'>5</option>";
echo "<option value='0'>Unlimited</option>";
echo "</select>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="radio" id="1" name="senabled" value="1"/><label for="c1" class="required">Required<br>(Study Shredder Feature Enabled)</br></label></td>';
echo '<td><input type="radio" id="0" name="senabled" value="0"/><label for="c1" class="optional">Optional</label></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="orgid" value="'.$adminorgid.'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="createdby" value="'.$userid.'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="timecreated" value="'.time(now).'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo ' <tr>';
echo ' <td><button type="submit" class="btn">Submit</button></td>';
echo ' </tr>';
echo '</table>';
echo "</form>";
echo '</div>';
depedit.php looks like this:
$adddep = "INSERT INTO organization_dep (orgid,depid,courselimit,senabled,createdby,timecreated) VALUES ('".$_POST["orgid"].",".$_POST["depid"].",".$_POST["courselimit"].",".$_POST["senabled"].",".$_POST["createdby"].",".$_POST["timecreated"]."')";
$res = mysql_query($adddep);
if ($res === TRUE) {
echo "Department added successfully";
} else{
printf("Could not create department");
}
the correct information seems like its getting passed as the url displays the following information in it:
/index.php?depid=6&courselimit=3&senabled=1&orgid=9&createdby=1129&timecreated=1364005206
any help with this would be greatly appreciated as I'm sure its something simple that I'm just over looking.
You want to get the values from the $_POST
('".$_POST["orgid"].",".$_POST["depid"].",".$_POST["courselimit"].",".$_POST["senabled"].",".$_POST["createdby"].",".$_POST["timecreated"]."')";
but your saying it is passed through the URL, this looks like you need to use $_GET to get the values
--- and one small tip you can use echo to print multiple lines it works. as long as you close it, in the end
e.g
echo " <html>
<body>
</body>
</html>
";
I think you have a bunch of things to get right before this will be working:
Only the first form, which seems to be for searching departments, have method and action attributes
Since the second form does not have the action attribute, it is not submitting to depedit.php but to the same page that has the form.
Since the second form does not have the method attribute, it defaults to GET, and you are trying to read out POST variables in your PHP. If it was not using GET, you would not see those params in the resulting URL.
In your SQL insert statement, you must have single quotes around every single text value but not around int values. Now you have one single quote before the first value and one before the last which makes no sense.
First: this portion will not be POSTed "depedit.php" because there is no submit
echo '<form action="depedit.php" method="post">';
echo '<input type="text" placeholder="Search departments">';
echo '<br>';
echo '</form>';
Second: this will never be POSTed to depedit.php, since your <form> does not have an action specifying "depedit.php"
echo '<form>';
echo '<table width="0" border="0">';
echo '<tr>';
//other codes
echo "</form>";
maybe you mean to remove the first echo '</form>'(line 7) and the second <form>(line 10)

Categories