PHP - Echo And Insert Into Problem.
This php file cant echo in the 2nd php code, can anyone help me about this?
1st php code to connect into the 2nd php code Code: [Select] <?php $Total = $Total + $Amount; } ?> </tr> <tr> <td colspan="3" align="Right">Total</td> <td align ="Center"><?php echo number_format($Total,2);?></td> </tr> 2nd php code Code: [Select] <?php $db = mysql_connect("localhost", "root", ""); mysql_select_db("vinnex",$db); $TransNo = $_POST['TransNo']; $Username = $_POST['Username']; $Date = $_POST['Date']; $Total = $_GET['Total']; echo $Total; $sqltransaction = " INSERT INTO transaction (TransNo, Username, Date, Total) VALUES ('$TransNo', '$Username', '$Date', '$Total')"; $resulttransaction = mysql_query($sqltransaction); ?> Similar TutorialsHi, i insert in db with mysql_real_escape_string() function, but when i read i use this: - htmlentities(stripslashes($value), ENT_QUOTES, "UTF-8") - for all fields but no textarea - stripslashes($value) - for textarea, becouse when insert that textare, its tinymce, and have html tags Is this right way ? I am echo information from the database now I would like to insert these to different table. I am using checkbox to echo and when the user click on the one of these the result should be saved to a new table. So far I have<?php include 'Database/connection.php'; include 'Database/question_sql.php'; while($info = mysql_fetch_array( $sql )) { echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; } ?> What I'm basically trying to accomplish is, that the datetime of the user posted information is registered with the Now() function in the query, BUT that the user entered information gets echo'd out with the Date showing ONLY. What I have is this: -Just as an example- INSERT INTO db (date_created) VALUES (now()) while ($row = mysqli_fetch_array($data)) { echo '<tr><td>' . $row['date_created'] . '</td></tr>'; } mysqli_close($dbc); With this way of course I get Date and Time showcased just like it's inserted into the DB. What would be a legit way of showcasing just date. Thanks for help. EDIT: or is there a better way than using now() to showcase the date when the user entered information was posted? Hi all, I have this problem with an echo I have this code, what is working only not all of it, it request a database (ID) TID which is a catorgy. Now I need to TID to be in a place but can't to seem to get it. Here is the code: Code: [Select] <?php defined('_JEXEC') or die('Restricted access'); // no direct access ?> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script> <script type="text/javascript"> /* function changeActiveCategory(id,show) { var a_categoryname = "a_category"+id; if(show){ document.getElementById(a_categoryname).className = "active"+id; }else{ document.getElementById(a_categoryname).className = ""; } } */ function changeActiveType(id,show) { var a_typename = "a_type"+id; if(show){ document.getElementById(a_typename).className = "active"+id; }else{ document.getElementById(a_typename).className = ""; } } var markerGroups = { "1": [], "2": [], "3": [], "4": [], "5": []}; function toggleGroup(type) { for (var i = 0; i < markerGroups[type].length; i++) { var marker = markerGroups[type][i]; if (marker.getVisible()) { marker.setVisible(false); changeActiveType(type,false); } else { marker.setVisible(true); changeActiveType(type,true); } } } function changeActiveButton(id) { document.getElementById("idmap").className = "map"; document.getElementById("idsatellite").className = "satellite"; document.getElementById("idterrain").className = "terrain"; var dividname = "id"+id; document.getElementById(dividname).className = id+" "+id+"active"; } var map; var goHome = new google.maps.LatLng(<?php echo $DefaultLat;?>, <?php echo $DefaultLng;?>); function HomeControl(controlDiv, map) { controlDiv.style.padding = '0px 5px'; var controlUI = document.createElement('DIV'); controlUI.style.cursor = 'pointer'; controlUI.setAttribute("class","mapType"); controlDiv.appendChild(controlUI); var controlMap = document.createElement('DIV'); if(map.getMapTypeId()=='roadmap'){ controlMap.setAttribute("class","map mapactive"); }else{ controlMap.setAttribute("class","map"); } controlMap.setAttribute("id","idmap"); controlUI.appendChild(controlMap); var controlsatellite = document.createElement('DIV'); if(map.getMapTypeId()=='satellite'){ controlsatellite.setAttribute("class","satellite satelliteactive"); }else{ controlsatellite.setAttribute("class","satellite"); } controlsatellite.setAttribute("id","idsatellite"); controlUI.appendChild(controlsatellite); var controlterrain = document.createElement('DIV'); if(map.getMapTypeId()=='hybrid'){ controlterrain.setAttribute("class","terrain terrainactive"); }else{ controlterrain.setAttribute("class","terrain"); } controlterrain.setAttribute("id","idterrain"); controlUI.appendChild(controlterrain); google.maps.event.addDomListener(controlUI, 'click', function() { /*map.setCenter(goHome);*/ }); google.maps.event.addDomListener(controlMap, 'click', function() { map.setMapTypeId(google.maps.MapTypeId.ROADMAP); changeActiveButton('map'); }); google.maps.event.addDomListener(controlsatellite, 'click', function() { map.setMapTypeId(google.maps.MapTypeId.SATELLITE); changeActiveButton('satellite'); }); google.maps.event.addDomListener(controlterrain, 'click', function() { map.setMapTypeId(google.maps.MapTypeId.HYBRID); changeActiveButton('terrain'); /*map.setMapTypeId(google.maps.MapTypeId.TERRAIN);*/ }); } function initialize() { var latlng = new google.maps.LatLng(<?php echo $DefaultLat;?>, <?php echo $DefaultLng;?>); var myOptions = { zoom: <?php echo $MapDistance;?>, center: latlng, navigationControl:true, scaleControl:true, mapTypeControl: false, mapTypeId: google.maps.MapTypeId.HYBRID }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var homeControlDiv = document.createElement('DIV'); var homeControl = new HomeControl(homeControlDiv, map); homeControlDiv.index = 1; map.controls[google.maps.ControlPosition.RIGHT].push(homeControlDiv); var gmarkers = []; var htmls = []; <?php echo 'var ptooltip=new Array();'; echo 'var showhtml=new Array();'; if($items) { $p=0; foreach ($items as $item) { $link = LinkHelper::getLink('properties','showproperty','',$item->CYslug,$item->Sslug,$item->Lslug,$item->Tslug,$item->Pslug); $item->name=str_replace("'","\'",$item->name); echo "\n"."ptooltip[".$p."]=new Array( '".$item->id."','".$item->ref."','".$item->tid."','".$item->name."','".$link."');"."\n"; /*property details*/ if($item->imagename!=NULL){ $img=$item->imagename;}else{$img='noimage.jpg';} $myHtml=''; $myHtml.='<div id="propertydetail"><div class="title"><a href="'. $link.'" title="'.str_replace('"',' ',$item->name).'">'.$item->name.'</a></div><div class="image"><img src="images/properties/images/thumbs/'.$item->id.'/'.$img.'" alt="'.str_replace('"',' ',$item->name).'" width="100" height="75"></div><div class="text">'; if ($item->name_type) { $myHtml.=JText::_($item->name_type).'<br />'; } if ($item->address) { $myHtml.=JText::_($item->address).'<br />'; } $myHtml.='</div>'; $myHtml.='<div class="property_button">'; $myHtml.='<a class="BottomlnkDetail" href="'.$link.'" title="'.$item->id.'">Lees meer...</a>'; $myHtml.='</div>'; $myHtml.='</div>'; echo "\n"."showhtml[".$p."]='".$myHtml."';"."\n"; $myHtml=''; /*end property details*/ $p++; } } ?> var base_Icon=new Array(); base_Icon = '<?php echo JURI::base();?>modules/mod_prop_googlemap/img/beer.png'; <?php if($items) { $x=0; foreach ($items as $item) { ?> var myLatlng = new google.maps.LatLng(<?php echo $item->lat;?>,<?php echo $item->lng;?>); var marker = new google.maps.Marker({ position: myLatlng, map: map, icon: base_Icon }); /*alert (marker.number);*/ marker.setTitle('Klik voor meer info.'); attachSecretMessage(marker, <?php echo $x;?>); markerGroups[HIER MOET TID KOMEN].push(marker); <?php $x++; } } ?> function attachSecretMessage(marker, number) { var infowindow = new google.maps.InfoWindow( { content: showhtml[number], /* disableAutoPan: true,*/ size: new google.maps.Size(50,50) }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); /*showInContentWindow(showhtml[number]);*/ }); google.maps.event.addListener(infowindow, 'closeclick', function() { /*infowindow.close(map,marker); showInContentWindow(''); closeInContentWindow();*/ }); /* google.maps.event.addDomListener(controlterrain, 'click', function() { map.setMapTypeId(google.maps.MapTypeId.HYBRID); changeActiveButton('terrain'); }); */ } function showInContentWindow(text) { var sidediv = document.getElementById('content_window'); sidediv.style.visibility = "visible"; sidediv.innerHTML = text; } function closeInContentWindow() { var sidediv = document.getElementById('content_window'); sidediv.style.visibility = "hidden"; } } </script> <div class="prop_googlemap" style="width:960px; height:510px"> <div class="first"> <div class="second"> <div class="third"> <div id="map_canvas" style="width: 950px; height: 500px"></div> <div id="prop_googlemap_categories_all"> <div id="prop_googlemap_categories"> <ul class="categorys"> <li><a id="a_type1" class="active1" href="javascript:void(0)" onclick="toggleGroup('1');">Kroeg</a></li> <li><a id="a_type2" class="active2" href="javascript:void(0)" onclick="toggleGroup('2');">Discotheek</a></li> <li><a id="a_type3" class="active3" href="javascript:void(0)" onclick="toggleGroup('3');">Zaal</a></li> <li><a id="a_type4" class="active4" href="javascript:void(0)" onclick="toggleGroup('4');">test</a></li> </ul> </div> <div style="clear:both"></div> <div class="prop_googlemap_categories_bottom"></div> </div> <div id="content_window"></div> <div id="side_bar"></div> </div> </div> </div> </div> <script type="text/javascript"> initialize(); </script> <div style="clear:both"></div> As you can see he Code: [Select] markerGroups[THIS IS WHERE THE TID SHOULD COME].push(marker);where now it says: "THIS IS WHERE THE TID SHOULD COME" there needs to be a number ( 1 stands for a bar, 2 stands for a disco, 3 for something else. Now this is where I ask for the TID: Code: [Select] echo "\n"."ptooltip[".$p."]=new Array( '".$item->id."','".$item->ref."','".$item->tid."','".$item->name."','".$link."');"."\n"; But it can be me, but can't seem to get it working.... Can't seem to get the right code for "THIS IS WHERE THE TID SHOULD COME" anyone that could help me? Thanks! Hello, I have this syntax on my header div Code: [Select] <p><a href="javascript:ajaxpage('shopcart.php', 'content');" class="difflink"><img src="../stock_photos/shopcart.png"><?php echo '<span class="text">'.writeShoppingCart().'</span>'; ?></a></p> but whatever I try it always output my echo in the next line instead of next to my picture file. How can I do it displayed at the same line? Thank you ok im building facebook app and im just back to php after months not touched it. this is the code: $image = $facebook->api_client->photos_get(null,null, echo $uid); print_r ($image); echo "<BR>"; echo $image[0]["src"]; the problem is that echo $uid i tried every variation and it does not work! i maybe forget something that i should have done? the $uid containing user id numbers so what i did wrong and if im not wrong i wanted the numbers($uid) Wrapped in quotation marks so i tried: echo ." $uid ". and alot of other please help tnx Hi, Im pretty new to php but im have trouble understanding why my script is doing this. Forgive me for silly mistakes! Im creating a login/register website and once the person has logged in they get a message saying "Successful login, welcome username!" The php checks against a database of users in an if statement to check if the password is correct and then prints out the message. But at the end of the message the echo is printing out a 1. I get that because the echo is in an if statement its return true or 1 but I cant get it to not print out the 1. code snippet is - if ($username==$dbusername&&$password==$dbpassword) { echo "Successful login, welcome!"; } Hope that makes sense. Thanks for the help. Neil Having problems with my script echo without form being completed yet. Any help would be appreciated. The echo that is outputting early is "You must enter a Session Name". Code: [Select] <html> <head> <title>ReH-0.1--Create a Session</title> </head> <body bgcolor="575757"> <center> <?php $error = "Could not connect to the database"; mysql_connect('localhost','root','') or die ($error); mysql_select_db('temp') or die ($error); //Set Variables $id = $_POST['id']; $table = $POST['table']; //Check for exsistence if (!$id or !$table) { echo "<font color='#ff0000'>You must enter a Session Name</font>"; } else { echo "Congrats!"; } ?> <h2 style="color:#fff">ReH-0.1 Password Encryption</h2><br><br> <font color="#fff">Before encrypting your password, a session must be started. We need you to enter a personal session name that you will remember so that you password is protected by this session.</font><br><br> <form action="session_start.php" method="POST"> <label for="id" style="color: #fff;">Session Name: <input type="text" maxlength="10" size="10" name="id"></label><br><br> <label for="table" style="color: #fff;">Session Name Confirmation: <input type="text" maxlength="10" size="10" name="table"></label><br><br> <input type="submit" value="Create Session"> </form> </center> </body> </html> I cannot retrieve my records from my table, neither can I display them on my website. I do not even get any errors when I run the script on my site. Any help or tips would be greatly appreciated. My current php script is: // connection to database server $db_selected = mysql_select_db('database1', $dbc); if (!$db_selected) { die ('Can\'t use database1 : ' . mysql_error()); } $query = "SELECT * FROM chesstable ORDER BY chapter, lastname"; $result = mysql_query($query) or die('Could not connect' . mysql_error()); echo mysql_num_rows($result); If (!$result) { $message = 'Invalid query: ' . mysql_error(); $message = 'Whole query: ' . $query; die ($message); } while($row = mysql_fetch_assoc($result)) { echo $row['firstname'] . " " . $row['lastname'] . $row['chapter']; } mysql_free_result($result); mysql_close($dbc); ?> Hi im having trouble getting the below code to listen to my css margin settings. Just to clear up the server side of things, can anybody tell me wether or not im using the correct syntax in the code below? Code: [Select] else { echo("<p class=\"passed\">Thankyou for submiting your details, you will be added to our directory shortly</p>"); }} Hi Guys, I keep getting the following error: Parse error: syntax error, unexpected T_ECHO in /Applications/XAMPP/xamppfiles/htdocs/pet/petCatalog1.php on line 51 I have copied the code from a tutorial and cannot for the life of me work out what the problem is with line 51???? I have attached the file and pasted the code below. The real problem line is: echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n" The full code is attached - btw, inserting the ">" does not help to fix it!! <?php /* Programme: PetCatalog.php * Desc: Lists all pet categories with radio buttons */ ?> <html> <head> <title>Select a Pet Category</title> </head> <body> <?php /* Database login info - Move to an Include */ $host="localhost"; $user="root"; $passwd=""; $dbname="information_schema"; /* Establishes a connection with the databse */ $cxn = mysqli_connect ($host, $user, $passwd, $dbname) or die ("Could not connect to the database JAMIE!"); /* SQL Query to select all categories of pet from the petType column in the pet table */ $query = "SELECT * FROM PetCatalog.petType ORDER BY petType"; $result = mysqli_query($cxn,$query) or die ("Unable to connect to the database JAMIE"); /* Echo of H1 & H2 above the pet table */ echo "<div style='margin-left: .lin'>\n <h1 style='text-align: center'>Pet Catalogue</h1>\n <h2 style='text-align: center'>The following categories of pets are now available</h2>\n"; /* Create form to diplay pet categories */ echo "<form action='ShowPets.php' method='POST'>\n"; echo "<table cellpadding='5' border='1'>"; $counter=1; while ($row = mysqli_fetch_assoc($result)) { extract ($row) echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n" echo "<input type='radio' name='interest' value='$petType'\n"; if( $counter == 1 ) { echo "checked='checked'"; } echo ">$petType</td>"; echo "<td>$typeDescription</td></tr>"; $counter++; } echo "</table>"; echo "<p>input type='submit' value='Select Pet Type'> </form></p>\n"; ?> </body> </html> OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> the line : echo $form['catcher_id'] gives me a dropdown list when i choose another item from the dropdown i want to do a few things but my code not working: $selected_catcher = $form['catcher_id']; foreach($selected_catcher as $val) { $catcher_name = $val->getName(); echo $catcher_name." ".$val->getId(); if ($catcher_name = "zed-catcher") { echo $form['service_code']->renderLabel(); echo $form['service_code']->renderError(); echo $form['service_code']; } } please help? thanks Hey guys for some reason this code is not working i can't see a problem myself could someone please have a look and point the issue out to me. what i mean by it not working is it won't insert into the database or show a mysql_error. thanks in advance Code: [Select] $guestip = $_SERVER['REMOTE_ADDR']; $time = date('G:i'); $date = date("y-m-d"); $query = mysql_query("SELECT * FROM IP_Address") or die(mysql_error()); while($row = mysql_fetch_assoc($query)){ if($guestip != $row['ip']){ //insert into db. mysql_query("INSERT INTO IP_Address(id, ip, date, time) VALUES(NULL,'$questip','$date','$time')") or die(mysql_error()); echo "inserted in to database"; echo mysql_error(); }else{ // add hit count and update time and date. echo "already in db"; } } I have search the net and at the end tried 2 things that didn't solved the problem. It is known that certain browsers can refresh th epage 2 times without us knowing bacause it's doing it all by himself and so fast we don't even see it blink ! So I have following code for the normal sql-insert : Code: [Select] $Opdracht = "INSERT INTO tbl_link(userid,linkcat,linksubid,linklang,linkactive,linktitle) VALUES('$userid',1,0,'$lang',1,'$newML')"; it was inserted 2 times... I did some session check : at the top of the page : Code: [Select] session_start(); if(isset($_SESSION['itel'])){ $_SESSION['itel'] = $_SESSION['itel']+ 1; } else { $_SESSION['itel'] = 1; } echo "<br>session: ". $_SESSION['itel']; And it gave me number 2 ! This means the page was loaded 2 times, thus inserted 2 times. ! Than I tried : Code: [Select] $Opdracht = "INSERT INTO tbl_link(userid,linkcat,linksubid,linklang,linkactive,linktitle) VALUES('$userid',1,0,'$lang',1,'$newML') ON DUPLICATE KEY UPDATE linkid=LAST_INSERT_ID(linkid), linktitle='$linktitle'"; I got no error back but again 2 rows were created instead of 1... These are the fields in the table tbl_link : linkid userid linkcat linksubid linksuborder linklang linkactive linktitle articleid Unfortunately certain fields may be double in multiple rows, the only unique key is "linkid" and that's AUTO_INCREMENT. The only thing I can use is that userid and linktitle may NOT be reproduced 2 times (inserted) !!! I have an old site written for PHP 5.4 and under and trying (very trying) to get it to work with PHP 7x without much luck. Due to all the changes in 7 my code is one big error message, but one thing at a time. I cannot get the follow code to work at all, even though it worked in PHP 5. Error:
QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'viewuser.php?u=666' id='member'>THE PREDATOR [666] was added to the hit' at line 1 I have tried at least 20+ different ways of doing this but just can't get the right syntax to get it inserted into MySQL, the code below is just the latest version. If I echo the a href line out, it works perfect. I am sure it is something ridiculously simple, but I have been 4 hours and counting on this now. Thanks gangevent_add_2($gangdata['gangID'], "<a href='viewuser.php?u=".$r['userid']."' ".$csscode[$r['userlevel']-1].">".$r['username']."</a> [".$r['userid']."] was added to your hitlist"); function gangevent_add_2($gang, $text) { global $db; $csscode; $db->query("UPDATE users SET gangevent = gangevent + 1 WHERE gang={$gang}"); $db->query("INSERT INTO gangevents VALUES('','$gang', UNIX_TIMESTAMP(),'$text')"); }
hi, i was having difficulty and i'm quite confused how to insert these values to the database before it will become as it is, based on this article: http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html what i did was putting/saving the values directly in the database (mysql). but now i want those values to be coming from the user's input:the country,state and city so the system will just get those values, store it to the database with the fields of each table having the same content like that from article above..i really need some help here.. Hi My problem is that I can't insert my information into my database. I was able to insert the information into my database last night but when I tried to use validation it's not working any more. Here is my code for the sign up Code: [Select] <?php require_once("validation.php"); ?> <!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" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>yensdesign.com - Validate Forms using PHP and jQuery</title> <link rel="stylesheet" href="css/general.css" type="text/css" media="screen" /> </head> <body> <a id="logo" title="Go to yensdesign.com!" href="http://www.yensdesign.com"><img src="css/images/logo.jpg" alt="yensdesign.com" /></a> <div id="container"> <h1>Registration process</h1> <?if( isset($_POST['send']) && (!validateName($_POST['name']) || !validateEmail($_POST['email']) || !validatePasswords($_POST['pass1'], $_POST['pass2']) || !validateMessage($_POST['message']) ) ):?> <div id="error"> <ul> <?if(!validateName($_POST['name'])):?> <li><strong>Invalid Name:</strong> We want names with more than 3 letters!</li> <?endif?> <?if(!validateEmail($_POST['email'])):?> <li><strong>Invalid E-mail:</strong> Stop cowboy! Type a valid e-mail please :P</li> <?endif?> <?if(!validatePasswords($_POST['pass1'], $_POST['pass2'])):?> <li><strong>Passwords are invalid:</strong> Passwords doesn't match or are invalid!</li> <?endif?> <?if(!validateMessage($_POST['message'])):?> <li><strong>Ivalid message:</strong> Type a message with at least with 10 letters</li> <?endif?> </ul> </div> <?elseif(isset($_POST['send'])):?> <div id="error" class="valid"> <ul> <li><strong>Congratulations!</strong> All fields are OK ;)</li> </ul> </div> <?endif?> <form method="post" id="customForm" action="index.php"> <div> Name <input id="name" name="name" type="text" /> <!--<span id="nameInfo">What's your name?</span>--> </div> <div> <input id="email" name="email" type="text" /> <!--<span id="emailInfo">Valid E-mail please, you will need it to log in!</span>--> </div> <div> Password <input id="pass1" name="password" type="password" /> <span id="pass1Info">At least 5 characters: letters, numbers and '_'</span> </div> <div> Confirm Password <input id="pass2" name="pass2" type="password" /> <span id="pass2Info">Confirm password</span> </div> <!--<div> <label for="message">Message</label> <textarea id="message" name="message" cols="" rows=""></textarea> </div>--> <div> <input id="send" type="submit" value="Send" /> </div> </form> </div> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="validation.js"></script> </body> </html> <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="emails"; // 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 values from form $name=$_POST['name']; $email=$_POST['email']; $password=$_POST['password']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, email, password)VALUES('$name', '$email', 'password')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='insert.php'>Back to main page</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> This is the validation.php Code: [Select] <?php function validateName($name){ //if it's NOT valid if(strlen($name) < 4) return false; //if it's valid else return true; } function validateEmail($email){ return ereg("^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$", $email); } function validatePasswords($pass1, $pass2) { //if DOESN'T MATCH if(strpos($pass1, ' ') !== false) return false; //if are valid return $pass1 == $pass2 && strlen($pass1) > 5; } function validateMessage($message){ //if it's NOT valid if(strlen($message) < 10) return false; //if it's valid else return true; } ?> And this is the validation.js Code: [Select] /***************************/ //@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro //@website: www.yensdesign.com //@email: yensamg@gmail.com //@license: Feel free to use it, but keep this credits please! /***************************/ $(document).ready(function(){ //global vars var form = $("#customForm"); var name = $("#name"); var nameInfo = $("#nameInfo"); var email = $("#email"); var emailInfo = $("#emailInfo"); var pass1 = $("#pass1"); var pass1Info = $("#pass1Info"); var pass2 = $("#pass2"); var pass2Info = $("#pass2Info"); var message = $("#message"); //On blur name.blur(validateName); email.blur(validateEmail); pass1.blur(validatePass1); pass2.blur(validatePass2); //On key press name.keyup(validateName); pass1.keyup(validatePass1); pass2.keyup(validatePass2); message.keyup(validateMessage); //On Submitting form.submit(function(){ if(validateName() & validateEmail() & validatePass1() & validatePass2() & validateMessage()) return true else return false; }); //validation functions function validateEmail(){ //testing regular expression var a = $("#email").val(); var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/; //if it's valid email if(filter.test(a)){ email.removeClass("error"); emailInfo.text("Valid E-mail please, you will need it to log in!"); emailInfo.removeClass("error"); return true; } //if it's NOT valid else{ email.addClass("error"); emailInfo.text("Stop cowboy! Type a valid e-mail please :P"); emailInfo.addClass("error"); return false; } } function validateName(){ //if it's NOT valid if(name.val().length < 4){ name.addClass("error"); nameInfo.text("We want names with more than 3 letters!"); nameInfo.addClass("error"); return false; } //if it's valid else{ name.removeClass("error"); nameInfo.text("What's your name?"); nameInfo.removeClass("error"); return true; } } function validatePass1(){ var a = $("#password1"); var b = $("#password2"); //it's NOT valid if(pass1.val().length <5){ pass1.addClass("error"); pass1Info.text("Ey! Remember: At least 5 characters: letters, numbers and '_'"); pass1Info.addClass("error"); return false; } //it's valid else{ pass1.removeClass("error"); pass1Info.text("At least 5 characters: letters, numbers and '_'"); pass1Info.removeClass("error"); validatePass2(); return true; } } function validatePass2(){ var a = $("#password1"); var b = $("#password2"); //are NOT valid if( pass1.val() != pass2.val() ){ pass2.addClass("error"); pass2Info.text("Passwords doesn't match!"); pass2Info.addClass("error"); return false; } //are valid else{ pass2.removeClass("error"); pass2Info.text("Confirm password"); pass2Info.removeClass("error"); return true; } } function validateMessage(){ //it's NOT valid if(message.val().length < 10){ message.addClass("error"); return false; } //it's valid else{ message.removeClass("error"); return true; } } }); I also get that the name, email and password is undefined |