How to pass image from one page to other using PHP? - php

I have been trying to execute the code for long time but rest then my image all other variables are working. My images are stored in server folder called "uploaded".
I have two pages called "show.php" and "readmore.php", and I want to pass the image from show.php to readmore.php but other then image all the variables are displaying in readmore.php.
My code for show.php
<a class="btn" href="readmore.php?ad_title=<?php echo $rec['ad_title']; ?> & price= <?php echo $rec['price']; ?> & address= <?php echo $rec['address']; ?> & phone= <?php echo $rec['m_number']; ?> & description= <?php echo $rec['description']; ?> & contact_name= <?php echo $rec['contact_name'] ; ?> & photo_name= <?php echo $rec['photo_name']?>;">
My code for readmore.php (I am displaying here two of the variables along with the image)
<div class="control-group">
<label class="control-label">About the book</label>
<div class="controls">
<label class="checkbox">
<?php echo $_GET['description'];?>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">About the book</label>
<div class="controls">
<label class="checkbox">
<td id="pic" width="300px"><img src= "../uploaded/<?php echo $_GET['photo_name'];?>" style="border-radius:5px; padding:3px; "/></td>
</label>
</div>
</div>

Learn to debug:
On first lines of readmore.php dump the superglobal variable $_GET and see whether value of $_GET['photo_name'] is coming or not.
Eg.
echo "<pre>";
print_r($_GET);
echo "</pre>";
P.S. <pre> tag is just for formatting the output. print_r dumps the values of $_GET.
If you see value of 'photo_name' index in the GET array,
there should be some errors in your image path.

Related

How to insert data to database table from $_GET value on PHP

Why I can't insert into 1 field to my database table?
I loop the data of my other table to display each data and put the result to href tag so it clickable and concatenate with it's id so it will put the id result after the link like this:
<a href="scheduling.php?CID=<?php echo $rows['docID']; ?>">
Here is how I loop my data using php on page1:
<?php
$sel = "SELECT * FROM doctors ORDER BY docID";
$result = $conn->query($sel);
if($result->num_rows>0)
{
while($rows = $result->fetch_array())
{
?>
<a href="scheduling.php?CID=<?php echo $rows['docID']; ?>">
<div class="doc_item" style="width:310px; border:4px solid #009973;display:inline-block; margin-top:40px; margin-right:20px;">
<img src="images/ft-img.png" style="width: 300px;">
<div class="item-lvl" style="width: 100%; background:#009973; color:#fff; height:70px; padding-top:10px;">
<h4 style="font-size:20px; font-weight:bold;">Dr. <?php echo $rows['docFname']; ?></h4>
<span><?php echo $rows['docType']; ?></span>
</div>
<div style="width: 100%; background:#00664d;padding-top:15px; padding-bottom:20px;">
<h3 style="color:#fff;">Make a Schedule!</h3>
</div>
</div>
</a>
<?php
}
}
?>
Then I want to add the value of CID to my database table using this code on page 2:
<?php
if (isset($_POST['btn-submit'])) {
$cusID = $customerID;
$docID = $_GET['CID'];
$checkupType = $_POST['checkupType'];
$schedTime = $_POST['schedTime'];
$contact = $_POST['contact'];
$ins = "INSERT INTO schedule
(customerID, docID, checkupType, schedTime, contact)
VALUE ('$cusID','$docID','$checkupType','$schedTime','$contact')";
if($conn->query($ins)===TRUE) {
header('location:success_sched.php');
}else{
echo "SQL Query: " . $ins . "->Error: " . $conn->error;
}
}
Now, this code insert data to my database table except $docID which is the value is $_GET['CID'];
docID column is intiger.
please correct my code, this is my school project.
Form code on page 2:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<div class="sign-u">
<div class="sign-up1">
<h4>Form of Checkup* :</h4>
</div>
<div class="sign-up2">
<label>
<input type="radio" value="Virtual" name="checkupType" required>
Virtual Checkup
</label>
<label>
<input type="radio" value="Facetoface" name="checkupType" required>
Face to Face Checkup
</label>
</div>
<div class="clearfix"> </div>
</div>
<p style="color:gray;">*Take note that virtual checkup will require a you stable internet for better communication.</p>
<div class="sign-u">
<div class="sign-up1">
<h4>Date and Time* :</h4>
</div>
<div class="sign-up2">
<input type="date" name="schedTime" id="date" required>
</div>
<div class="clearfix"> </div>
</div>
<p style="color:gray;">*Please provide Skype id as a contact information if <span style="color:#ff5c33">Virtual Checkup</span> is your choice.</p>
<div class="sign-u">
<div class="sign-up1">
<h4>Contact Information :</h4>
</div>
<div class="sign-up2">
<input type="text" name="contact">
</div>
<div class="clearfix"> </div>
</div>
<div class="sub_home" style="text-align: right;">
<input style="background: #339966;" type="submit" name="btn-submit" value="Submit">
<div class="clearfix"> </div>
</div>
</form>
Please understand that when you submit a form, that is a new request to the server. It has a new URL. Your page 2 form submits to $_SERVER['PHP_SELF']; - which is the current URL but without the querystring variables. Therefore your GET parameter is not passed in the form submit. (If you use the "View Source" feature of your browser to examine the "action" attribute of the form after it's rendered, you'll see exactly what URL it makes the request to when submitting. You can also see the same thing by looking at your browser's Network tool, or your webserver's access logs.)
There are a couple of ways around that, but I'd suggest adding the value as a hidden field in the form, and populating it with the value of the GET parameter during the previous request.
e.g.
<input type="hidden" value="<?php echo $_GET["CID]; ?>" name="CID">
and then in the PHP, retrieve it via $_POST like all the other variables:
$docID = $_POST['CID'];
Finally, please ensure you update your code to use prepared statements and parameters, as recommended in the comments, so that you are protected against both SQL injection attacks and unexpected syntax errors. You can get more info and examples here

