Hi guys i am doing a personal project which i want to use on my small business, i am not that rich thats why i cant afford to hire a developer to do it for me :( my problem is that variable seems not to work if its called on an iframe, ok just like i said im not a pro developer so even on terms im not sure what to use so i will just explain on whatever i can and i hope some one can catch up with me.
an iframe is called on uikit modal, url on iframe have parameters
file is called firstreminder.php and this is the code
<?php
require_once 'layout/header.php';
if(!empty($_GET['message'])){
$sms_msg = 'https://www.experttexting.com/ExptRestApi/sms/json/Message/Send?username=xpertdotmedia&password=c61iQO1E&api_key=4aw0l0noipli133&from=LocalVerify&to=63'.urlencode($_GET['mobile']).'&text=' . urlencode($_GET['message']) . '&type=text';
$msg_json = file_get_contents($sms_msg);
$msg_array = json_decode($msg_json, true);
}
$url = $_SERVER['REQUEST_URI'];
$parts = parse_url($url);
parse_str($parts['query'], $query);
$clientid = $query['userid'];
$getinvid = $query['invid'];
?>
<form action="">
<div class="uk-margin">
<textarea rows="6" cols="50" name="message" class="uk-textarea"/><?php
echo 'Greetings,
Just a friendly reminder for your upcoming due on '.$query['date'].'
Thank you
*auto msg do not reply';
?></textarea>
</div>
<div class="uk-margin">
<?php echo '<input type="text" name="mobile" class="uk-input" value="'.$query['userphone'].'" />';?>
</div>
<div class="uk-margin">
<button class="uk-button uk-button-primary" type="submit">Send</button>
</div>
<?php
if(!empty($msg_array)){
$status = $msg_array['Status'];
if($status!="1"){
header('Location: sent.php?id='.$getinvid);
}
}
?>
</form>
<?php
require_once 'layout/footer.php';
?>
so far its working good as i can fetch value of each parameters, example i can call $query['date']whenever i want and its actually working but problem lies on header location as it doesnt seem to fetch the value of the variable, header location is called whenever the script successfully sent the sms message and then it redirect to sent.php as i want to remind the user that sms was successfully sent and also update the database and this is the code of the sent.php file
<?php
require_once 'layout/header.php';
$senturl = $_SERVER['REQUEST_URI'];
$invURL = parse_url($senturl);
parse_str($invURL['query'], $smsquery);
$invoID = $smsquery['id'];
$updateSentTo = "UPDATE ffcko_invoices_invoices SET last_sent=NOW() WHERE ffcko_invoices_invoices.id=$invoID;";
if (mysqli_query($DBcon, $updateSentTo)) {
echo '<h1 class="uk-h3 uk-text-success">Message Sent <span uk-icon="icon: check; ratio: 1.5"></span></h1>';
echo '<script>window.top.location.reload();</script>';
} else {
echo "Error: " . $updateSentTo . "<br>" . mysqli_error($DBcon);
}
mysqli_close($DBcon);
require_once 'layout/footer.php';
?>
it should go to sent.php?id=(id) so that i can successfully update the database but i always end up with this error
i tried all the combinations i can, i even transfered the code from sent.php to firstreminder.php inorder for it to have a direct control of the variable but still problem occurs as if the $getinvid is being ignored
i think it has something to do with the iframe? you think so? cause if I enter the url directly to my browser
http://localhost/sms/sent.php?id=3
adding the id manually it works as it should and it updates the database so i wonder what im doing wrong?
hope you guys can help me, thank you so much and i hope i have explained it well as english is not my native language so i really really apologize.
Related
I am trying to create a simple "notepad" form. I have a pop-up button that when pressed will open a text file (or create one when saved if none exists). The pop up opens, the file gets created/written to. But I can't seem to pull the complete text file back up.
It all works fine until the visitor leaves the page. Meaning they can be on the page, open the file, write to it, save and close. Then, reopen it and all information is there. Add to it if they so choose, and save again. However, When they come back, everything works, except previously saved text doesn't display. It is still in the file, (verified through visual inspection through FTP) but doesn't populate the pop-up.
Still new to learning PHP and am trying to figure it out, but I am quite stuck here.
I haven't tried anything other than making sure POST is done correctly and trying to find similar problems online, but can't locate any.
<div id="myNote" class="note">
<div class="note-content">
<div class="note-header">
<span class="close">×</span>
<h2>Notepad</h2>
</div>
<div class="note-body">
<p><?php
if(isset($_POST['submit']))
{
$comment = $_POST['note'] . "\r\n";
$file = fopen($context['user']['name'] . '.php',"a+");
fwrite($file,$comment);
fclose($file);
print_r(error_get_last());
}
echo '<form action="" method="POST" name="note">
<textarea name="note" rows="20" cols="40">', $comment, '</textarea>
<input type="submit" name="submit" value="Save Note"></form>';
?></p>
</div>
<div class="note-footer">
<h3>If you close the window without saving, your notes will not be saved.</h3>
</div>
The
$comment = $_POST['note'];
Populates the textbox
What you want to add is
else {
$comment = fread($context['user']['name'] . '.php', filesize($context['user']['name'] . '.php'));
}
below your if.
should I think do the trick.
I have a form that submits fields to a database using mysqli that was working perfectly; however, I pulled up the form page in Chrome and tried to submit a new row to the db, only for the page to go back to the previous page when I tried to click on the form's text-areas. I tried clearing all of my browser history (cache, cookies, etc.) and asked a friend to try it on their Chrome browser, with the same result.
The kicker? It works in Edge. Makes no sense.
I've gone through the code and can't find any missing <'s or quotes, etc. Everything was working fine and I can't imagine why it would suddenly start doing this in Chrome.
(Note: I know this code is clunky and vulnerable to SQL injection, but I don't have any users/sensitive data to protect, for the moment. Also, I made no changes to head.php or any code (that I can recall), just confused as to why it would suddenly start redirecting me back to notebook.php as soon as I click on a text area in Chrome but not in Edge.)
Notebook_add.php
$con = #mysqli_connect('localhost', 'root', 'pass', 'db');
if (!$con) {
echo "Error: " . mysqli_connect_error();
exit();
}
?>
<body>
<div class="wrapper">
<h1>Post Comments</h1>
<?php
include ('navbar.php');
?>
<br>
<form name="noteworthy" METHOD=POST action=<?php echo $_SERVER['PHP_SELF']; ?>>
<br>
Title: <input type="text" name="title" id="$title" size="50"> <br>
Link: <input type="text" name="link" id="$link" size="50"><br>
Description: <TEXTAREA NAME="description" id="$description" ROWS="5" COLS="30"></TEXTAREA><br>
<Input type="submit" name="enter" id="$enter" value="enter">
</form>
<?
echo $submitted = date("Y-m-d");
?>
<?
$title = $_REQUEST['title'];
$link = $_REQUEST['link'];
$description = $_REQUEST['description'];
$enter = $_REQUEST['enter'];
if(isset($_REQUEST['enter'])){
$submitted = date("Y-m-d");
$sql = "INSERT INTO notes (title, link, description, submitted) VALUES ('$title','$link','$description','$submitted')";
}
if(mysqli_query($con, $sql)){
echo "Records inserted successfully.";
print "<meta http-equiv='refresh' content='0; url=http:notebook.php' />";
}
// Close connection
mysqli_close($con);
?>
<div class="push"> </div>
</div>
<?php
include 'footer.php';
?>
</body>
So what happened was that I had added a new menu item in my navbar.php and forgot to close the link tag (e.g., " New menu item "). This made the entire php form into a link, so whenever I anywhere on it under my navbar I was returned to the previous page.
It is interesting that this didn't happen in Edge; perhaps there is some feature in Edge that automatically closes rogue tags.
Anyway, thanks for responding. #Smith, thanks for the tip, I'm using the php head featured/location function instead of meta-refresh now.
I am using codeigniter and the tutorial from here. I have made a basic blog tool which works fine. However as it stands to add a new post you have to go to a separate page 'create.php' to get to the form. I would like to try and put the form on the same page as the page that will be updated i.e. 'index.php'. If I try to do this at the moment the form simply refreshes and does submit the data.
model
function insert_post($data){
$this->db->insert('posts', $data);
return;
}
Current View (admin/create.php)
<?php echo validation_errors(); ?>
<h4>Create A New Post Below</h4>
<form action="" method="post" >
<p>Title:</p>
<input type="text" name="title" size="50"/><br/>
<p>Summary:</p>
<textarea name="summary" rows="2" cols="50"></textarea><br/>
<p>Post Content:</p>
<textarea name="content" rows="6" cols="50"></textarea><br/>
<input type="submit" value="Save" />
<?php echo anchor('admin','Cancel'); ?>
</form>
View I would like the form to be on (index.php)
<?php
echo '<p>Welcome '.$username.'! All posts available for edit or deletion is listed below.</p><br/>';
echo anchor('admin/create','Create New Post');
$count = count($post['id']);
for ($i=0;$i<$count;$i++)
{
echo '<div class="postDiv">';
echo '<h4>'.$post['title'][$i];
echo '<p>'.$post['summary'][$i].'</p>';
echo '<p>'.$post['content'][$i].'</p>';
//echo anchor('blog/view/'.$post['id'][$i],' [view]');
echo anchor('admin/edit/'.$post['id'][$i],' [edit]');
echo anchor('admin/delete/'.$post['id'][$i],' [delete]</h4>');
echo '</div>';
}
?>
Controller
function create(){
$data['userId'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$this->form_validation->set_rules('title','title','required');
$this->form_validation->set_rules('summary','summary','required');
$this->form_validation->set_rules('content','content','required');
if($this->form_validation->run()==FALSE)
{
$this->load->view('template/admin_html_head',$data);
$this->load->view('admin/create',$data);
$this->load->view('template/html_tail',$data);
} else {
$data = $_POST;
$this->posts->insert_post($data);
redirect('admin');
}
}
This was straight forward when I used normal php but with codeigniter I am getting lost with the MVC stuff. I know this is probably a fairly basic question so please either explain your answer or give me a link to something which will explain what I need to do as I want to learn from this. I have read the codeigniter docs on validation but I dont think thats my problem?
What you are trying to do is called embedding a view. I will try to explain how but you should also check some links which might prove to be more in depth:
http://net.tutsplus.com/tutorials/php/an-introduction-to-views-templating-in-codeigniter/
Codeigniter: Best way to structure partial views
The crux of what you need to do is change the link on index.php from:
echo anchor('admin/create','Create New Post');
to
$this->load->view('admin/create');
Now this should work, but to help you on the MVC front, it helps to explain why doing it this way is wrong. The idea of MVC is to seperate the functions in your application into their distinct roles. Most people will frown at putting business logic into views unless it is very minimal. The way that we could improve upon your code is to load the view in the controller, and set it to variable.
At the bottom of the codeigniter docs for views it shows how to load into a variable:
http://ellislab.com/codeigniter/user-guide/general/views.html
if the third parameter of load->view is set to true then the function will return your view as a string instead of outputting it to the browser
$data['input_form'] = $this->load->view('admin/create', $data, true);
then in the view that you want to load that form all you need to do is echo input_form
<?php echo $input_form;?>
So that should solve your problem but there are also a few more things you can do in your view file that will improve the readability of your code.
Instead of using a count() and for loop you can use foreach which makes everything much easier
<?php foreach ($post as $post_item):?>
<div>
<h4><?php echo $post_item['title'];?></h4>
</div>
<?php endforeach;?>
It also helps to break your view files up and have more tags. It might seems like it is extra bloat, but when you have larger view files it will be very cumbersome to continue using as many echo's as you have
just add one method uri_string() in your form action, uri_string will take same url of page put in action you can submit form to same page
<?php echo validation_errors(); ?>
<h4>Create A New Post Below</h4>
<form action="<?=uri_string()?>" method="post" >
<p>Title:</p>
<input type="text" name="title" size="50"/><br/>
<p>Summary:</p>
<textarea name="summary" rows="2" cols="50"></textarea><br/>
<p>Post Content:</p>
<textarea name="content" rows="6" cols="50"></textarea><br/>
<input type="submit" value="Save" />
<?php echo anchor('admin','Cancel'); ?>
</form>
in controller little chagnes
function create(){
$data['userId'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$this->form_validation->set_rules('title','title','required');
$this->form_validation->set_rules('summary','summary','required');
$this->form_validation->set_rules('content','content','required');
if($this->form_validation->run()==FALSE)
{
$this->load->view('template/admin_html_head',$data);
$this->load->view('admin/create',$data);
$this->load->view('template/html_tail',$data);
} else {
$data = $this->input->post();
$this->posts->insert_post($data);
redirect('admin');
}
}
Use session library
check this another stackoverflow thread to know how to use session
In order to use session library, u need to configure encryption_key in config.php
To do that, check this out
I'm having some weird issues with this code block, it's a little school project, going well so far but the form at the bottom is not returning any post data. the var_dump($_POST); never shows any post data being submitted from this particular form.
I just cannot understand why, been struggling with it for so long.
Here's the code, i couldn't understand to format it on this page, adding 4 indents for every line seemed a bit tedious.
<?php session_start();
require_once'user.class.php';
require_once 'posts.class.php';
require_once'comments.class.php';
$posts = new Posts($user->getID(), $db);
$comment = new Comments($user->getID(), $db);
include_once'includes/header.php';
include_once'includes/nav.php';
?>
<h2><br></h2>
<?php
include_once'includes/intro.php';
// CONTENT
$post = $posts->showPost($_GET['id']);
$title = $post['title'];
$content = $post['content'];
$created = $post['timestamp'];
echo "<section> <article class='blogPost'> <header> " . " <h2>$title</h2> " . "<p> Posted on $created <a href ='#comments'> X comments</a></p></header>" . "<p>$content</p>" . "</article> </section>";
var_dump($_POST);
if (isset($_POST['submit_comment']) && isset($_POST['id_comment'])) {
echo "Kom seg inn i ifen";
$pid = $_GET['id'];
$comment->newComment ($db, $user->getID(), $pid, $_POST['id_comment']);
header ("location: showPost.php?id=$pid");
exit ();
}
?>
<form name='commentform' action='showPost.php?id=<?php echo $_GET['id'];?>' method='POST'>
<h3>Post a comment</h3>
<p>
<label for='id_comment'>Comment</label>
<textarea name='id_comment' id='id_comment' required></textarea>
</p>
<p><input style='width: 100%;' type='submit' name='submit_comment' value='Legg til kommentar' /></p>
</form>
<?php
include_once'includes/asidefooter.php';
?>
Thanks for all help!
It looks like if post is data present, the user is redirected. You will only see the post data at the time the form is submitted, and the redirect will cause another page load and the data won't be present anymore.
Can you see the post data if you comment out the redirect, with:
//header ("location: showPost.php?id=$pid");
//exit ();
Something is causing a redirect, which is turning the request into a GET. If you're trying to submit to a index.php then don't forget the ending slash.
I have a page where I am using a PHP while loop to echo the names and addresses of our dealers. For the email link, I want the user to be able to click the link, which would then take him to a form that emails that person.
I know that you can't mix Javascript and PHP, so how do I tell which link the user has clicked on so that I can pass that variable to the form on the next page? Here is my code:
<?php while($row = mysql_fetch_array($result)) {
if ($row['active'] == 1) {
?>
<div id="dealer">
<div id="dealername">
<h3 style="float:left;"><?php echo $row['company']; ?></h3><br/>
<p><?php echo $row['address1']; ?><br/>
<?php if($row['address2'] || $row['address3']) {
echo $row['address2'] . ' ' . $row['address3'] . '<br/>'; } ?>
<?php echo $row['city'];
if ($row['state']) {
echo ', ' . $row['state'];
}
echo ' ' . $row['zip']; ?>
<br />
<?php echo $row['country']; ?>
<br />
<br />
Phone: <strong><?php echo $row['phone1']; ?></strong><?php if ($row['phone2']) {
echo ' or ' . $row['phone2']; } ?><br/>
<?php if($row['fax']) { echo 'Fax: ' . $row['fax']; } ?><br />
</p>
</div>
<?php if ($row['email']) {
echo '<div class="dealerEmail">'. // need help here . '</div>';
} ?>
<br class="clearall" />
</div>
<?php }} ?>
The page that this code appears on is pulling data from a database using a GET statement based on a URL similar to "index.php?state=az".
I've tried making the email link use a "?email=..." format but when I go to the dealer-email.php page there are no parameters in the URL, which I don't get. That's why I'm trying to find some other way to pass some kind of variable to the next page, based on which link the user clicks on.
Hope this is clear. Thanks in advance for your help.
this should work fine:
contact dealer
and then you retrieve the data in the somepage.php page:
if(isset($_GET['email']))
$email = $_GET['email'];
else
//redirect somewherelse
I know that you can't mix Javascript
and PHP
This is not true. Javascript is a Client-Side Scripting language, and PHP is Server-Side scripting. They run at different times, on different machines, and will run just fine.
Mixing Javascript and PHP might be a mental challenge and subject to pitfalls, but it definitely can be done, and often is done.
You might skip the email form altogether and include a mailto attribute in your link.
contact dealer
This will open the user's default email client new message window with the address filled in. I understand you may want to use a custom form to prevent someone from spamming all your contacts, but if this is a restricted area for logged in users, or an intranet site, this might work.