473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP Insert adding wrong values

97 New Member
I have a form like this:

Expand|Select|Wrap|Line Numbers
  1. <form action="CreateNewNews.php" method="post" class="newNews">
  2. //rest of the form
  3. </form>
  4.  
And the php file that is actioned is this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. include ('includes/DbCon.php');
  4.  
  5. $headline = isset($_POST['headline']);
  6. $body = isset($_POST['body']);
  7. $image = isset($_POST['image']);
  8. $current_date = date("j/M/y");
  9.  
  10. if(isset($_POST['submit'])){
  11. $query = $mysqli->prepare("INSERT INTO news (`headline`, `body`, `image`, `date`) VALUES ('$headline', '$body', '$image', '$current_date');");
  12. $sql->execute(array(":headline" => headline, ":body" => body, ":image" => image, ":date" => $current_date));
  13.  
  14. echo '<script type="text/javascript">';
  15. echo 'alert("News Items Saved")';
  16. echo 'document.location.href = "/pc.v.2/admin-news.php";';
  17. echo '</script>';
  18. }
  19.  
  20. else
  21. {
  22. echo '<script type="text/javascript">';
  23. echo 'alert("The news item was not able to be created. Please try again."). mysql_error()';
  24. echo '</script>';
  25. }
  26.  
  27. $mysqli->close();    
  28. ?>
  29.  
  30.  
But all it adds to the DB is a '1' for the headline and the same for the body, the image isn't working, neither is the date. Where have I gone wrong?
Jun 10 '15 #1
2 1255
RonB
589 Recognized Expert Moderator Contributor
You're assigning those vars the return value of a boolean test, not the values of the form submission.
Jun 10 '15 #2
tdrsam
97 New Member
Ok. So I changed them to this:

Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['headline']))$headline = $_POST['headline'];
  2.  
Jun 11 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
23061
by: schumacker | last post by:
Hi everyone! I am working with Delphi v7 and MS SQLServer. I am trying to insert data in a table with a SQL sentence. Some of the fields of my table are type char or varchar, and they can have null values. ¿What do i have to write in the SQL sentence to insert a null value in those fields? I tried with '', an empty String, but it doesnt...
6
1932
by: Rich | last post by:
Hello, I have to create a table in an Access mdb (remotely) on the fly. Create Table tbl1(fld1 Integer, fld2 varchar(10), fld3...) Then I have to insert data: Insert Into tbl1 Values(" & val1 & ", '" & val2 & "',...")"
0
1340
by: Jeff Boes | last post by:
I have a rule defined on a table, to log rows from that table (which tend to get read elsewhere and quickly deleted) into another table for audit. It looks like this: rul_job_queue_trace_log AS ON INSERT TO job_queue DO INSERT INTO job_queue_trace (job_id, ...) VALUES (new.job_id, ...) The table on which the rule is defined looks...
1
4491
by: mosquito.dotnet | last post by:
I am getting clearly wrong values from TextBox.SelectionStart property in C# code. For example, if I move caret one character to right by pressing Keys.Right, sometimes declared SelectionStart property actually decreases, sometimes it does not change. Difference seems always at most off by 1 but it is very irritiating. My setup is as...
4
2911
by: Phille | last post by:
Hi I have a form with a few textboxes and some listboxes with multiple values allowed. I would like to use an append query to insert everything into a table but for some reason it just gives me no values at all for the listboxes (the textboxes are ok). Is there something that could be done. Thanks in advance
3
2327
by: shk253 | last post by:
Hi - This program converts temperature from C to F and F to C and averages the Celsius outputs in one variable and Fahrenheit outputs in another. My professor asked us to modify this program to use functions. After I created functions and got it running, the csum and fsum variables seem to get the wrong values. It would be great if somebody could...
7
2496
by: dongletran06 | last post by:
Hi, Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input text" are successfully adding data to mysql. I just try first using the month as drop down. The month data type I used in mysql database is varchar....
0
1649
by: Dmitriy Son | last post by:
Hi! How to insert dynamically added values of the select list into mysql table? $10 any working solution pls. function SaveNewCampaign() { global $wpdb; $table_name= $wpdb->prefix.'campaigns'; $data = array(); $data=$wpdb->escape($_POST); $data=$wpdb->escape($_POST); $data=$wpdb->escape($_POST);
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7444
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.