Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
In the following code, everything works except that when you click the submit button, nothing happens at all
Please tell me what's wrong, the connection and everything is fine (it is included in the Header.php file) and submit forms on other pages work, but this one seems to just do nothing, page doesn't even load
Thanks!
Here is the code
<?php
//connection is in header
include "../Header.php";
//checks if logged in
if (!$User)
{
header("Location: ../index.php"); exit();
}
//heres the form
echo"<form><center><br /><br /><br /><br /><font size='3'><br />You are changing your Post Color<br />
Your current color is $myU->PostColor<br /><br /></font><form>
Color:<br /><textarea name='color' rows='1' cols='15'></textarea><br /><br />
<input type='submit' name='Submit' value='submit'></form></center></form>";
$Color = mysql_real_escape_string(strip_tags($_POST['Color']));
$submit = mysql_real_escape_string(strip_tags($_POST['submit']));
if ($submit) {
mysqli_query("UPDATE `socialli_main`.`Users` SET `PostColor` = '$Color' WHERE `Users`.`ID` ='$myU->ID'");
header("Location: ../index.php"); exit();
}
include "../Footer.php";
A submit button will submit the form that it is inside. You don't have a <form> element at all. You need to add one.
More importantly than adding a <form> tag is actually setting attributes on it. Try the following.
<form action='' method='POST'>
And you also end your </form> tag many times...
Here is how I would fix up your code anyways:
<?php
//connection is in header
include "../Header.php";
//checks if logged in
if (!$User)
header("Location: ../index.php"); exit();
?>
<form action='' method='POST'>
<div style="text-align:center;">
<br /><br /><br /><br /><br />
<span style="font-size:1.6em;">
You are changing your Post Color
</span><br>
<span style="font-size:1.3em;">
Your current color is <?=$myU->PostColor?>
</span><br>
Color:<br />
<textarea name='color' rows='1' cols='15'></textarea>
<br /><br />
<input type='submit' name='Submit' value='submit'>
</div>
</form>
<?php
$Color = mysql_real_escape_string(strip_tags($_POST['Color']));
$submit = mysql_real_escape_string(strip_tags($_POST['submit']));
if ($submit){
mysqli_query("UPDATE `socialli_main`.`Users` SET `PostColor` = '$Color' WHERE `Users`.`ID` ='$myU->ID'");
header("Location: ../index.php"); exit();
}
include "../Footer.php";
?>
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I've created a website where I can upload articles however im having trouble with updating articles that have been created. I have managed to fill in a form with the information from the database pre-filled in but when i submit any changes then to the article then it does not update.
The $var_value is the primary key passed from the previous page to determine which article to load & edit.
Here is my form to update the article.
<?php
$var_value = $_POST['varname'];
$get_studies = "select * from news where `news`.`articleID` = $var_value";
$run_studies = mysqli_query($con,$get_studies);
while($row_studies = mysqli_fetch_array($run_studies)){
$newsTitle = $row_studies['title'];
$newsDate = $row_studies['date'];
$shortBio = $row_studies['shortBio'];
$longBio = $row_studies['longBio'];
$longBio2 = $row_studies['longBio2'];
$image = $row_studies['image'];
}
echo "
<div class='panelContent1' id='addNewsWraper'>
<h2>Dashboard</h2>
<h3>Update Article</h3>
<form method='post' enctype='multipart/form-data' onsubmit='alert('stop submit'); return false;' >
<div class='newsForm'>
<p>Article Title<br /><input type='text' value='$newsTitle' name='newsTitle' /></p>
<p>Short Description<br /><textarea name='newsShort' placeholder='Around a paragraph' />$shortBio</textarea>
<p>Image<br /><input type='file' name='newsImage' /></p>
</div>
<div class='newsForm'>
<p>Date<br /><input type='text' value='$newsDate' name='newsDate' placeholder='2017' /></p>
<p>Story<br /><textarea name='newsLong' placeholder='News article text' />$longBio</textarea>
<p>Story2<br /><textarea name='newsLong2' value='' placeholder='News article text' />$longBio2</textarea>
<button type='submit' name='updateNews'>
Update
</button>
</div>
</form>
</div>
";
?>
Here is how i am trying to update the article. I have tried to update the record based on a primary key, this variable is being passed to the page as its what is loading the content in the form.
<?php
if(isset($_POST['updateNews'])){
$newsTitle = $_POST['newsTitle'];
$newsDate = $_POST['newsDate'];
$newsShort = $_POST['newsShort'];
$newsLong = $_POST['newsLong'];
$newsLong2 = $_POST['newsLong2'];
$newsImage = $_POST['newsImage'];
$insertNews = "UPDATE mods SET title='$newsTitle', date='$newsDate', shortBio='$newsShort', longBio='$newsLong', longBio2='$newsLong2', image='$newsImage' WHERE articleID='$var_value'";
$updateNews = mysqli_query($con,$insertNews);
if($updateNews){
echo "<script>alert('Article updated.');</script>";
}
}
?>
You say $var_value is being passed to your php update script, but I cannot see that is is, nor is it being picked up by a POST and transferred to a local variable. Pass it as a <input type="hidden" and then pick up with a POST to use.
In first php script:
<p>Article Title<br /><input type='text' value='$newsTitle' name='newsTitle' />
<input type="hidden" value='$var_value' name='var_value' />
</p>
In second php script:
$var_value = $_POST['var_value'];
It would also be good to look at protecting your script from sql injection by using a parameterized query.
There is a problem with your query
insertNews = "UPDATE mods SET title='$newsTitle' date='$newsDate' shortBio='$newsShort' longBio='$newsLong' longBio2='$newsLong2' image='$newsImage' WHERE articleID='$var_value'";
Replace this with your current Query you will be good to go.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm new in php and i have an issue in creating a form and geting the posted values.
I have two pages login.php and display.php
I need to display in the display page the two values i have inserted on login page using a php function.
>How can I use GET to retrieve my values?
Thanks for your answer.
what i realy whant to do is this:
login page:
<html>
<body>
<form action="./display.php" method="Post">
<h3>
<fieldset>
<?php
echo"<label for='username'>Username:</label>";
echo"<input type='text' name='username' id='username' size='10' title='Username' />";
echo"<label for='password'>Password:</label>  ";
echo"<input type='password' name='password' id='password' size='10' title='Password'/>";
function getvalue(){
// i want to use this function to get the username and password
}
?>
</fieldset>
<br>
<a id="myLink" title="forum" href="./display.php" onClick="getvalue()";return false;">link text</a>
</form>
</body>
</html>
what shoul i do, i know that what i wrote is so incorrect
If your form is something like this:
<form method="get" action="display.php">
<input type="text" name="username" />
<input type="password" name="password"/>
</form>
You can use php in display.php like this:
<?php
echo $_GET['username']."<br />";
echo $_GET['password']."<br />";
?>
If you use this option, your URL would look like:
http://example.com/display.php?username=something&password=somethingelse
This is NOT what you want.
However, I would use POST as it is more secure.
You can do this by changing the method to:
method="post"
and in display.php changing it to:
echo $_POST['username']."<br />";
echo $_POST['password']."<br />";
The URL will look like this then:
http://example.com/display.php
NOTE: Just so you know, do not ever send a password over GET! This is just an example. Anyone who does this is an idiot.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
$redirect=$_GET["r"];
if ( isset($_GET["r"]) ){
header("location: http://" .$redirect);
} else {
$redirect = "mickiewiki.nl/login/profile.php";
header("location: http://" .$redirect);
this code won't work? I want it to be like if I go to mickiewiki.nl/login/login.php?r=mickiewiki.nl/Doneer.php that when I login I go back to the page Doneer.php
When I login, I am always being sent to profile.php no matter if I add my r or not
<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$database = mysql_select_db('***', $con) or die(mysql_error());
//include out functions file giving us access to the protect() function made earlier
include "login/functions.php";
$selectedid = $_GET['id'];
if(empty($selectedid)) {
$selectedid = $_SESSION['uid'];
}
if(strcmp($_SESSION['uid'],"") == 0){
header("location: login/login.php?r=mickiewiki.nl/Doneer.php");
} else {
?>
In your form on your website, you are not setting r through GET. You have username, password & submit for your form - and nothing for GET. If you are submitting r with your form (which I cannot see that you are), then you should probably be checking for $_POST['r'] instead of $_GET['r'].
Basically, you need to add a hidden field for your r variable and submit that along with your form.
<form method="post" action="login.php">
<input type="hidden" name="r" value="<?php print $_GET['r']; ?>">
<p><label for="name">Username: </label>
<input type="text" name="username" /></p>
<p><label for="pwd">Password: </label>
<input type="password" name="password" /></p>
<p>
<input type="submit" id="submit" value="Login" name="submit" />
</form>
but, you must do a control for $_GET["r"] ... and why it doesn't work?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is page 2
$var= $_GET['var'];
$id= $_GET['id'];
echo "Book Title:<br>" .$var. "<br> Book id:".$id."<br>";
$result = mysqli_query($con,"SELECT * FROM books WHERE bookid='$id'");
while ($row = mysqli_fetch_array($result)) {
echo "<br><br>Author:<br>".$row['author'];
echo "<br><br>Average rating is:<br>" .$row['avgrating'];
}
?>
<form name='myForm' action='addreview.php' method='POST' >
Give your reviews here:<br>
<input type='textarea' name='review' style='width: 500px; height:200px' ><br>
<input type='hidden' id='ids' name='ids' value=''<?php echo $id ?> ''>
<input type='SUBMIT' name='done' value='DONE'>
</form>
on page 1 I am retrieving bookid from database and then passing it to page 2, and then i have to pass it to page 3. on page 3 I am retrieving it with GET command but it is not working. Kindly help me
$_GET and $_POST in PHP correspond to the form method= in the HTML. If your form's method="POST", you must use $_POST to get to the value.
You've got too many quotes:
<input type='hidden' id='ids' name='ids' value=''<?php echo $id ?> ''>
^^-- ^^--
That'll produce HTML that will be interepreted as (for an id of 8):
<input [...snip...] value="" 8 "" />
value gets an an empty string, followed by an invalid attribute 8, followed by a couple quotes that aren't a valid attribute OR value.
If you are submitting page 1 via POST, you will need to access your submitted data using $_POST, not $_GET.
<input type='hidden' id='ids' name='ids' value=''<?php echo $id ?> ''>
Look at your value:
value=''<?php echo $id ?>''
It shoud be
value='<?php echo $id; ?>'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Software/Applications: Notepad++ 6.5, Google Chrome Version 26.0.1410.64 m
I copied a code online just to test on how forms work so I can map it on my real page.
But even I tried the online example code it still doesnt work in my end. Can pls someone tell me what's the reason behind this?
copypaste.php
<html><body>
<form action="DesignPageProcess.php" method="POST">
<p>Your name: <input type="text" name="name"/></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" value="submit" name="submit" /></p>
</form>
</body></html>
DesignPageProcess.php
<html><body>
<?php
if ($_POST['submit'] == "submit")
{
$name = $_POST['name'];
echo "asd".$name.;
// - - - snip - - -
}
?>
</body></html>
It returns a blank page.
Remove the extra .
<html><body>
<?php
if($_POST['submit'] == "submit")
{
$name = $_POST['name'];
echo "asd".$name; //Removed the extra . on this line
// - - - snip - - -
}
?>
</body></html>
Try:
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "asd".$name;
// - - - snip - - -
}