PHP Link does not work - php

echo "<td><input name='Send' type='button' value='Submit' onClick=location.href='save.php?myDocRegNo=$A&docCat=$C&dcrNo=$Dcr_No
&metTown=$Town_Code&dcrDate=$Dcr_Date&repCode=$Rep_Code&db=$Dbase' /></td>";
I have above link echoed in my php file and all my $ variables are set with values and the link works perfect.
But when I add two more variables &fullTown=$Town&fullRep=$FlRp to the same link and try to submit nothing happens and link does not work.Can anybody can identify the error ?Is there a variable limit for a HTML link?
echo "<td><input name='SendTest' type='button' value='SubmitTest' onClick=location.href='save.php?myDocRegNo=$A&docCat=$C&dcrNo=$Dcr_No
&metTown=$Town_Code&dcrDate=$Dcr_Date&repCode=$Rep_Code&db=$Dbase&fullTown=$Town&fullRep=$FlRp' /></td>";

please try this code its working fine
please try this code its workin fine
echo '<button onclick="window.location.href=\'save.php?myDocRegNo='.$A.'&docCat='.$C.'&dcrNo='.$Dcr_No.'&metTown='.$Town_Code.'&dcrDate='.$Dcr_Date.'&repCode='.$Rep_Code.'&db='.$Dbase.'&fullTown='.$Town.'&fullRep='.$FlRp.'\'">Continue</button>';
echo 'Continue';

please use this code it is working, i think there was only some blank space issue and i have change location.href change to window.location.href and it is working properly.
here is the code
echo "<td><input name='Send' type='button' value='Submit' onClick=window.location.href='save.php?myDocRegNo=$A&docCat=$C&dcrNo=$Dcr_No&metTown=$Town_Code&dcrDate=$Dcr_Date&repCode=$Rep_Code&db=$Dbase' /></td>";

Related

Javascript button wont work or show

I have been trying for few hours now to try and get this working. However, the code is working fine but the second button just does not show on my website. Could you please help?
echo "<td><input class=button_normal type=button value=Google Renter onclick=window.window.open(href='https://www.google.co.uk/')";
echo "<input class=button_normal type=button value=Yahoo onclick=window.window.open(href='https://www.yahoo.co.uk')</td>";
You haven't added quotations to onclick, value and class. You also forgot to close the input tag.
echo "<td><input class='button_normal' type='button' value='Google Renter' onclick='window.window.open.href=\'https://www.google.co.uk/\''/>";
echo "<input class='button_normal' type='button' value='Yahoo' onclick='window.location.href=\'https://www.yahoo.co.uk\''/></td>";
What I suggest is this:
<script>
function goToYahoo() {
window.open('https://www.yahoo.co.uk');
}
function goToGoogle() {
window.open('https://www.google.co.uk');
}
</script>
<?php
echo "<td><input class='button_normal' type='button' value='Google Renter' onclick='goToGoogle()'/>";
echo "<input class='button_normal' type='button' value='Yahoo' onclick='goToYahoo()'/></td>";
?>
window.location is a property not method:
window.location(href='https://www.yahoo.co.uk')
Should be:
window.location.href='https://www.yahoo.co.uk'
Basically in your code you are missing input tag closing "/>"
echo <<<"FOOBAR"
<td>
<input class="button_normal" type="button" value="Google Renter" onclick="window.open('https://www.google.co.uk/')"/>;
<input class="button_normal" type="button" value="Yahoo" onclick="window.open('https://www.yahoo.co.uk')"/>
</td>
FOOBAR;

how to declare a php variable in POST scope