Read MySQL data into Bootstrap 4 columns

Welcome Forum residents,
My goal is to display MySQL data in input cards and the cards aligned side by side in bootstrap 4 rows.
Reading MySQL data works fine, but the input cards are not juxtaposed by the Bootstrap 4 grid system. (If I do not read data from MySQL, I only use plain HTML, the Grid system works.)
The code:
...
<?php include_once('includes/head.tpl'); ?>
</head>
<body>
<?php include_once('includes/php/navbar.php'); ?>
<form method="GET" action="action2.php">
<?php
$result = mysqli_query($conn, "SELECT * FROM plans");
while($row = mysqli_fetch_array($result)) {
?>
<div class="container">
<div class="row">
<div class="col-sm-4">
<label>
<input type="radio" name="plan_id" id="plan_id" value="<?php echo $row['id']; ?>" class="card-input-element" />
<div class="card-input">
<?php echo $row['plan_name']; ?><br>
<?php echo $row['plan_cpu']; ?><br>
<?php echo $row['plan_memory']; ?><br>
<?php echo $row['plan_disk']; ?><br>
</div>
</label>
</div>
</div>
<?php
}
?>
<input type="submit" name="btn-submit">
</form>
</div>
...
The end result:
What could be the problem?
Why is Grid system not working when reading MySQL?
Thanks in advance for the answers!
The problem looks like you create the bootstrap container div and row element for each row of the data, this should be outside of the loop where you retrieve the rows...
<div class="container">
<div class="row">
<?php
$result = mysqli_query($conn, "SELECT * FROM plans");
while($row = mysqli_fetch_array($result)) {
?>
<div class="col-sm-4">
<label>
<input type="radio" name="plan_id" id="plan_id" value="<?php echo $row['id']; ?>" class="card-input-element" />
<div class="card-input">
<?php echo $row['plan_name']; ?><br>
<?php echo $row['plan_cpu']; ?><br>
<?php echo $row['plan_memory']; ?><br>
<?php echo $row['plan_disk']; ?><br>
</div>
</label>
</div>
<?php
}
?>
</div>
</div>
If you have more plans that fit on a row, you would need to create the div's for the row each time you get to the split point.

How can I upload information from a php form on a different site?

I'm creating a form that needs to upload the information retrieved to an entirely separate site.
My form's "action" is to send the information to itself in order to validate information as well as see, if the required fields are input. If no errors are found, an email is sent with a message that includes the information from the form.
My code for the index page generally looks like this:
<?php include('action_page.php'); include('config.php')?>
<form method="POST" name="email_form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="row">
<div class="col-25">
<label for="subject"><span class="error">* <?php echo $titleErr;?></span> Subject <i class="glyphicon glyphicon-pencil"></i></label>
</div>
<div class="col-75">
<textarea id="subject" name="subject" placeholder="Please input a subject for the email" style="height:46px"><?php echo $title;?></textarea>
</div>
</div>
<hr>
<div class="row">
<div class="col-25">
<label for="emails"><span class="error">* <?php echo $emailErr;?>
</span> Email <i class="glyphicon glyphicon-envelope"></i></label>
</div>
<div class="col-75">
<p style="color:#0071c5">Please choose which group(s) to send this to:
</p>
<?php foreach($emails as $value): ?>
<input type="checkbox" name="email[]" value='<?php echo $value ?>'<?php if (isset($_POST['email']) && in_array($value, $_POST['email'])) echo 'checked="checked"';?> ><?php echo $value ?>&nbsp &nbsp &nbsp
<?php endforeach; ?>
</div>
</div>
My action page then sends an email using the php mail() function.
What I want to do is upload the body of the email on a separate website, which runs similarly to how Wikipedia is run - anyone can edit a page even if you're not the owner of the page.
To be honest, I'm not entirely sure how to even start. I'm able to use a header on my action page that can link my form to a different page, but this doesn't autofill like I want it to.
For example:
if(mail($mail_to, $title, $msg, implode("\r\n", $headers))){
header('Location: https://en.wikipedia.org/w/index.php?title=Japanese_aircraft_carrier_Ry%C5%ABj%C5%8D&action=edit');
}
sends the user to the appropriate Wikipedia page, but I'm not able to see any of my variables, that my form stored.
How do I solve the problem?
It's hard to say without seeing more of your code, but you will likely need API access to perform a POST request. Here is documentation from Wikipedia about working with their API in PHP.

