PHP - Problem In Completing The Form.
Hi !
I am created this form - well it's more of a view and less of a form since the form part is only the check-boxes column and the rest is the data displayed from a database. But now I want to have this submitted with a SUBMIT button centered beneath the form after I have checked the required check boxes. I am unable to find a way to do this maybe simple task. Please help,
unclubbed.php
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'testdb'; // CHANGE THIS TO ANY EXISTING DB ON PHPMYADMIN OR CREATE THIS DB FIRST IN PHPMYADMIN // $fcon = mysqli_connect($dbhost, $dbuser, $dbpass, $db); if(!$fcon ) { die('Could not connect: ' . mysql_error()); } // echo 'Connected successfully'; /* /////////// UNCOMMENT TO CREATE A TABLE IN A DATABASE NAMED testdb THEN COMMENT BACK ///////////// $sql = "CREATE TABLE member( mid INT NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL, reg_date Date NOT NULL, email VARCHAR(30) NOT NULL, cell INT NOT NULL, status VARCHAR(2) NOT NULL, primary key ( mid ))"; if (mysqli_query($fcon,$sql)) { echo "Table member created successfully"; } else { echo "Error creating table: " . mysqli_error($con); } $query = "Insert into member (name, reg_date, email, status) VALUES ('John','1980-08-12','john@123.com','9878954323','cc')"; mysqli_query($fcon, $query); $query = "Insert into member (name, reg_date, email, status) VALUES ('Bill','1988-03-21','bill@123.com','9878900123','cc')"; mysqli_query($fcon, $query); $query = "Insert into member (name, reg_date, email, status) VALUES ('Jack','1990-05-18','jack@123.com','9878912300','cc')"; mysqli_query($fcon, $query); */ $check = true; $query = "SELECT * from member"; $result = mysqli_query($fcon, $query); if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') { echo "<br> Member = ".$_POST['name']."<br>" ; echo "RegDate = ".$_POST['reg_date']."<br>" ; echo "Email = ".$_POST['email']."<br>" ; echo "Status = ".$_POST['status']."<br>" ; /// more code would go here once I have submitted the check box information successfully ///// } ?> <html> <head> <title> CLUB ADMIN </title></head> <body> <table> <?php echo "<table class = 'TFtable' border = 1 cellspacing =2 cellpadding = 5 >"; echo "<tr>"; echo "<th> S.No. </th>"; echo "<th> Member </th>"; echo "<th> Reg Date </th>"; echo "<th> Email </th>"; if($check == true) echo "<th> <Input type='checkbox' id='selecctall' /> All </th>"; else echo "<th> Status </th>"; echo "</tr>"; $cnt = 1; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $name = htmlspecialchars($row['name']); $reg_date = htmlspecialchars($row['reg_date']); $cell = htmlspecialchars($row['cell']); $email = htmlspecialchars($row['email']); $mid = htmlspecialchars($row['mid']); if($check == false) $status = htmlspecialchars($row['status']); echo "<tr>"; echo "<td>".$cnt++."</td>"; echo "<td>".$name."</td>"; echo "<td>".$reg_date. "</td>"; echo "<td>".$email. "</td>"; if($check == true) { echo "<form name = 'form1' action='unclubbed.php' method='post' > "; echo "<td align ='center'><Input type='hidden' name='mid' value=$mid> <Input class='checkbox1' type = 'checkbox' name='check[]' value='$mid'> </td>"; echo "</form>"; echo "</tr>"; } else echo "<td>".$status. "</td> </tr> "; } ?> </table> </body> </html>Thanks ! Similar TutorialsHi, I wouder if someone can help me with this issue? I want a user to click submit on a form which posts the data of to a processing page! but i only want a user to be taken to the processing page if the data in the fields passes some vailation. If the data does not pass the validation error message appear! What way could this be done? I've created a code to allow the user to change the background color and scheme of my site. However, I'm having trouble getting a random color to show up if the user has not yet set a color choice. Here's my code. Could someone put it together to make it work? <?php if ($_POST['change']){ $thevar = $_POST['change']; $_SESSION['bcg'] = $thevar; } if(isset($_SESSION['thecolor'])) { $thecolor = $_SESSION['thecolor']; } else { $num = rand(0,9); if ($num == 0) $thecolor = "0DEBDF"; // CYAN if ($num == 1) $thecolor = "AE00FF"; // PURPLE if ($num == 2) $thecolor = "FFDC01"; // YELLOW if ($num == 3) $thecolor = "FF6D2D"; // PEACH if ($num == 4) $thecolor = "20ff7f"; // LIGHTER-GREEN if ($num == 5) $thecolor = "00E612"; // GREEN if ($num == 6) $thecolor = "E6005D"; // PINK if ($num == 7) $thecolor = "E600CF"; // PINK-PURPLE if ($num == $thecolor = "e2ff20"; // LIME if ($num == 9) $thecolor = "8868ff"; // LAVENDER // send a cookie that never expires setcookie("thecolor",$thecolor, time()+604800); } ?> When I press submit on the form, I do receive the email, but the text in the fields don't show up. How do I fix this? Thanks. FORM CODE: Code: [Select] <form method="post" id="contacts-form" action="process.php"> <fieldset> <div class="rowElem"> <input type="text" value="Name:" onFocus="if(this.value=='Name:'){this.value=''}" onBlur="if(this.value==''){this.value='Name:'}"> </div> <div class="rowElem"> <input type="email" value="E-mail:" onFocus="if(this.value=='E-mail:'){this.value=''}" onBlur="if(this.value==''){this.value='E-mail:'}"> </div> <textarea onFocus="if(this.value=='Message:'){this.value=''}" onBlur="if(this.value==''){this.value='Message:'}">Message:</textarea> <div class="alignright"><input value="Submit" type="submit" name="submit"></div> </fieldset> </form> PHP CODE: Code: [Select] <?php if(isset($_POST['submit'])) { $to = 'example@example.com' ; //put your email address on which you want to receive the information $subject = 'Contact Form'; //set the subject of email. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = "<table><tr><td>Name</td><td>".$_POST['Name:']."</td></tr> <tr><td>E-Mail</td><td>".$_POST['E-mail:']."</td></tr> <tr><td>Message</td><td>".$_POST['Message:']."</td> </tr></table>" ; mail($to, $subject, $message, $headers); header('Location: contact.php'); } ?> Hello everyone, I'm creating a user information form which includes an image uploader as well as several text inputs. The problem is with... Code: [Select] <form ENCTYPE = "multipart/form-data"></form> When I have ENCTYPE set to multipart/form-data the image uploader works but not the text inputs. When its not set text inputs work but image uploader doesn't work. Anyone have insight into why this is and a good solution? Thanks Below here is the php and form i got right now. What i want to achieve is that when i check a checkbox that the TotalCosts will be updated by the matching value, and when i checked multiple boxes that those vallues will be added together. But the most important thing what i want to achieve right now is that when you check a box that the TotalCosts echo on the screen will be updated right away with the correct vallues. I tried some things i found while looking here and on other sites, but nothing seems to be working the way i want. Anyways, here is my php, i hope someone can help me <?php $hire = 60.00; $hire1 = 20.00; $hire2 = 22.50; $TotalCosts = 0.00; ?> <form action="index.php" method="post"> <input type="checkbox" name="hire" value="" />Hire <br /> <input type="checkbox" name="hire1" value="" />Hire1 <br /> <input type="checkbox" name="hire2" value="" />Hire2 <br /> </form> <?php if (isset($_POST['hire'])) { $TotalCosts = $TotalCosts + $hire; } if (isset($_POST['hire1'])) { $TotalCosts = $TotalCosts + $hire1; } if (isset($_POST['hire2'])) { $TotalCosts = $TotalCosts + $hire2; } echo $TotalCosts; ?> Hello, Having a problem when putting an xml tag in an input field. The field shows blank in $_POST. Heres some sample code
<!doctype html>
If I put <test in the field it shows up blank in the print of POST. I actually want to pass xml in a hidden field, and it wouldnt work. Tracked it down to this problem. Thanks in Advance Edited May 14, 2020 by derbyshiresoftwareerror How can I get an output where it only shows the name of the drink and quantity where quantity > 0 ? Code: [Select] <?php if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="nl"> <html> <form method="post" action="<?php echo $PHP_SELF;?>"> <?php $drinks = array("cola", "fanta", "bier", "koffie", "thee", "vodka"); $i = 0; echo "<table>"; while ($drinks[$i]) { $listnaam = $drinks[$i] . "_aantal"; $optionlist = "<select name= '$listnaam' ><option>0</option><option>1</option><option>2</option><option>3</option></select>"; echo "<tr><td >" . $drinks[$i] . "</td>"; echo "<td>" .$optionlist . "</td></tr>"; $i++; } echo "</table>"; ?> <input type="submit" value="Toon Output" name="submit"/> </form> <?php } else {echo $drinks;} ?> </html> I don't know whether this is a PHP or an HTML question. I want to be able to post a preset value to accompany an input text value, and have both values entered in the database record. You can see in the code below that the form asks for names for up to six student groups, such as "Year7", "Year8", "Year9" and so on. What I want my form to do is to post the accompanying preset input name (in this case "group1", "group2", "group3", and so on) to a second column in the same record, so that I can search the records on this preset field. How can I do this? Code: [Select] <table width="750" align="center" cellpadding="4"> <form action="admin_login.php" method="post" enctype="multipart/form-data"> <tr> <td><div align="right"><font size="-1">Student Group 1: </font><font color="#CC0000"> </font></div></td> <td><input name="group1" type="text" value="<?php echo "$group1"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 2: </font><font color="#CC0000"> </font></div></td> <td><input name="group2" type="text" value="<?php echo "$group2"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 3: </font><font color="#CC0000"> </font></div></td> <td><input name="group3" type="text" value="<?php echo "$group3"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 4: </font><font color="#CC0000"> </font></div></td> <td><input name="group4" type="text" value="<?php echo "$group4"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 5: </font><font color="#CC0000"> </font></div></td> <td><input name="group5" type="text" value="<?php echo "$group5"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 6: </font><font color="#CC0000"> </font></div></td> <td><input name="group6" type="text" value="<?php echo "$group6"; ?>" /></td> </tr> <tr> <td><div align="right"></div></td> <td><input type="submit" name="Submit" value="Submit Form" /></td> </tr> </form> Im a having a problem and im thinking maybe i cant do it with php and will have to look into java script I have several If statements but will only display two of them below. both inputs run on the same button $_POST['build'] the first if statement updates $naqahdah in the database. Its a number being subtracted. I need the 2nd if statement to grab the new updated naqahdah field in the database before the script reads it. Code: [Select] <?php if ($_POST['build']) { if ($_POST['homes']) { if ($naqahdah < $cost_homes) { }else{ mysql_query("UPDATE systems SET homes= $homes + '".mysql_real_escape_string($_POST['homes'])."' WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); mysql_query("UPDATE systems SET naqahdah= $naqahdah - $cost_homes WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); }}} if(isset($_POST['build'])) { if($_POST['naqahdah_mines']) { if ($naqahdah < $cost_naqahdah_mines) { }else{ mysql_query("UPDATE systems SET naqahdah_mines= $naqahdah_mines + '".mysql_real_escape_string($_POST['naqahdah_mines'])."' WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); mysql_query("UPDATE systems SET naqahdah= $naqahdah - $cost_naqahdah_mines WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); }}} ?> hey, ive edit a contact form i found on net, changed everything i needed, when i click the "submit" button it shows that the form was send succsesfuly but nothing comes up in the email.. what is wrong ?
form code html:
<form method="post" action="../booking/booking.php" id="contactform"> Hi! I am not great at using php but do use it to process forms on websites. I always use the same script and just change the relevant sections for each website. This usually works with no problems. I am writing an mailing list subscribe/unsubscribe form my website and it works fine as in I get the email sent through with all the information on it and the automated reply gets sent out etc. The problem is that once the user hits Submit instead of going to the redirect page it stays on the php page. if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a company name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.hillsideweb.co.uk/unsubthanks.html" );} Like I say this exact script works on another site of mine perfectly well, can someone please help me solve this. The form is found on http://www.hillsideweb.co.uk/unsubscribe.html I hope this makes sense! Many thanks Swenglish Hello everyone , I have form and I am using action create2.php and everything is working when I want to send to my database information through the form .. This are codes : Code: [Select] <form action="create2.php" method="post"> <p>email</p> <input type="text" name="inputPayer_email" value="" /> <br/> <p>Name</p> <input type="text" name="inputFirst_name" value="" /> <br/> <p>Last name</p> <input type="text" name="inputLast_name" value="" /> <br/> <p>Address 1</p> <input type="text" name="inputAddress_street" value="" /> <br/> <p>Address 2</p> <input type="text" name="inputAddress_city" value="" /> <br/> <p>State</p> <input type="text" name="inputAddress_state" value="" /> <br/> <p>Mobile number</p> <input type="text" name="inputcmd" value=""> <br/> <input type="submit" name="submit" value="submit" /> </form> and create2.php code is Code: [Select] <?php $db_host = "mysqlxxx.host.com"; // Place the username for the MySQL database here $db_username = "nia"; // Place the password for the MySQL database here $db_pass = "pass"; // Place the name for the MySQL database here $db_name = "db"; // Run the actual connection here mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); mysql_select_db("$db_name") or die ("no database"); ?> <?php $Payer_email = $_POST['inputPayer_email']; $First_name = $_POST['inputFirst_name']; $Last_name = $_POST['inputLast_name']; $Address_street = $_POST['inputAddress_street']; $Address_city = $_POST['inputAddress_city']; $Address_state = $_POST['inputAddress_state']; $cmd = $_POST['inputcmd']; mysql_query("INSERT INTO `transactions` ( `payer_email` , `first_name` , `last_name` , `address_street` , `address_city` , `address_state` , `cmd` , ) VALUES (NULL , '$Payer_email', '$First_name', '$Last_name', '$Address_street', '$Address_city', '$Address_state', '$cmd')") or die(mysql_error()); //!!!!!!!!!!!!!!!!!!!!!!!!! Email User the activation link !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $to = "$Payer_email"; $from = "admin@mywebsite.com"; $subject = "Your order .."; //Begin HTML Email Message $message = "Hi $First_name, Thank you , bla bla .. "; //end of message $headers = "From: $from\r\n"; $headers .= "Content-type: text\r\n"; mail($to, $subject, $message, $headers); $msgToUser = "Thank you .. "; include_once 'hvala.php'; exit(); // Close else after duplication checks header('Location: hvala.php'); ?> And this is redirecting me to hvala.php and sending e-mail for those who ordered something .. But when I want to add javascript so I can validate my web form , sending information in database is not working . I named form with "m" and action is create2.php , javascript works but my order form is not sending to my database anything .. Only blank fields in database .. I will give code with javascript , so if anyone see where is mistake , please write on thread .. Thank you in advance Code: [Select] <script type="text/javascript" language="javascript"> <!-- function validateMyForm ( ) { var isValid = true; if ( document.m.inputPayer_email.value == "" ) { alert ( "Insert email" ); isValid = false; } else if ( document.m.inputPayer_email.value.length < 1 ) { alert ( "Insert email" ); isValid = false; } else if ( document.m.inputFirst_name.value == "" ) { alert ( "First name" ); isValid = false; } else if ( document.m.inputLast_name.value == "" ) { alert ( "Last name" ); isValid = false; } else if ( document.m.inputAddress_street.value == "" ) { alert ( "Address" ); isValid = false; } else if ( document.m.inputAddress_city.value == "" ) { alert ( "Address" ); isValid = false; } else if ( document.m.inputAddress_state.value == "" ) { alert ( "State" ); isValid = false; } else if ( document.m.inputcmd.value == "" ) { alert ( "Mobile number" ); isValid = false; } return isValid; } //--> </script> <form name="m" action="create2.php""> <p>email</p> <input type="text" name="inputPayer_email" value="" /> <br/> <p>Name</p> <input type="text" name="inputFirst_name" value="" /> <br/> <p>Last name</p> <input type="text" name="inputLast_name" value="" /> <br/> <p>Address 1</p> <input type="text" name="inputAddress_street" value="" /> <br/> <p>Address 2</p> <input type="text" name="inputAddress_city" value="" /> <br/> <p>State</p> <input type="text" name="inputAddress_state" value="" /> <br/> <p>Mobile number</p> <input type="text" name="inputcmd" value=""> <br/> <input name="button" type="submit" value="Submit Information" onclick="javascript:return validateMyForm();"/> </form> Hi, I have made personal messaging system however I can't reply unless it is to the last message! I think I've messed up the looping somewhere but can you see if you can figure out what's wrong with it? This is the code for the inbox page: <?php require('scripts/top.php'); ?> <title>Spares List | Your Messages</title> <div id='full'> <?php if ($username){ echo "<a href='create_message.php'>Create Message</a> <div id='box'> <b class='corners'> <b class='corners1'><b></b></b> <b class='corners2'><b></b></b> <b class='corners3'></b> <b class='corners4'></b> <b class='corners5'></b></b> <div class='cornersfg'> <div id='top'>Inbox for $username</div> <div id='bottom' style='padding: 10px;'>"; //////////////////////////////////////////////////////////////////////// require('scripts/connect.php'); $query = mysql_query("SELECT * FROM messages WHERE to_user='$username' ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows > 0){ echo "<form action='delete_message.php' method='POST'>"; echo "<div id='messages'> <div id='leftside'><input type='checkbox' name='selectall'><input type='submit' name='deleteinbox' value='Delete' class='button'></div> <div id='rightside'>Date</div> <div id='center'>Subject and Message</div> <div style='clear: both;'></div> </div>"; while($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $msg_to_user = $row['to_user']; $msg_to_id = $row['to_id']; $msg_from_user = $row['from_user']; $msg_from_id = $row['from_id']; $msg_subject = $row['subject']; $msg_content = $row['content']; $msg_date = $row['date']; $msg_from_delete = $row['from_delete']; $msg_to_delete = $row['to_delete']; if (!$msg_to_delete){ echo "<div id='messages'>"; echo "<div id='leftside'> <input type='checkbox' name='cb$msg_id' value='$msg_id'> <a href='profile.php?id=$msg_from_id' target='_blank'>$msg_from_user</a> </div>"; echo "<div id='rightside'>$msg_date</div>"; echo "<div id='center'> <span class='toggle'><a href='#'>$msg_subject</a></span> <div class='hiddenDiv'> <br>$msg_content<br><br> <span class='toggle'><a href='#'>REPLY</a></span> <div class='hiddenDiv'> <form action='reply.php' method='POST'> <input type='hidden' value='$msg_id' name='replyid'> <input type='text' name='replysubject' style='width: 300px;' class='text-box' value=' $msg_subject'><br> <textarea name='replycontent' style='width: 298px;' rows='5'></textarea><br><br> <input type='submit' name='replybutton' class='button' value='Reply'> </form> </div> </div> </div>"; echo "<div style='clear: both;'></div>"; echo "</div>"; $num += 1; } } if ($num == 0){ echo "You have no messages in your inbox."; } echo "</form>"; } else echo "You have no messages in your inbox."; //////////////////////////////////////////////////////////////////////// echo "</div> </div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// echo "<div id='box'> <b class='corners'> <b class='corners1'><b></b></b> <b class='corners2'><b></b></b> <b class='corners3'></b> <b class='corners4'></b> <b class='corners5'></b></b> <div class='cornersfg'> <div id='top'>Outbox for $username</div> <div id='bottom' style='padding: 10px;'>"; //////////////////////////////////////////////////////////////////////// require('scripts/connect.php'); $query = mysql_query("SELECT * FROM messages WHERE from_user='$username' ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows > 0){ echo "<form action='delete_message.php' method='POST'>"; echo "<div id='messages'> <div id='leftside'><input type='checkbox' name='selectall'><input type='submit' name='deleteoutbox' value='Delete' class='button'></div> <div id='rightside'>Date</div> <div id='center'>Subject and Message</div> <div style='clear: both;'></div> </div>"; while($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $msg_to_user = $row['to_user']; $msg_to_id = $row['to_id']; $msg_from_user = $row['from_user']; $msg_from_id = $row['from_id']; $msg_subject = $row['subject']; $msg_content = $row['content']; $msg_date = $row['date']; $msg_from_delete = $row['from_delete']; $msg_to_delete = $row['to_delete']; if (!$msg_from_delete){ echo "<div id='messages'>"; echo "<div id='leftside'> <input type='checkbox' name='cb$msg_id' value='$msg_id'> <a href='profile.php?id=$msg_from_id' target='_blank'>$msg_from_user</a> </div>"; echo "<div id='rightside'>$msg_date</div>"; echo "<div id='center'> <span class='toggle'><a href='#'>$msg_subject</a></span> <div class='hiddenDiv'> <br>$msg_content<br><br> </div> </div>"; echo "<div style='clear: both;'></div>"; echo "</div>"; $num += 1; } } if ($num == 0){ echo "You have no messages in your outbox."; } echo "</form>"; } else echo "You have no messages in your outbox."; //////////////////////////////////////////////////////////////////////// echo "</div> </div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; echo "</div>"; } else echo "<center><h2><font color='red'>You must be logged in to view this page.</font></h2></center>"; require('scripts/bottom.php'); ?> And this is the code for the deleteorsend php file: <?php include("header.inc"); ?> <table border="0" width="100%"><tr><td valign="top" width="800"> <div id="content"> <?php //Start Content $replybtn = $_POST['replybutton']; $inboxbtn = $_POST['deleteinbox']; $outboxbtn = $_POST['deleteoutbox']; if($_SESSION['uid']){ if ($replybtn){ $subject = $_POST['replysubject']; $content = $_POST['replycontent']; $replyid = $_POST['replyid']; if ($subject && $content){ $date = date("M d, Y"); $query = mysql_query("SELECT * FROM messages WHERE content='$content' AND date='$date'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM messages WHERE id='$replyid' AND to_user='$username'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $to_id = $row['from_id']; $to_user = $row['from_user']; mysql_query("INSERT INTO messages VALUES ('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date', '0', '0')"); echo "Your reply has been sent. <a href='messages.php'>Click here</a> to return to your inbox."; } else echo "No message was sent. An error has occured!!!!"; } else echo "You can NOT resend the same messages."; } else echo "You did not supply a subject and/or message."; } else if($inboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE to_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "cb"."$msg_id"; $checkbox = $_POST[$value]; if ($checkbox){ mysql_query("UPDATE messages SET to_delete='1' WHERE id='$msg_id'"); } } echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox."; } else if($outboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE from_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "cb"."$msg_id"; $checkbox = $_POST[$value]; if ($checkbox){ mysql_query("UPDATE messages SET from_delete='1' WHERE id='$msg_id'"); } } echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox."; } else echo "You must click the button!"; } else echo "You must be logged in to do that!"; //End Content ?> </div> </td><td width="250"> <?php include("sidebar.inc"); ?> </td> </table> <?php include("footer.inc"); ?> </div> </div> I hope you can work out what is wrong as I am quite new to php. Thanks in advanced Cameron Hi first off i`d like to say hello, i`ve just been customising a site template and the contact form php script appears to be incorrect. I`ve tried to contact the templates creator, but have had no success. The contact form is pretty simple, a name, email and message fields. The form is sending an email but i`m not getting the message text. i get something like this Quote "The Name Of The Sender: 1 Email: blahblah@blah.com Subject: Message: IP ADDRESS: 82.28.90.77 Daniel Reed Photography" which is pretty useless. I`m less than a novice and i know it could be as simple as a typo but if anyone could have a look over this i`d really appreciate it. Code: [Select] <?php //Type the receiever's e-mail address $emailAddress = "dr@danielreedphotography.com"; //Type your Site Name $siteName = "Daniel Reed Photography"; $contact_name = $_POST['name']; $contact_email = $_POST['email']; $contact_subject = $_POST['subject']; $contact_message = $_POST['message']; if( $contact_name = true ) { $sender = $contact_email; $receiver = $emailAddress; $client_ip = $_SERVER['REMOTE_ADDR']; $email_body = "The Name Of The Sender: $contact_name \nEmail: $sender \n\nSubject: $contact_subject \n\nMessage: \n\n$contact_message \n\nIP ADDRESS: $client_ip \n\n$siteName"; $emailAutoReply = "Hi $contact_name, \n\nWe have just received your E-Mail. We will get in touch in a few days. Thank you! \n\n$siteName "; $extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion(); $autoReply = "From: $receiver\r\n" . "Reply-To: $receiver \r\n" . "X-Mailer: PHP/" . phpversion(); mail( $sender, "Auto Reply: $contact_subject", $emailAutoReply, $autoReply ); if( mail( $receiver, "New E-Mail - $contact_subject", $email_body, $extra ) ) { echo "success=yes"; } else { echo "success=no"; } } ?> the website is danielreedphotography.com if you`re if seeing the form will help. click the contacts link at the top to see it in action or inaction lol. many thanks, Daniel Reed I am building a hospital chart simulation for my pharmacy students and I am trying to learn PHP. Today is form validation. The following form has only one input. I have tried to piece together examples I find and from readings. The function works if the student leaves the input null, but does not catch any other errors and passes them to the next form as typed. The Patient ID is a 6 digit numeric between 100000 and 999999 and the 'patientid' will eventually be placed in a MySQL query to see if a patient with that number exists, but one question at a time. Thanks for any help. <?php session_start(); if (isset($_POST['submit'])) { $patient_id = check_input($_POST['patient_num'], "Enter Patient ID"); $_SESSION['patientid'] = $patient_id; header('Location: pt_found.php'); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Patient Call Form</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <form name="patientfindform" action="#" method="post"> <div> <label>Patient ID:</label> <input type="text" name="patient_num" /><br /> </div> <div> <label> </label> <input type="submit" name="submit" value="Find Patient" /><br /> </div> </form> <script> type="text/javascript"> document.patientfindform.patient_num.focus(); </script> </div> </body> </html> <?php function check_input ($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data)== 0) { die($problem); } return $data; } ?> Hi everyone, im working on a e comm site as a project. I have a register.php page, and its supposed to check for the presence of posted data, and if data is not posted show a form block,and if posted data is present insert it into a database. However its not working,i get an unexpected } on line 114, where there is a }else{ . I've only been working with php a few days, but from what i've read the braces seem where they should be,can someone please tell me where the problem is? <script language="JavaScript" type="text/javascript" src="library/checkout.js"></script> <?php //set up a couple of functions function doDB() { global $mysqli; //connect to server and select database; you may need it $mysqli = mysqli_connect("localhost", "root", "", "onlinestore"); } //determine if they need to see the form or not if (!$_POST) { //they need to see the form, so create form block $display_block = " <form name=\"register\" method=\"post\"action=\"index.php?r=1\"\ id=\"register\"> <table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\" class=\"entryTable\"> <tr class=\"entryTableHeader\"> <td colspan=\"2\">Login Details</td> </tr> <tr> <td width=\"150\" class=\"label\">Email</td> <td class=\"content\"><input name\=\"txtEmail\" type=\"text\" class=\"box\" id=\"txtEmail\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Password</td> <td class=\"content\"><input name=\"txtPassword\" type=\"password\" class=\"box\" id=\"txtPassword\" size=\"30\" maxlength=\"50\"></td> </tr> </table> <p> </p> <table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\" class=\"entryTable\"> <tr class=\"entryTableHeader\"> <td colspan=\"2\">Shipping Information</td> </tr> <tr> <td width=\"150\" class=\"label\">First Name</td> <td class=\"content\"><input name=\"txtShippingFirstName\" type=\"text\" class=\"box\" id=\"txtShippingFirstName\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Last Name</td> <td class=\"content\"><input name=\"txtShippingLastName\" type=\"text\" class=\"box\" id=\"txtShippingLastName\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Address1</td> <td class=\"content\"><input name=\"txtShippingAddress1\" type=\"text\" class=\"box\" id=\"txtShippingAddress1\" size=\"50\" maxlength=\"100\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Address2</td> <td class=\"content\"><input name=\"txtShippingAddress2\" type=\"text\" class=\"box\" id=\"txtShippingAddress2\" size=\"50\" maxlength=\"100\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Phone Number</td> <td class=\"content\"><input name=\"txtShippingPhone\" type=\"text\" class=\"box\" id=\"txtShippingPhone\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Area</td> <td class=\"content\"><input name=\"txtShippingState\" type=\"text\" class=\"box\" id=\"txtShippingState\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">City</td> <td class=\"content\"><input name=\"txtShippingCity\" type=\"text\" class=\"box\" id=\"txtShippingCity\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Post Code</td> <td class=\"content\"><input name=\"txtShippingPostalCode\" type=\"text\" class=\"box\" id=\"txtShippingPostalCode\" size=\"10\" maxlength=\"10\"></td> </tr> </table> <p> </p> <table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\" class=\"entryTable\"> <tr class=\"entryTableHeader\"> <td width=\"150\">Payment Information</td> <td><input type=\"checkbox\" name=\"chkSame\" id=\"chkSame\" value=\"checkbox\" onClick=\"setPaymentInfo(this.checked);\"> <label for=\"chkSame\" style=\"cursor:pointer\">Same as shipping information</label></td> </tr> <tr> <td width=\"150\" class=\"label\">First Name</td> <td class=\"content\"><input name=\"txtPaymentFirstName\" type=\"text\" class=\"box\" id=\"txtPaymentFirstName\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Last Name</td> <td class=\"content\"><input name=\"txtPaymentLastName\" type=\"text\" class=\"box\" id=\"txtPaymentLastName\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Address1</td> <td class=\"content\"><input name=\"txtPaymentAddress1\" type=\"text\" class=\"box\" id=\"txtPaymentAddress1\" size=\"50\" maxlength=\"100\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Address2</td> <td class=\"content\"><input name=\"txtPaymentAddress2\" type=\"text\" class=\"box\" id=\"txtPaymentAddress2\" size=\"50\" maxlength=\"100\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Phone Number</td> <td class=\"content\"><input name=\"txtPaymentPhone\" type=\"text\" class=\"box\" id=\"txtPaymentPhone\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Area</td> <td class=\"content\"><input name=\"txtPaymentState\" type=\"text\" class=\"box\" id=\"txtPaymentState\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">City</td> <td class=\"content\"><input name=\"txtPaymentCity\" type=\"text\" class=\"box\" id=\"txtPaymentCity\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Post Code</td> <td class=\"content\"><input name=\"txtPaymentPostalCode\" type=\"text\" class=\"box\" id=\"txtPaymentPostalCode\" size=\"10\" maxlength=\"10\"></td> </tr> </table> <p> </p> <p> </p> <p align=\"center\"> <input class=\"box\" name=\"btnStep1\" type=\"submit\" id=\"btnStep1\" value=\"Proceed >>\"> </p> </form>" } else { //connect to database doDB(); //add records $add_sql = "INSERT INTO tbl_customer (email) VALUES('".$_POST["txtEmail"]."')"; $add_sql = "INSERT INTO tbl_customer (password) VALUES('".$_POST["txtPassword"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_first_name) VALUES('".$_POST["txtShippingFirstName"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_last_name) VALUES('".$_POST["txtShippingLastName"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_address1) VALUES('".$_POST["txtShippingAddress1"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_address2) VALUES('".$_POST["txtShippingPhone"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_phone) VALUES('".$_POST["txtShippingState"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_city) VALUES('".$_POST["txtShippingCity"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_state) VALUES('".$_POST["txtShippingState"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_postal_code) VALUES('".$_POST["txtShippingPostalCode"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_first_name) VALUES('".$_POST["txtPaymentFirstName"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_last_name) VALUES('".$_POST["txtPaymentLastName"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_address1) VALUES('".$_POST["txtPaymentAddress1"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_address2) VALUES('".$_POST["txtPaymentPhone"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_phone) VALUES('".$_POST["txtPaymentState"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_city) VALUES('".$_POST["txtPaymentCity"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_state) VALUES('".$_POST["txtPaymentState"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_postal_code) VALUES('".$_POST["txtPaymentPostalCode"]."')"; $add_res = mysqli_query($mysqli, $add_sql) or die(mysqli_error($mysqli)); $display_block = "<p>Thanks for signing up!</p>"; } ?> Hey All, Our web server appears to be getting hacked by a third part and I think they are getting in via a PHP contact form. They are planting a .htaccess file in the root folder redirecting the pages to a blank one. Can anyone give me advice on the best course of action to take. I can post our PHP code if needed. Many Thanks For those willing to run this sample problem, reference the 2 files below. You will need to create an Excel file called blank.xls and put it in the same directory as these 2 files. When you launch indexTest.php, it will load the formTest.html.php page. This form has 3 options on it: 1. Export Excel - will prompt you to download the Excel file you made and should clear the error message on the form 2. Test Flag - tests the functionality of clearing the error message, shows what should happen when the Export Excel option is selected 3. Reset - resets back to initial state I really need the Export Excel option to be allow the form to reload properly. This is a problem that I have been wresting with for awhile and need a solution. Hopefully someone can give me some insight on how to get this to work. indexTest.php <?php $frmErrorLevel=1; $frmErrMsg='Error Level 1 indicated'; if(isset($_POST['action']) && $_POST['action']=='submitted') { if(isset($_POST['ExportCarrier'])) { $download_filename = "blank.xls"; $FileInfo = pathinfo($download_filename); // fix for IE catching or PHP bug issue header("Pragma: public"); header("Expires: 0"); // set expiration time header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // browser must download file from server instead of cache // force download dialog header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-type: application/x-msexcel"); header("Content-Type: application/download"); // use the Content-Disposition header to supply a recommended filename and // force the browser to display the save dialog. header("Content-Disposition: attachment; filename=".$download_filename.";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($download_filename)); @readfile($download_filename); //ob_end_clean(); $frmErrorLevel=0; } if(isset($_POST['Test_Flag']) && $_POST['Test_Flag']=='Test Flag'){ $frmErrorLevel=0; $frmErrMsg=''; } } include ('formTest.html.php'); exit(); ?> formTest.html.php <?php ini_set ("display_errors", "1"); error_reporting(-1); echo "<pre>"; echo "--> Form data (POST) <-- <br>"; print_r ($_POST); echo "--> Form data (GET) <-- <br>"; print_r ($_GET); echo "</pre>"; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Export Trucking Data</title> </head> <body> <h1>Export Data</h1> <form action="" method="post"> <?php if($frmErrorLevel>0) { echo '<font color=#CC6600 size=+1>'.$frmErrMsg.'</font><br><br>'; } ?> <table width="650" border="0"> <caption> <font size="+3">Data Export Options</font> </caption> <tr> <td> <?php if($frmErrorLevel==1) print '<img src= "..\..\images\rdx.gif">'; else echo " "; ?> </td> <td width="275"><label> Carrier table data</label></td> <td width="100"><input name="ExportCarrier" type="submit" value="Export Excel"></td> <td> <div align="center"> <td><input type="submit" name="Test Flag" value="Test Flag"></td> <td> <div align="center"> <td><input type="submit" name="Reload Form" value="Reset"></td> </tr> </table> <div> <input type="hidden" name="action" value="submitted" /> </div> </form> </body> </html> Hi My PHP knowledge is very very small. This code was written for me by a friend but everytime I ask him for help I end up being more confused then I was anyways . It was working perfectly until I changed my webspace to another provider. <?php if ($email == "") { require_once ("xyz1.html"); } else { $pos = strrpos($email, "@"); if ($pos != false) { $to = "email@address.com"; $headers = "From: \"".$name."\"<".$email.">\n"; $message = " \n Name: $name , ..."; $sent = mail ($to, mailheadersubject, $message, $headers); require_once ("send.html"); } else { require_once ("xyz2.html"); } } ?> ... and the HTML part: <form action="send.php" method="GET"> Apart from that it's just a normal HTML contact form. As I said nothing has changed exepct the provider, so my only guess would be that the problem is that part of this code doesn't work as it used to on a newer version of PHP. What it did was - as you probably see in the code anyway - checking if there was something written in the contact form where you put in your email, else show xyz1.html , then checking if there is a "@" in the email address and if there is send the email, if not posting the xyz2.html. Now it always shows the xyz1.html, no matter what is written in the email part of the contact form. I hope there is a small simple solution to the problem, but I'm grateful for any help I can get greetings Hi, I've got a pdf catalog which posts an order to a php form. The idea is that that the php page looks like an order form that the client can check before finally hitting 'submit' (i.e. along the lines of go to shopping cart). I'd like the php page to be editable. Meaning clients can not only look at their echoed order, but change it before committing to it. So the catalog order gets put into a php submit form with editable fields. I've read that others have accomplished this with statements like: Code: [Select] value="<?php echo $clientName; ?>" Which should fill the client name input box on the order form with the posted variable. But it doesn't work properly for me, instead, the form field is filled with "<?xml version=" with the expected name on the line benath the input box and " /> on the line beneath that. Placing the input box declaration entirely within php tags doesn't work either (exactly the same output). Code: [Select] <?php echo ("Name: <input class=\"inputbox\" type=\"text\" name=\"clientName\" maxlength=\"40\" value=\"$clientName\"><br>"); ?> Can anyone help? Steve |