I have this code and it works.
echo "<input type='submit' name='liga' value='Liga'>";
if (isset($_POST['liga'])) {
unset($_POST['liga']);
liga();
?>
But I need change the name LIGA to the php variable $on. I tried this but don't work.How can I insert the variable in this code?
$on=1;
echo "<input type='submit' name='$on' value='Liga'>";
if (isset($_POST['$on'])) {
unset($_POST['$on']);
liga();
}
?>
The problem here is that variables inside single quotes don't get interpolated whereas variables inside double quotes do.
echo "<input type='submit' name='$on' value='Liga'>";
becomes
<input type='submit' name='1' value='Liga'>
But $_POST['$on'] stays the same. To solve this, use $_POST[$on] (or the equivalent $_POST["$on"]).

action tag in a form didn't work out in google chrome

can anyone tell me why is that the action in the form tag is not working on google chrome?i use echo to display the the table and form..
i have this code..
echo "<form method='post' name='computation' action='savepagibigcomputation.php'>";
echo "<table>";
echo "<tr>";
echo "<td>Blocknumber:</td><td class='reset_border_left'><b><label>$blocknumber</label></td>";
echo "<input type='text' name='blocknumber' value='$blocknumber'>";
echo "</tr>";
echo "<tr>";
echo "<td>Lotnumber:</td><td><b><label>$lotnumber</label></td>";
echo "<input type='text' name='lotnumber' value='$lotnumber'>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='5' align='right'><input type='submit' name='save' value='RESERVE' class='button'/></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
so when i click the submit button the action should be excuted. In firefox is all working but in google chrome i really having a hard time to figure out why it will not re direct to the said action above??
any help is highly appreciated..
any one can help please..
Your HTML is not well-formed. Your <input type="text"> tags end outside of table cells. Make sure your inputs are inside cells (<td> or <th>) of the <table>.
If something doesn't work, validating your HTML (in browser right click -> view source) with W3C HTML validator should be the first step in debugging, before trying to think what else could be wrong.
If fixing the HTML doesn't work, try looking at developer tools in Firefox (Firebug) or Chrome (Developer tools are integrated in Chrome) both at the DOM and the HTTP request the browser tries to make when you hit submit.
If it still doesn't work, you should provide us with a link so we don't have to guess (especially when your HTML is dynamic) what's wrong - we could instantly see what's wrong. For all we know, the issue might not even be in the code you posted, it could be a HTML formatting error somewhere else in <head> or <body>
Sometimes Chrome can mess with markup if there is an error in it. I suspect that the error is due to some other part of the code and not the part you have pasted here. Try this extract, it works on my chrome, this will rule out that element of your problem:
<?
$blocknumber = 1;
$lotnumber = 3;
echo "<form method='post' name='computation' action='savepagibigcomputation.php'>";
echo "<table>";
echo "<tr>";
echo "<td>Blocknumber:</td><td class='reset_border_left'><b><label>$blocknumber</label></td>";
echo "<input type='text' name='blocknumber' value='$blocknumber'>";
echo "</tr>";
echo "<tr>";
echo "<td>Lotnumber:</td><td><b><label>$lotnumber</label></td>";
echo "<input type='text' name='lotnumber' value='$lotnumber'>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='5' align='right'><input type='submit' name='save' value='RESERVE' class='button'/></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
?>

onclick action not working as intended with radio buttons

For the last 4 hours I've been struggling to get something to work. I checked SO and other sources but couldn't find anything related to the subject. Here is the code:
<?php
$email=$_SESSION['email'];
$query1="SELECT * FROM oferte WHERE email='$email'";
$rez2=mysql_query($query1) or die (mysql_error());
if (mysql_num_rows($rez2)>0)
{
while ($oferta = mysql_fetch_assoc($rez2))
{
$id=$oferta['id_oferta'];
echo "<input type='radio' name='selectie' value='$id' id='$id'> <a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a>";
echo "</br>";
}
echo "</br>";
//echo "<input type=\"button\" id=\"cauta\" value=\"Vizualizeaza\" onclick=\"window.location.href='oferta.php?id={$oferta['id_oferta']}'\" />";
//echo " <input type=\"button\" id=\"cauta\"value=\"Modifica\" onclick=\"window.location.href='modifica.php?id={$oferta['id_oferta']}'\" />";
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
echo "</form>";
echo "</div>";
}
else
{
}
?>
The while drags all of the user's entries from the database and creates a radio button for each one of them with the value and id (because I don't really know which one is needed) equal to the entry's id from the db. I echoed that out and the id is displayed as it should so no problems there.
The delete script works ok as well so I won't attach it unless you tell me to. All good, no errors, until I try to delete an entry. Whatever I choose from the list of entries, it will always delete the last one. Note that I have two other inputs echoed out, those will be the "view" and "modify" buttons for the entry.
I really hope this is not JavaScript related because I have no clue of JS. I think this will be of major help to others having this problem. Please let me know if I need to edit my question before downrating. Thanks!
After edit:
This is the delete script, which as I said earlier works fine.
<?php
if (isset($_GET['id']))
{
$id = $_GET['id'];
echo $id;
require_once('mysql_connect.php');
$query = "DELETE FROM oferte Where id_oferta = '$id'";
mysql_query($query) or die(mysql_error());
//header('Location: oferte.php');
}
else
{
//header('Location: oferte.php');
}
?>
The session is started as well, like this:
<?php
session_start();
?>
The reason the last $id is deleted is because this line is outside/after the while loop:
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
You want to move this line inside the loop so that you have a button that executes delete for each radio button.
Update:
To have links to delete and
echo "<input type='radio' name='selectie' value='$id' id='$id'> ";
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a> ";
echo "<a href='delete.php?id=$id'>delete</a>";
Also I do not think the radio button is needed here at all since you are not really doing anything with it. You could simply echo out the value of your choice and have these links as follows:
echo $oferta['denumire_locatie'] . ' '; // replace $oferta['denumire_locatie'] with something of your choice
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a> ";
echo "<a href='delete.php?id=$id'>delete</a>";
echo "<br />";
The problem, in this case, is JavaScript related, yes. What I recommend you to do is to simply add a Remove link for each item.
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a>";
echo " - <a href='delete.php?id={$oferta['id_oferta']}'>Remove</a>";
echo "</br>";
Your $id is outside your while() loop.
The last one is getting deleted because the $id has the last one's value when the loops is exited.
Include all your code :
echo "</br>";
//echo "<input type=\"button\" id=\"cauta\" value=\"Vizualizeaza\" onclick=\"window.location.href='oferta.php?id={$oferta['id_oferta']}'\" />";
//echo " <input type=\"button\" id=\"cauta\"value=\"Modifica\" onclick=\"window.location.href='modifica.php?id={$oferta['id_oferta']}'\" />";
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
Inside your while loop.
When the rendered html reaches the browser, it will be something like this:
<input type='radio' name='selectie' value='1' id='1'> <a href='oferta.php?id=1'>TEXT</a>
<input type='radio' name='selectie' value='2' id='2'> <a href='oferta.php?id=2'>TEXT</a>
<input type='radio' name='selectie' value='3' id='3'> <a href='oferta.php?id=3'>TEXT</a>
<input type='radio' name='selectie' value='4' id='4'> <a href='oferta.php?id=4'>TEXT</a>
<br/>
<input type="button" id="sterge" value="Sterge" onclick="window.location.href='delete.php?id=5'" />
With this markup you won't be able to accomplish what you want without using javascript to update the onclick attribute whenever you select a radio button.
On the other hand, instead of using the client-side onclick event you can use the button's default behaviour, which is to submit the form.
You'll just have to set the action attribute:
<form method="post" action="http://myurl.php">
and write the myurl.php page which will just read the posted variable $_POST['selectie'] and call the delete method with the posted id.

Form not passing any values

I have a form that I'm submitting using jQuery $.post(). It doesn't submit any variables.
Here's the jQuery code:
$('#eb1').live('click',function() {
$.post("php/emailPost.php", $("emailPost").serialize(), function(){
$("#emailModal").dialog('close');
$('#emailJQButton').attr('value', 'Emailed');
});
});
The post file returns no errors, and everything else is working fine. It's only the fact that no values are passed (I checked with Firebug).
Here's a portion of the PHP code outputting the form itself (don't say anything about HEREDOC, it does not work for me, case closed):
echo "<form action='php/emailPost.php' method='POST' class='inline' id='emailPost'>";
echo "<input type='hidden' value='" . $_SESSION["email"] . "' name='emailAddress'>";
echo "<input type='button' value='Email To Me' id='eb1'/>";
echo "<input type='hidden' name='passedCoupID' value='" . $coupID . "'/>";
echo "</form>";
I don't see anything obvious why it doesn't pass any values. Other similarly-written forms pass variables correctly. $coupID is pre-populated by the page.
Any help?
$("emailPost").serialize()
Should be
$("#emailPost").serialize()
change $("emailPost").serialize() to $("#emailPost").serialize() or $("form").serialize()

Categories