PHP - Posting (null) Into A Field From A Form...
I have one field which is set up as a Text field in my database. What I'm wanting is if the field is blank in the form to just leave the field alone in the database. I need it to be NULL.
OR...is there a way to query a database to recognize a field is blank? Similar TutorialsHow can I change Yes to No for the NULL field in the mysql db structure. E.g. (Table name: address and Column name : state) <?php $link = mysql_connect("localhost","db","pw"); mysql_select_db("db"); mysql_query("alter table address modify state null NO); $result = mysql_query($query); $sent = "Edit Successful."; echo ($sent); ?> I am having trouble sending information that was entered into a form, on the same page to the next page. I am sure i have done this a few years ago but cant find the code and cant find the answer online, hope someone can help me. My code is as follows: <form method="POST" action="https://.............. .asp "> <table> <tr> <td>Name: </td> <td><input type="text" name="clientname" /></td> </tr> <tr> <td>E-mail:</td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Contact No:</td> <td><input type="text" name="telno" /></td> </tr> </table> <?php $udate = date("y-m-d H:i:s", strtotime ("+2 hour")); $uniquevalue = "$udate" . " " . "Simpay Pro"; echo $uniquevalue; ?> <br /> <input type="hidden" name="info1" value="<?php print $uniquevalue?>"> <input type="hidden" name="info2" value=$clientname> <input type="submit" value="Submit"> </form> So basically info1 is working i can see the value on the next page after its submitted, but info2 is the value of the input field. Is this possible to do it like this, or do i have to send it to another page and then to my last page that displays the values? Hi
I would really appreciate some help.
I am trying to structure some php to detect if a value is null, if it is not null i want it to print the value if null print nothing.
so far all i have it doing is detecting whether it is null or not. but it is printing part of my code instead of the fields value.
here is the code I have
this is for a word press theme that I am modifying for my purpose. I see some of the fields in mysql show NULL and some are just empty, wonder what is the difference, is empty field still NULL? Hi, i have written a form that uses 3 dropdown boxes, one of them being populated from a database. The form code is as follows; Code: [Select] <form id="pointsForm" name="pointsForm" method="post" action="points-engine.php"> <select name="car" id="car"> <?php // result of car name collection $result = mysql_query ($query); //Array stored in $cars while($cars=mysql_fetch_array($result)){ //option values added by looping through array echo "<option value=$cars[id]>$cars[carName]</option>"; } ?> </select> <select name="season" id="season"> <option value="low">Low season</option> <option value="mid">Mid season</option> <option value="high">High season</option> <option value="peak">Peak season</option> </select> <select name="period" id="period"> <option value="day">One day</option> <option value="weekend">Weekend</option> <option value="week">One week</option> </select> <input type="submit" name="Submit" value="Submit" /> </form> which posts to; Code: [Select] <?php $car=$_POST['car']; echo $car; $season=$_POST['season']; echo $season; $period=$_POST['period']; echo $period; ?> The initial form code is working fine, the car field is being populated from the database. My problem is the post value for car isn't working... points-engine.php is echoing $season & $period fine but not $car can anyone tell me why? many thanks Richard I am working on a PHP/MySQL authorization script. The script seems to work initially, but when I try to Login and post the Form ( echo '<form method="post" action=authorize_1.php">'; echo '<table>'; echo '<tr><td>Userid:</td>'; echo '<td><input type="text" name="userid"></td></tr>'; echo '<tr><td>Password:</td>'; echo '<td><input type="password" name="password"></td></tr>'; echo '<tr><td colspan="2" align="center">'; echo '<input type="submit" value="Log in"></td></tr>'; echo '</table></form>'; ) Internet Explorer returns the error that the page is not found.... but I am using one .php file for the authorization so I am sure the page is found because i can see the Login portion. Any ideas as to what is going wrong? I have this code with clears the input box onclick... Code: [Select] <input type="text" name="username" value="Username" onclick="value=''"/> however is there any way to use php to get the value of username, before its posted? that way i can make it so it only clears if the value of username is "username" Hi Guys, I need a bit of help. I need to post a value to a second page, but I want the button to have the same name. The page is to show registered users and then allows a user to send a friend request 'to put it in simple terms'. Username submitbutton username submitbutton And then i do the following <?php foreach ($_POST['username') as $user { echo $user; } ?> How could i go about doing this or would I have to use a 'Hidden' Field. Hi everyone! So, I have recently become interested in the world of webpage design and HTML coding. Thus far, I have created a few simple HTML webpages, the first of which includes some basic facts and information on the state of NC. Everything has gone rather smoothly for me until this point, but I would now like to incorporate a bit of PHP into my knowledge of web development. First, I would like to include a form on my NC page that once submitted, goes to a new PHP page displaying the inputted data to the screen. On the new page, I am attempting to include files: a header and footer. On my other couple of pages for which I would like to add server side includes. And lastly, if possible, it would be great if I could learn how to add some additional features like sending e-mails or displaying the date. Any advice or tips on how to go about this would be greatly appreciated! This topic has been moved to Other Programming Languages. http://www.phpfreaks.com/forums/index.php?topic=322013.0 Hi There, I have a series of submit buttons that I would like to update records in a table when they are pressed. For example, when clicked, I would like them to run the following statement: update mytable set completed = 1 where colname = $variable I would then like it to refresh the page. Is there a way of doing this? Thanks Matt I have got another of those problems that should be easy to solve but I cannot get my head round it! I have a form to enter data into a table and one of the fields can be left blank. However, I'd data is entered in the field it can be a Zero. This is leaving me a problem as I cannot find a way to get the script to insert NULL if the field is blank but actually put the Zero in if that is what is entered. I have tried several permutations of nested if's using empty or isset, but whatever I try, the same result is inserted in both scenarios. The arguments I need to pass are...... If field is empty INSERT null If field is 0 INSERT 0 If field is not empty and not 0 INSERT field Thanks in advance for any suggestions. Steve Hello again. I need help for a PHP project I'm working on for school. I need it to do the following: 1) When nothing is entered, it will echo "Please enter a number." 2) When "0" is entered, it will echo "Please enter a number that is not zero." My code is as follows... <form action="hwpositive.php" method="post"> Enter number <input type="text" name="number"/><br /> </form> <?php $input = $_POST['number']; // if number entered is less than 0 if ($input<0) { echo "Enter a positive number."; } // if number entered is greated than 1000 elseif ($input>1000) { echo "Enter a number less than 1000."; } // if number entered is not a number (ie, a letter, a character) elseif (!is_numeric($input)) { echo "<br><img src=\"squidward.jpg\"><br><br>Enter a valid number. "; } // if number entered is between 1-999 elseif (($input>0) && ($input<1000)) { echo "hello world " . $i . "<br />"; } // if number entered is zero elseif ($input===0) { echo "Please enter a number that is not zero."; } // if no number is entered elseif ($input=null) { echo "Please enter a number."; } else { echo "Please enter a number."; } ?> However, it's not working. What am I doing wrong? Everytime I enter this page, it should show me "Please enter a number" because I haven't entered anything yet, but it doesn't. It's showing me the image right away. I don't understand... Help me, please! Thank you so much in advance. I appreciate the help. Hello, When a user clicks a Submit button on my page, I'm using an onClick event to essentially just disable the button and change the message to 'Saving'. However, when I add the onClick code, the form no longer posts using PHP. The button does indeed change but the postback never occurs. Is there something extra I need to add or do? Thank you!! This is my submit button: Code: [Select] <input type="submit" id="submit" value="Save Changes" onclick="this.disabled=true; this.value='Saving'">|<a href="/">Cancel</a> Then I have the normal PHP stuff for postback which isn't firing.... Code: [Select] //IF POSTBACK if ($_SERVER['REQUEST_METHOD'] == 'POST') { //DO STUFF HERE } This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=346552.0 Hi, I got this form which passes hidden values as well as a select menu. The only thing is, it doesnt seem to post the form data to the script.
Here is the form
echo '<form action="regsale.php" method="POST">'; echo '<input type="hidden" name="username" value="<?php echo $username ?>"'; echo '<input type="hidden" name="listing_title" value="<?php echo $listing_title ?>"'; echo '<input type="hidden" name="speciesCommon" value="<?php echo $speciesCommon ?>"'; echo '<input type="hidden" name="cost" value="<?php echo $cost ?>"'; echo '<input type="hidden" name="business" value="<?php echo $business ?>"'; echo '<input type="hidden" name="postage_cost" value="<?php echo $postage_cost ?>"'; echo '<input type="hidden" name="multipostage" value="<?php echo $multipostage ?>"'; echo "<ul class='results'>"; echo '<li>Quantity:</li>'; echo '<select name="quantity">'; echo "<option value='$quantity'>Maximum of $quantity available</option>"; for ($q=1; $q<=$quantity; $q++) { echo "<option value='$q'>$q</option>"; } echo '</select>'; echo' </ul><br>'; echo '<div align="center">'; echo '<br>'; echo '<input type="submit" value="Confirm Purchase"><br>'; echo '</form><br>';And here is the script that the form is posted to <?php include 'init.php'; include 'includes/overall/header.php'; include 'includes/logo.php'; if (!isset($_SESSION['loggedin'])) { die("You must be logged in to submit care guides"); //this causes to script to stop executing and lets the user know there is a problem /* Note: instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave. */ } //else { //logged in elseif (isset($_SESSION['loggedin']) ){ //logged in $username = $_SESSION['loggedinuser']; if (isset($_POST['listing_title'], $_POST['speciesCommon'], $_POST['cost'], $_POST['business'], $_POST['postage_cost'], $_POST['multipostage'], $_POST['quantity'] ) ) { if( $_POST['listing_title'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['speciesCommon'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['cost'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['business'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['postage_cost'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['multipostage'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['quantity'] == "" ) { echo "Error: Please go back and try again"; } else { $listing_title = mysqli_real_escape_string($con, $_POST['listing_title']); $speciesCommon = mysqli_real_escape_string($con, $_POST['speciesCommon']); $cost = mysqli_real_escape_string($con, $_POST['cost']); $business = mysqli_real_escape_string($con, $_POST['business']); $postage_cost = mysqli_real_escape_string($con, $_POST['postage_cost']); $multipostage = mysqli_real_escape_string($con, $_POST['multipostage'] ); $quantity = mysqli_real_escape_string($con, $_POST['quantity'] ); if( $multipostage == "per item" ) { $postage_cost = $quantity * $postage_cost; } elseif( $multipostage == "Combined Postage" ) { $postage_cost; } $total = $cost + $postage_costage; // Writes customer_sales information to the MySQL database $sqlCustomerSales = "INSERT INTO customer_sales(username, listing_title, speciesCommon, total, business, postage_cost, multipostage ) VALUES ( '". $username ."', '". $listing_title ."', '". $speciesCommon ."', '". $total ."', '". $business ."', '". $postage_cost ."', '". $multipostage."' )"; $result1 = mysqli_query($con, $sqlCustomerSales); // This writes the transaction to the MySQL database $memo = $listing_title; $datetime = date("Y-m-d H:i:s"); $regCustomerTransaction = "INSERT INTO customer_transactions(username, datetime, cost, postage_cost, memo) VALUES ( '". $username ."', '". $datetime ."', '". $cost ."', '". $postage_cost ."', '". $memo."' )"; // Query the database $result2 = mysqli_query($con, $regCustomerTransaction); } // This writes the user_stats to the MySQL database $total_items_sold = $quantity; $regUserStats = "INSERT INTO user_stats(username, datetime, total, items_listed, bonus_credits, last_credit_purchase, total_care_guides, total_items_sold, total_currently_listed_items, total_items_purchased, total_diary_entries, feedback ) VALUES ( '". $username ."', '". $datetime ."', '". $total ."', '". $quantity ."', '". $subtotal ."', '". $last_credit_purchase ."', '". $total_care_guides ."', '". $total_items_sold ."', '". $total_currently_listed_items ."', '". $total_items_purchased ."', '". $total_diary_entries ."', '". $feedback."' )"; // Query the database $result3 = mysqli_query($con, $regUserStats); } ?> <h1>Payment to <?php echo $username ?></h1><br> <?php echo '<strong>Thank you for confirming you would like to purchase $speciesCommon; </strong>'; echo '<br>'; echo '<strong>Your payment comes to a total of $total; </strong></h2>'; echo '<br>'; echo '<br>'; echo 'Please complete payment using the PayPal button<br>'; echo '<br>'; echo '<br>'; ?> <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="shipping" value="<?php echo $postage_cost ?>"> <input type="hidden" name="business" value="<?php echo $business ?>"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="item_name" value="<?php echo $speciesCommon ?>"> <input type="hidden" name="amount" value="<?php echo $cost ?>"> <input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" onclick="OnButton1(); OnButton2();" alt="PayPal – The safer, easier way to pay online." > <img alt="" align="center" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"></form> <?php } else { echo 'Sorry we were unable to process your listing. Please contact <a href="mailto:helpdesk@aquapetcentre.com?Subject=Listing%20error">helpdesk@aquapetcentre.com'; die(); include('includes/overall/footer.php'); } // Close the connection mysqli_close($con); ?><h1>Payment to <?php echo $username ?></h1><br> works, but I think that is because it is passed in the SESSION. Any other $variable such as those below echo '<strong>Thank you for confirming you would like to purchase $speciesCommon; </strong>'; echo '<br>'; echo '<strong>Your payment comes to a total of $total; </strong></h2>';does not work. Why is the form not posting the values to the database. Just in case it helps, the form gets its values from the database, and the values are displayed in the sales page on which the form is contained. Here is the page containing the form. <?php include 'init.php'; include 'includes/overall/header.php'; include 'includes/logo.php'; if (!isset($_SESSION['loggedin'])) { die("You must be logged in to view this page!"); //this causes to script to stop executing and lets the user know there is a problem /* Note: instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave. */ } //else { //logged in elseif (isset($_SESSION['loggedin']) ){ //logged in $username = $_SESSION['loggedinuser']; $results = $con->query("SELECT * FROM user WHERE username = '$username';"); while($row = $results->fetch_array()) { $business = $row['paypal_email']; $user_id = $_GET['user_id']; $results1 = $con->query("SELECT * FROM live_sales WHERE user_id = '$user_id';"); while($row = $results1->fetch_array()) { $username = $row['username']; $fishtype = $row['fishtype']; $speciesCommon = $row['speciesCommon']; $speciesScientific = $row['speciesScientific']; $listing_title = $row['listing_title']; $age = $row['age']; $quantity = $row['quantity']; $origin = $row['origin']; $size = $row['size']; $environment = $row['environment']; $waterChemistry = $row['waterChemistry']; $temperature = $row['temperature']; $feeding = $row['feeding']; $sexing = $row['sexing']; $compatability = $row['compatability']; $temperament = $row['temperament']; $breeding = $row['breeding']; $comments = $row['comments']; $postage_type = $row['postage_type']; $postage_cost = $row['postage_cost']; $multipostage = $row['multipostage']; $cost = $row['cost']; echo "<div class='result'>"; echo "<h3>$speciesCommon</h3>"; echo "<h2>$listing_title</h2>"; echo "<ul class='results'>"; echo "<li>Species</li>" . str_replace("_"," "," $fishtype") . "<br>"; echo "<li>Common Name:</li> $speciesCommon<br>"; echo "<li>Scientific Name:</li> $speciesScientific<br>"; echo "<li>Age:</li> $age<br>"; echo "<li>Quantity:</li> $quantity<br>"; echo "<li>Price per item:</li> £$cost<br>"; echo "<li>Origin:</li> $origin<br>"; echo "<li>Size:</li>$size<br>"; echo "<li>Environment:</li> $environment<br>"; echo "<li>Water Chemistry</li> $waterChemistry<br>"; echo "<li>Temperatu </li> $temperature<br>"; echo "<li>Feeding:</li> $feeding<br>"; echo "<li>Sexing:</li> $sexing<br>"; echo "<li>Compatability:</li> $compatability<br>"; echo "<li>Temperament:</li> $temperament<br>"; echo "<li>Breeding:</li>$breeding<br>"; echo "<li>Comments:</li> $comments<br>"; echo "<li>Postage Type:</li>$postage_type<br>"; echo "<li>Postage Cost:</li> £$postage_cost $multipostage<br>"; echo '<form action="regsale.php" method="POST">'; echo '<input type="hidden" name="username" value="<?php echo $username ?>"'; echo '<input type="hidden" name="listing_title" value="<?php echo $listing_title ?>"'; echo '<input type="hidden" name="speciesCommon" value="<?php echo $speciesCommon ?>"'; echo '<input type="hidden" name="cost" value="<?php echo $cost ?>"'; echo '<input type="hidden" name="business" value="<?php echo $business ?>"'; echo '<input type="hidden" name="postage_cost" value="<?php echo $postage_cost ?>"'; echo '<input type="hidden" name="multipostage" value="<?php echo $multipostage ?>"'; echo "<ul class='results'>"; echo '<li>Quantity:</li>'; echo '<select name="quantity">'; echo "<option value='$quantity'>Maximum of $quantity available</option>"; for ($q=1; $q<=$quantity; $q++) { echo "<option value='$q'>$q</option>"; } echo '</select>'; echo' </ul><br>'; echo '<div align="center">'; echo '<br>'; echo '<input type="submit" value="Confirm Purchase"><br>'; echo '</form><br>'; echo '<br><br> </div>'; exit(); } } echo 'Sorry but we could not find any results.'; } include 'includes/overall/footer.php'; ?>Any help is always appreciated. aquaman |