PHP - Updating Data Not Populating From Database On To Form
Hi I making some forms that write to mysql database, Im now in the process of making the update form so the user can update there details on the form, I want it to populate the form with existing data but its not doing it at all. Thanks in advance
Attached Files
delete.php 210bytes
2 downloads
modify.php 4.03KB
4 downloads
index.php 473bytes
3 downloads
Similar Tutorialshi, Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Sahansevena_ver1\admin\profile\updAdmiInfo.php on line 49 i got this error. here is the coding Code: [Select] <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $dbuser="root"; $dbpswd="****"; $dbserver="localhost"; $nwuser=$_POST['username']; $c_pw=$_POST['cur_password']; $n_pw=$_POST['conf_password']; //$user=$userName; //$pass=$password; // $dbname="sahansevena"; if($_SERVER['REQUEST_METHOD']=='POST'){ //get username and password from admin login.php $con=mysql_connect($dbserver,$dbuser,$dbpswd); if(!$con){ die('coudnt connect db connection prob'.mysql_error()); }else{ if($c_pw==$n_pw){ $uname=mysql_real_escape_string($username); $pword=mysql_real_escape_string($n_pw); // setDatabase($dbname, $con) ; mysql_select_db($dbname, $con); // $result="update admin set username='$uname',password='$pword'" where limit 0; $result="update admin set username='$uname' , password='$pword', last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname' limit 0"; //Checked to see if any rows were returned from the database // If rows were returned, set a session variable to 1 $result=mysql_query($result); if ($result) { $numRow=mysql_numrows($result); if($numRow>0){ //session_start(); //SESSION['admin']="menuka"; echo "data was suaccesfully updated"; /// header ("Location:config/menu.php"); //mysql_close($con); }else{ //session_start(); echo " problem in updating "; //$_SESSION['login'] = ""; //header ("Location:login.php"); } } else { trigger_error(mysql_error(), E_USER_ERROR); } } } }else{ echo 'error message not post methode'; include(login.php); } ?> please check my code and help me to figur out the error thanks in advance, menukadevinda I'm building a php program that registers users onto a website. With the help of people from this thread http://www.phpfreaks.com/forums/index.php?topic=332260.15 I was able to accomplish the goal and now the signup works with conditions that check for a valid email, and if the password is strong enough. T he program correctly displays the the problem when a user does NOT enter a valid email, or a strong enough password, but the user has to re-enter the email and password everytime. I want to make it so that the fields remained populated with what the user entered previously, so he or she does not have to re-enter his or her email/password. Here is the code (its really ghetto) Code: [Select] <?php function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } define('DB_NAME', 'catch'); define('DB_USER', 'username'); define('DB_PASS', 'password'); define('DB_HOST', 'page.sqlserver.com'); // contact to database $connect = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Error , check your server connection.'); mysql_select_db(DB_NAME); //Get data in local variable $v_name=$_POST['name']; $v_email=$_POST['email']; $v_msg=$_POST['msg']; if ( check_email_address($_POST['name']) == false) { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> You must enter a valid email. <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if( $v_name == "" || $v_msg == "" ) // if name is empty or if pass is empty { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> You must enter an email and password. <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if( strcspn( $_REQUEST['msg'], '0123456789' ) == strlen( $_REQUEST['msg'] ) ) // the above statement says if pass does not contain a number { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> <div style="color:red;">Your password must contain a number.</div> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if( strlen($_POST['msg']) < 8 ) // the above statement says if pass is not 8 characters long { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> <div style="color:red;">Your password must be at least 8 characters long.</div> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if ( $_POST['msg'] == strtolower($_POST['msg']) ) // the above statement says if pass is all lowercase { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> <div style="color:red;">Your password must have at least one capital letter.</div> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if ( preg_replace("/[^a-zA-Z0-9\s]/", "", $_POST['msg']) == $_POST['msg'] ) // the above statement says if pass contains no special characters { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> <div style="color:red;">Your password must have at least one special character.</div> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } else echo <<<EOD <B>GO FUCK YOURSELF</B> EOD; ?> I used to be good at this but I changed servers and everything is different... Heres my code so far: Code: [Select] <?php $rated=$_REQUEST['rated']; echo $rated; $rating=$_REQUEST['rating']; echo $rating; // Make a MySQL Connection mysql_connect("localhost", "********", "********") or die(mysql_error()); mysql_select_db("*********") or die(mysql_error()); $result = mysql_query("SELECT * FROM main WHERE username = '$rated'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $votes = $db_field['$rating']; $newvotes = $votes + 1; echo $newvotes; mysql_query("UPDATE main SET $rating = '$newvotes' WHERE username = '$rated'"); ?> Whats going on here is the colomb that I want to update comes as a variable $rated (That works) and then the database selects the row to update with $username (That works) and gets the variable $newvotes by taking the original value of the data its about to update and add 1 to it (That works) Then it updates the field to $newvotes.... I don't know why the update won't go through... there are no errors.... Code: [Select] <?php $host="xxxx"; // Host name $username="xxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="xxxx"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $model_id=$_GET['model_id']; // Retrieve data from database $sql="SELECT model_id, model_name, location, email_1 FROM $tbl_name WHERE model_id='$model_id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="updated.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>Location</strong></td> <td align="center"><strong>Email</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['model_name']; ?>"></td> <td align="center"><input name="location" type="text" id="location" value="<? echo $rows['location']; ?>"></td> <td><input name="email" type="text" id="email" value="<? echo $rows['email_1']; ?>"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['model_id']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <? // close connection mysql_close(); ?> This is the part that isn't working Code: [Select] <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['model_name']; ?>"></td> <td align="center"><input name="location" type="text" id="location" value="<? echo $rows['location']; ?>"></td> <td><input name="email" type="text" id="email" value="<? echo $rows['email_1']; ?>"></td> The echo values aren't being fetched and left blank when I run the script. Any ideas? Hey guys, I have made an admin page for a game Im working on to quickly allow me to update many aspects of the game. My form is sending the correct data because i can echo the $_post but for some reason it isnt updating my database. I just get a blank white page. Could anyone see what i have done wrong. Thanks Code: [Select] <?php require($DOCUMENT_ROOT . "/game/includes/connection.php"); require($DOCUMENT_ROOT . "/game/includes/settings.php"); ?> <?php $name = $_POST['admin_name']; $img = $_POST['admin_img']; $current_hp = $_POST['admin_current_hp']; $max_hp = $_POST['admin_max_hp']; $current_energy = $_POST['admin_current_energy']; $max_energy = $_POST['admin_max_energy']; $level = $_POST['admin_level']; $exp_total = $_POST['admin_exp_total']; $exp = $_POST['admin_exp']; $exp_level = $_POST['admin_exp_level']; $pos_x = $_POST['admin_pos_x']; $pos_y = $_POST['admin_pos_y']; $potion = $_POST['admin_potion']; $ether = $_POST['admin_ether']; $elixir = $_POST['admin_elixir']; $zenni = $_POST['admin_zenni']; $sector = $_POST['admin_sector']; $battle = $_POST['admin_battle']; ?> <?php $sql_1 = "UPDATE game_character SET name='$name', img='$img', current_hp='$current_hp', max_hp='$max_hp', current energy='$current_energy', max_energy='$max_energy', level='$level', exp_total='$exp_total', exp='$exp', exp_level='$exp_level', pos_x='$pos_x', pos_y='$pos_y', potion='$potion', ether='$ether', elixir='$elixir', zenni='$zenni' WHERE id=1"; $sql_2 = "UPDATE game_status SET sector='$sector', battle='$battle' WHERE id=1"; $statement_1 = $dbh->prepare($sql_1); $statement_2 = $dbh->prepare($sql_2); $statement_1->execute(); $statement_2->execute(); ?> <SCRIPT LANGUAGE="JavaScript"> redirTime = "1"; redirURL = "<?php echo $r_admin ?>"; function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); } </script> <BODY onLoad="redirTimer()"> I have a form on our website that a user can fill out for custom product. I want the form data to be 1) stored into a mysql database AND after storing said data, 2) email the same data to our sales department. 1) The form data DOES get stored into mysql database (except for the first two fields, for some weird reason) 2) I added a "mail" section to the php file that stores the data into the database, but it is not working correctly. I have stripped the email portion down to sending just one of the fields in the "message" to make it easier for troubleshooting I have included here, both the form section of the html file, and the formdata.php file that processes the data for your analysis. I am relatively new to php so there are going to be some issues with security, but I can work on those after I get the store & email process to work correctly. Please review my code and see if anyone can be of assistance. I looked through the forums and couldn't find another issue that was the same as mine. If I just overlooked, please tell me the thread post #. Thanks THE FORM WHICH COLLECTS THE DATA ******************************* <form method=POST action=formdata.php> <table width="640" border=0 align="center"> <tr> <td align=right><b>First Name</b></td> <td><input type=text name=FName size=25></td> <td><div align="right"><b>Telephone</b></div></td> <td><input type=text name=Tel size=25></td> </tr> <tr> <td align=right><b>Last Name</b></td> <td><input type=text name=LName size=25></td> <td><div align="right"><b>Fax</b></div></td> <td><input type=text name=Fax size=25></td> </tr> <tr> <td align=right><b>Title</b></td> <td><input type=text name=Title size=25></td> <td><div align="right"><b>Email</b></div></td> <td><input type=text name=Email size=50></td> </tr> <tr> <td align=right><b>Company</b></td> <td><input type=text name=Comp size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Address</b></td> <td><input type=text name=Addr size=25></td> <td><div align="right"><b>Estimated Annual Volume</b></div></td> <td><input type=text name=EAV size=25></td> </tr> <tr> <td align=right><b>City</b></td> <td><input type=text name=City size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>State/Province</b></td> <td><input type=text name=SProv size=25></td> <td><div align="right"><b>Application</b></div></td> <td><input type=text name=Appl size=25></td> </tr> <tr> <td align=right><b>Country</b></td> <td><input type=text name=Ctry size=25></td> <td><div align="right"><b>Type of System</b></div></td> <td><input type=text name=Syst size=25></td> </tr> <tr> <td align=right><b>Zip/Postal Code</b></td> <td><input type=text name=ZPC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td><div align="right"><strong><font color="#FFFF00" face="Arial, Helvetica, sans-serif">COIL DESIGN</font></strong></div></td> <td><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PARAMETERS</strong></font></td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Primary Resistance (ohms)</b></td> <td><input type=text name=Pres size=25></td> <td><div align="right"><b>Primary Inductance (mH)</b></div></td> <td><input type=text name=Pind size=25></td> </tr> <tr> <td align=right><b>Secondary Resistance (ohms)</b></td> <td><input type=text name=Sres size=25></td> <td><div align="right"><b>Secondary Inductance (H)</b></div></td> <td><input type=text name=Sind size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Peak Operating Current (Amps)</b></td> <td><input type=text name=POC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Output Energy (mJ)</b></td> <td><input type=text name=Egy size=25></td> <td><div align="right"><b>Output Voltage (kV)</b></div></td> <td><input type=text name=Volt size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b># HV Towers per Coil</b></td> <td><input type=text name=TPC size=25></td> <td><div align="right"><b># of Coils per Package</b></div></td> <td><input type=text name=CPP size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <th colspan=4><b>Please enter any additional information he </b></th> </tr> <tr> <th colspan=4><textarea name=Mess cols=50 rows=10 id="Message"></textarea></th> </tr> </table> </dl> <div align="center"> <p> <input type=hidden name=BodyTag value="<body bgcolor="#484589" text="#FFFFFF" link="#FFFF00" alink="#FFFFFF" vlink="#FF7F00">"> <input type=hidden name=FA value=SendMail> </p> <p><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PLEASE MAKE SURE ALL INFORMATION<br> IS CORRECT BEFORE SUBMITTING</strong></font></p> <p> <input type=submit value="Submit Form"> </p> </div> </form> THE FILE THAT PROCESSES THE FORM DATA (formdata.php) *********************************************** <?php $con = mysql_connect("localhost","XXX","XXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("customform", $con); $sql="INSERT INTO formdata (Fname, Lname, Title, Comp, Addr, City, SProv, Ctry, ZPC, Tel, Fax, Email, EAV, Appl, Syst, Pres, Pind, Sres, Sind, POC, Egy, Volt, TPC, CPP, Mess) VALUES ('$_POST[Fname]','$_POST[Lname]','$_POST[Title]','$_POST[Comp]','$_POST[Addr]','$_POST[City]','$_POST[SProv]','$_POST[Ctry]','$_POST[ZPC]','$_POST[Tel]','$_POST[Fax]','$_POST[Email]','$_POST[EAV]','$_POST[Appl]','$_POST[Syst]','$_POST[Pres]','$_POST[Pind]','$_POST[Sres]','$_POST[Sind]','$_POST[POC]','$_POST[Egy]','$_POST[Volt]','$_POST[TPC]','$_POST[CPP]','$_POST[Mess]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Your Information Was Successfully Posted"; mysql_close($con); $to = "recipient email address here"; $subject = "Custom Form"; $email = $_POST['Email'] ; $message = $_POST['Comp'] ; $headers = "From: $Email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> Hi All, I've searched long and hard accross the web for an answer to this and finnally given in and requesting help. Here's what i have, i have a database setup and working fine. What i would like to do is for an administrator to be able to update my users details. It may sound odd, why don't you let your users update their own details? Well the administrators are dispatchers if you like, and my users are the 'dispatchees', for want of a better word. So i would like my administrators to be able to dispatch my users with routes and my users be able to see the routes that have been dispatched to them. I've setup a login area and a page that pulls there routes off the database, depending on their login details, i.e. jack will see his routes and jill will see her's independantly. This works by me editing the appropriate columns/rows of my database using phpmyadmin. What i'd like now is for administrators (who are directed to a seperate page, with more controls) to be able to do the same as me (updating the database) but by using a php form/script. I'd like to be able to select the routes from a second table on the same database if possible, to try and keep everything tidy. So my dispatcher would select Route001 from a drop down list, this would fill in the text fields next to the route field with From To, so my dispatcher would know what route001 actually is from/ too, choose a username (now being driven from my other table) and hit dispatch. My user would login to their area, hit view dispatched routes and it would display Route 001 with the correct information. The login area was a downloaded script i modified to suit and is called Login-Redirect_v1.31_FULL Many thanks in advance, hope you can sort of understand what i want Josh PHP/MySQL ability:Novice Any help on this would be greatly appreciated. I am trying to run a mysqldump from my site for my client when they want to back up. They basically will jsut click a button to run the backup. With my script below, the backup file is genrated, but there is no table data in the file. There are the headers in the file with the server IP, linux versin, etc..., but there is no data in the file. Does this look right? Thank you for helping me out. Ryan Code: [Select] ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbhost = 'localhost'; $dbuser = 'databaseuser'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'database'; mysql_select_db($dbname); $tableName = 'lots'; $backupFile1 = '/home/stuff/wwwroot/stuff/appnew/backup/'; $backupFile = $backupFile1.$dbname . date("Y-m-d-H-i-s") . '.gz'; $command = "mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname | gzip > $backupFile"; system($command); $result = mysql_query($command); Alright so I created a MySQL database that has 5 tables each named a brand of a dirt bike. In each table their are 2 fields, one INDEX_ID and MODELS. Under that for rows I have every model bike named. A quick question before I get onto what I want to do: Can data be added underneath the rows? For example, users will be able to submit information about each bike model. If each bike model is a row, can there be a category past that row or do I need to make each field a model name and just have a ton of fields and have the rows be the information users submit. To make it easier to understand I'll post the SQL code for the brand Honda: CREATE TABLE `Honda` ( `INDEX_ID` int(3) NOT NULL auto_increment, `MODELS` varchar(20) collate latin1_general_ci NOT NULL, PRIMARY KEY (`INDEX_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=23 ; -- -- Dumping data for table `Honda` -- INSERT INTO `Honda` VALUES(1, 'CR85'); INSERT INTO `Honda` VALUES(2, 'CR125'); INSERT INTO `Honda` VALUES(3, 'CR250'); INSERT INTO `Honda` VALUES(4, 'CRF100'); INSERT INTO `Honda` VALUES(5, 'CRF150'); INSERT INTO `Honda` VALUES(6, 'CRF230'); INSERT INTO `Honda` VALUES(7, 'CRF250X'); INSERT INTO `Honda` VALUES(8, 'CRF250R'); INSERT INTO `Honda` VALUES(9, 'CRF450X'); INSERT INTO `Honda` VALUES(10, 'CRF450R'); INSERT INTO `Honda` VALUES(11, 'CRF50'); INSERT INTO `Honda` VALUES(12, 'CRF70'); INSERT INTO `Honda` VALUES(13, 'CRF80'); INSERT INTO `Honda` VALUES(14, 'XR650'); INSERT INTO `Honda` VALUES(15, 'CR500'); INSERT INTO `Honda` VALUES(16, 'XR100'); INSERT INTO `Honda` VALUES(17, 'XR200'); INSERT INTO `Honda` VALUES(18, 'XR250'); INSERT INTO `Honda` VALUES(19, 'XR400'); INSERT INTO `Honda` VALUES(20, 'XR50'); INSERT INTO `Honda` VALUES(21, 'XR70'); INSERT INTO `Honda` VALUES(22, 'XR80'); Anyway I still need to figure out how to have this under a form that a user can use to select the bike they want to submit information about. A code like this perhaps?: <? $connection = mysql_connect("localhost","user","pass"); $fields = mysql_list_fields("dbname", "table", $connection); $columns = mysql_num_fields($fields); echo "<form action=page_to_post_to.php method=POST><select name=Field>"; for ($i = 0; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); } echo "</select></form>"; ?> Thanks. The below should choose the radio button that is set by the $_SESSION variable or default to 3. However, it's defaulting to 1. Code: [Select] $content.=' <p class="form_item"><label>Product Rating:</label><br /> <div class="rating_radio"><input type="radio" name="review_product_rating" value="1"'; if(isset($review_product_rating) && $review_product_rating=="1"){$content.='checked';} $content.=' /> <br />1</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="2"'; if(isset($review_product_rating) && $review_product_rating=="2"){$content.='checked';} $content.=' /> <br />2</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="3"'; if(isset($review_product_rating) && $review_product_rating=="3" || !isset($review_product_rating)){$content.='checked';} $content.=' /> <br />3</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="4"'; if(isset($review_product_rating) && $review_product_rating=="4"){$content.='checked';} $content.=' /> <br />4</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="5"'; if(isset($review_product_rating) && $review_product_rating=="5"){$content.='checked';} $content.=' /> <br />5</div> <div class="worst">(Worst)</div><div class="best">(Best)</div> </p> I'm figuring it's because it's multiple if statement (with no elseif) so it's evaluating the first if and being set to true. I tried changing everything else after the first one to elseif, and it's throwing an unexpected T_ELSEIF error. I almost have it but I am missing something. The form is being sent and the row is being created but there is not data. It is blank. I know it is something simple I am missing but I cannot figure it out
If anyone can look at my code below and tell me what I am missing to make the inputed info be seen, I would sure appreciate it.
<?php include_once('class/class_email.php'); // contact to database $connect = mysql_connect("localhost", "admin", "password") or die ("Error , check your server connection."); mysql_select_db("database"); $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $company = $_POST['company']; $telephone = $_POST['telephone']; $comments = $_POST['comments']; $EID = $_POST['eid']; extract ($_POST); // Pick up the form data and assign it to variables // $id = intval($id); $fname = strip_tags($fname); $lname = strip_tags($lname); $email = strip_tags($email); $company = strip_tags($company); $telephone = intval($telephone); $query="INSERT INTO users(`id`, `fname`, `lname`, `email`,`company`,`telephone`) VALUES('$id','$fname','$lname','$email','$company','$telephone')"; echo $query; mysql_query($query) or die(mysql_error()); echo mysql_error(); $SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `id`='$EID' LIMIT 1;"; $result = mysqli_query($connect,$SQL_GetEquipment); $row = mysqli_fetch_assoc($result); $EmailBody = "$fname $lname has requested a quote from NAPE on Item $EID\n Information on quote request: \n Name: $fname $lname \n Email: $email \n Company: $company \n Number: $telephone \n Comments: $comments \n \n Information Requested for: {$row['itemname']}\n The URL to {$row['itemname']} is: http://www.mydomain.com.com/new-product.php?Item=$EID \n Click to send a quote now:\n http://www.mydomain.com.com/Admin/send-quote.php?id=$EID "; $e = new email(); //First value is the URL of your server, the second the port number $e->set_server( 'mail.mydomain.com.com', 26); //First value is your username, then your password $e->set_auth('noreply@mydomain.com', '112233'); //Set the "From" setting for your e-mail. The Name will be base64 encoded $e->set_sender( 'Quote Requested', 'noreply@mydomain.com' ); //for one recipient //$send_to = array('myemail@mydomain.com','myemail2@mydomain.com'); $send_to = ('myemail@gmail.com'); //you may also specify multiple recipients by creating an array like this: //$send_to = array('foo1@localhost.local', 'foo2@localhost.local', 'foo3@localhost.local'); $subject = 'Quote Request from NAPE'; $body = "$EmailBody"; if( $e->mail($send_to, $subject, $body, $headers) == true ) { //message was received by the smtp server //['last'] tends to contain the queue id so I like to save that string in the database echo 'last: '.htmlspecialchars($e->srv_ret['last']).''; }else{ //something went wrong echo 'all: '.nl2br(htmlspecialchars($e->srv_ret['all'])).''; echo 'full:'.nl2br(htmlspecialchars($e->srv_ret['full'])).''; } ?> Hi All I have a contact form whcih works great - its has a little validation on it and sends me all the information I need via email. I now want to store all data submitted via the form to be stored in a MySQL database. What is the best way to do this?? Attached is my form as it is, just being emailed to the relevent accounts. Look forward to your replies. Adi helo does anyone know how to display data from db in checkbox form? i have been searching for days and still cannot find answer that i can understand. i hope someone can help me. i really am lost. any help is much appreciated The company I work for is a not-for-profit organization, we provide medical services for people who can not afford to go to the regular doctor. We need a way to keep track of our patients and their visits and a way to search the data. I found an html form, with name, address, phone number, zip code,,,,,, and made a few changes to fit our needs. But I do not know how to get that information into the database. I also need a way to make sure the information is not a duplicate. Since we are a not-for-profit organization, funds are kinda tight. That is why I want to go with php instead of buying medical software. Most of the medical software on the market cost more then we can afford. I'am a computer tech here at the office, but my field is hardware, networking, and malware removal. PHP programming is new to me. So where do I start? Hi all, I hope someone can help me out here as I think I am close but am not sure where to go from here. The problem is: I have a cms where a user can see a list of photos in the gallery. I provide them the ability to select what photos they want to appear on a particular webpage. The problem I have is that the user wants to be able to put the photos in whatever order they choose. So, I have a form (see attached), the html code is: <table width="566px" cellspacing="0" border="0"> <tr> <td width="33%"> <div class="serviceCell"> <input type='checkbox' checked='checked' name='photos[][0]' value='119' /> Bathroom Sin... <img src="./images/help.gif" title="Enter an integer to signify the order in which this image will appear on the webpage." alt="Enter an integer to signify the order in which this image will appear on the webpage."/> <input type="text" size="2" name="photos[][1]" value="0"/> </div> </td> <td width="33%"> <div class="serviceCell"> <input type='checkbox' checked='checked' name='photos[][0]' value='113' /> Courtyard 1 <img src="./images/help.gif" title="Enter an integer to signify the order in which this image will appear on the webpage." alt="Enter an integer to signify the order in which this image will appear on the webpage."/> <input type="text" size="2" name="photos[][1]" value="0"/> </div> </td> <td width="33%"> <div class="serviceCell"> <input type='checkbox' name='photos[][0]' value='114' /> Courtyard 2 <img src="./images/help.gif" title="Enter an integer to signify the order in which this image will appear on the webpage." alt="Enter an integer to signify the order in which this image will appear on the webpage."/> <input type="text" size="2" name="photos[][1]" value=""/> </div> </td> </tr>... Now, lets assume that the user ticked the box next to 'Courtyard 2' and entered an integer '1' in the input box to signify that this image should be displayed 1st on the chosen webpage. These 2 values go into the multidimensional array (photoid, ranking) and are submitted in the form to php in the photos[][] array. But here is where I have the problem. I am trying to extract the values from the array and then do an insert to a table in mysql. My syntax must be wrong somewhere so I am asking anyone to please offer any advice: if (isset($_REQUEST['submitted'])){ $photos = $_REQUEST['photos']; ... if(!empty($photos)){ foreach($photos as $photoID){ $sql = "INSERT IGNORE INTO menuItemPhotos SET photoid='$photoID[0]', menuItemid='$id', ranking='$photoID[1]'"; $ok = @mysql_query($sql); // execute the query } // End of foreach($photos as $photoID){ } // End of if(!empty($photos)){ Thanks Conor [attachment deleted by admin] Hi everyone, First off thank you very kindly to anyone who can provide some enlightenment to this total php/mysql newb. I am creating my first database and while I have been able to connect to the database within my php script (or so I believe), the form data does not appear to be actually getting sent. I have development experience in other languages but this is completely new to me so if I've missed something that appears painfully obvious like a parse error of some sort, I do apologize. I am creating a website using Godaddy as the hosting account, and attempting to connect to the mysql database at the following URL (maybe this is where I'm going wrong): "pnmailinglist.db.4662743.hostedresource.com" Below is my very simple code: <?php //Verify successful connection to database. $connect = mysql_connect("pnmailinglist.db.4662743.hostedresource.com", "*********", "*********"); if(!$connect) {die("Could not connect!"); } //Initialize variables with form data. $firstname = $_POST['FirstName']; $lastname = $_POST['LastName']; $email = $_POST['Email']; $howfound = $_POST['HowFound']; //Post data to database, or return error. mysql_select_db("pnmailinglist", $connect); mysql_query("INSERT INTO mailinglist (First, Last, Email, How_Found) VALUES ($firstname,$lastname,$email,$howfound)"); mysql_close($connect); echo "Thank you for joining our mailing list! We will contact you soon with the dates and times of our upcoming events."; ?> Thank you again very much for any pointers or hints as to where I'm screwing up. I get no runtime errors, no syntax errors, and the echo message does display fine at the end -- just no data when I go to check my database! Best Regards, CL I have deleted mysql info for safety reasons. Here are the two webpage's codes i'm using right now menu.php <? session_start(); if(!session_is_registered(myusername)){ header("location:login.php"); } ?> <html><title>ChronoServe - Saving Time</title> <link href="style.css" rel="stylesheet" type="text/css"> <body> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="container"> <tr> <td> <table width="335px" height="50%" border="1" align="center" cellpadding="0" cellspacing="0" class="centered"> <tr> <td> <form method="post" action="insertvalues.php"> <table width="100%" border="0" align="center" cellpadding="3" cellspacing="10"> <tr> <td colspan="2"><div align="center" class="font2">Activation Information</div></td> </tr> <tr> <td colspan="2"></td> </tr> <tr> <td width="40%" class="font3">First Name :</td> <td width="60%"> <div align="center"> <input name="firstname" type="text" class="font3" id="firstname" maxlength="25" /> </div></td> </tr> <tr> <td class="font3">Last Name :</td> <td> <div align="center"> <input name="lastname" type="text" class="font3" id="lastname" maxlength="25" /> </div></td> </tr> <tr> <td height="28" class="font3">Phone Number :</td> <td> <div align="center"> <input name="pnumber" type="text" class="font3" id="pnumber" maxlength="10" /> </div></td> </tr> <tr> <td class="font3">Personnel Activated :</td> <td> <div align="center"> <input name="numberactivated" type="text" class="font3" id="numberactivated" maxlength="3" /> </div></td> </tr> <tr> <td height="37" colspan="2"></td> </tr> <tr> <td colspan="2"><div align="center"> <input name="submit" type="Submit" class="font3" value="Submit" /> </div> </td> </tr> </table> </form></td> </tr> </table> </td> </tr> </table> </body> </html> insertvalues.php <?php if(isset($_POST['Submit'])) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $pnumber = $_POST['pnumber']; $numberactivated = $_POST['numberactivated']; mysql_connect ("deleted", "deleted", "deleted") or die ('Error: ' . mysql_error()); mysql_select_db ("deleted"); $query = "INSERT INTO disney_database (id, firstname, lastname, pnumber, numberactivated, date) VALUES ('NULL', '".$firstname."', '".$lastname."', '".$pnumber."', '".$numberactivated."', 'NULL')"; mysql_query($query) or die('Error updating database'); header("location:menu.php"); echo "Database Updated With: ".$firstname."" - "".$lastname."" - "".$pnumber."" - "".$numberactivated.""; } else { echo "Database Error" { ?> Here is my problem. I set a one <form> on every form field I have including the submit button. Now whenever I press the submit button it redirects to insertvalues.php which it should be doing. In insertvalues i told it to query the form data and post it into my database's table. Its not doing that and tells me that it has a database error which i set it to tell me if something goes wrong. Anyone can help me? BTW I can manually query in the information using sql with phpmyadmin. so can someone please review my code for me? thanks big help! You can see what is happening. Visit www.chronoserve.com The username and password are "admin" I am having difficulty inserting the following codes values into my database. I know that the variables contain a value as I am displaying them on the output screen. Code: [Select] $link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection'); mysql_select_db($db_database,$link); mysql_query("SET names UTF8"); $usr = $userid; $golfer = $_REQUEST['golfer']; $tourney = $_REQUEST['tournament']; $backup = $_REQUEST['backup']; date_default_timezone_set('US/Eastern'); $time = date("Y-m-d H:i:s"); $t_id=1; mysql_query("INSERT INTO weekly_picks (t_id, tournament, user, player, backup, timestamp) VALUES ('$t_id', '$tournament', '$usr', '$golfer', '$backup', '$time') or die('Error, insert query failed')"); echo $t_id; echo "<br />"; echo $tourney; echo "<br />"; echo $usr; echo "<br />"; echo $golfer; echo "<br />"; echo $backup; echo "<br />"; echo $time; echo "<br />"; echo $userdetail['email']; echo "<br />"; $to = $userdetail['email']; $subject = "Weekly Tournament Pick for: $tourney"; $message = "This email is to confirm your pick for $tourney has been received. Your pick is: $golfer. Your backup pick is: $backup The time it was submitted was $time Do not reply to this email, the mailbox does not exist. Contact me with any issues at xxxxxxx@xxxxxxx.com"; $from = "noreply@chubstersgcc.com"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); ?> <div> <p>This is to confirm that your pick has been submitted for the following tournament: <?php echo $tourney; ?>. A confirmation of your pick as also been emailed to you.</p> <p>Your golfer: <?php echo $golfer; ?></p> <p>Your backup: <?php echo $backup; ?></p> <p>Your pick was submitted at: <?php echo $time; ?></p> </div> I have a simple database table that has the names of countries listed with just 2 fields ID & country.
I want to use this in a form to choose the country and provide statistics regarding that country.
I know how to get the data from MySQL, but I don't know how I can use this in the form as a selection?
How do I get the options to iterate all of the countries so that when the form is displayed a combo type box is displayed with a dropdown list?
I have not shown any code as I am not sure if this is possible.
Please can anyone advise if this is possible and if so some example code?
|