Hide label class in div

For 2 days I didn't understand why my pictures aren't uploaded onto my server correctly.
I am using osclass and in my theme I have this :
<?php if( osc_price_enabled_at_items() ) { ?>
<div class="control-group">
<label class="control-label" for="price"><?php _e('Recompensa', 'infinity'); ?></label>
<div class="controls">
<?php ItemForm::price_input_text(); ?>
<?php ItemForm::currency_select(); ?> ( optional )
</div>
</div>
<?php } ?>
I was partially able to achieve what I wanted: when someone chooses a category where the price is off, the label with text price disappears, but I still have the problem that my pictures don't upload.
This was my code, but with this the text PRICE is not disappearing, only the text area is:
<?php if( osc_price_enabled_at_items() ) { ?>
<div class="control-group">
<label class="control-label" for="price"><?php _e('Price', 'bender'); ?></label>
<p class="controls">
<?php ItemForm::price_input_text(); ?>
<?php ItemForm::currency_select(); ?> ( optional )
</div></p>
</div>
<?php } ?>
This is the problem
<p class="controls">
should be
<div class="controls">
Unless there is something I'm missing.
i was able to adjust this , was my mistake , the last from my code was in addition i deleted and now is ok , my server uploads pictures with no problem , thank you all

Form submitting in php

--EDIT---
i have created a text box area where users can input some data,
Basically when i press the submit button, it should save the inputted data. here is the full code, i can't fix it. :/
The user entry does not get updated.
<?php
if ( $act == "htmlprofile" ) {
?>
<div class="contentcontainer">
<div class="contentmboardheaderarea"><img src="images/header.png" />
<div style=”word-wrap: break-word”><div class="contentheadertext"><?php echo "$hlang2"; ?></div></div></div>
<div class="contentheading">
<form id="htmlform" name="htmlform" method="post" action="options.php?act=htmlsubmit">
<div class="contentheading4">
<?php echo "$olang15"; ?></div>
</div>
<div class="contentmboardlistarea2"><textarea id="htmlprofile" name="htmlprofile" cols="33" rows="10"><?php echo $qry2[htmlprofile];?>
</textarea></div></form>
<div class="contentbuttonarea">
<div class="contentbutton1" onClick="document.location.href = 'profile.php?act=index'";><?php echo "$glang3"; ?></div>
<div class="contentbutton2" onClick="document.forms['htmlform'].submit();"><?php echo "$glang21"; ?></div>
<div class="contentbutton3"></div>
<div class="contentbutton4"></div>
<div class="contentbutton5" onClick="document.location.href = 'help.php#htmlprofile'";><?php echo "$glang5"; ?></div>
</div>
</div>
<?php
}
?>
<?php
if ( $act == "htmlsubmit" ) {
$save ='Profile updated successfully';
$query4 = "UPDATE members SET htmlprofile = '$htmlprofile' WHERE username = '$myuser'";
mysql_query($query4);
?>
There is no value attribute in textarea you have to enter the content between the <textarea>text</textarea>
See for reference tag_textarea
It should be like this
<textarea id="htmlprofile" name="htmlprofile" cols="33" rows="16" >
<?php echo $qry2[htmlprofile]; ?>
</textarea>
Refer to this answer also which-value-will-be-sent-by-textarea-and-why
Your div contentheadertext is not contained within the <form></form> so if you have inputs there, they won't be included in the form submission.
To resolve, move the opening <form> tag higher, so that it encloses all inputs.
the submit works fine. But you have no variables with the post data definied. And textareas haven't "value". And when you don't need fixed strings in your echo, don't use the "
try the following:
<textarea id="htmlprofile" name="htmlprofile" cols="33" rows="16"><?php echo htmlspecialchars($_POST['htmlprofile']); ?></textarea>
if you are trying to use a php variable inside HTML do that simply by echo $myvariable ; Quotes not required there. But if u are trying to echo a string use quotes just like echo 'mystring' .
Moreover when you are trying to pass some values as part of form submission, the required values should be between the tags
if you want to show any value inside text area, remember it doesn't have a 'value' attribute. So write the code like this: value to be displayed

Categories