PHP - Sql Error On Multi-page Order Script (using Session).
SET UP: Windows vista
# XAMPP 1.7.3, # Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l # MySQL 5.1.41 + PBXT engine # PHP 5.3.1 # phpMyAdmin So I'm getting this error message: 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 '", )' at line 8. I can't see where the '", )' code is in that script. I've looked and contrl + find it but no joy. I've looked through the previous pages and mysql database to ensure the variables and the tables match up. Any help would be appreciated. Maybe some good mysql debug advice. Is there a good debug open source program out there? Any help would be appreciated. <?php //let's start our session, so we have access to stored data session_start(); include 'db.inc.php'; $db = mysql_connect('localhost', 'root', '') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('ourgallery', $db) or die(mysql_error($db)); //let's create the query $query = sprintf("INSERT INTO subscriptions ( name, email_address, membership_type, terms_and_conditions, name_on_card, credit_card_number, credit_card_expiration_data) VALUES ('%s','%s','%s','%s','%s','%s','%s')", $_SESSION['email_address'], $_SESSION['membership_type'], $_SESSION['terms_and_conditions'], $_POST['name_on_card'], $_POST['credit_card_number'], $_POST['credit_card_expiration_data']); //let's run the query mysql_query($insert_query); ?> Similar TutorialsI'd describe myself as a "basic" php programmer....
I'm trying to build my first multi-page forms.
The first page is calculator_q1.php
No session variables are needed here, I have omitted a few options, the code looks like this
<form id="page1" method="post" action="calculator_q2.php"> <h1>1. Which best describes the primary and secondary sports combination that will be played on your pitch?</h1> <table> <tr><td>Rugby only</td><td><input type="radio" name="1_primary_secondary_combo" value="Rugby only"></td></tr> <tr><td>Rugby/Soccer</td><td><input type="radio" name="1_primary_secondary_combo" value="Rugby Soccer"></td></tr> <tr><td>Soccer/Hockey</td><td><input type="radio" name="1_primary_secondary_combo" value="Soccer Hockey"></td></tr> </table> <input class="blue" type="submit" value="Next"> </form>The 2nd page is calculator_q2.php. This has some php to start the session, copy the result of form 1 to a session var, I do a debug echo and the variable is printed correctly so I think have captured it correctly. In extract, I do this: <?php //Start the session session_start(); //Store our posted values in the session variables $_SESSION['1_primary_secondary_combo'] = $_POST['1_primary_secondary_combo']; ?> <?php $debug=True; if ($debug) { echo ("Debug: session for q1 = ".$_SESSION['1_primary_secondary_combo']); } ?> <form id="page2" method="post" action="calculator_q3.php"> <h1>2. Please choose a preferred surface</h1> <table> <tr><td>3G Rubber Crumb Filled Turf</td><td><input type="radio" name="2_preferred_surface" value="3G Rubber Crumb Filled Turf "></td></tr> <tr><td>Sand Filled Turf</td><td><input type="radio" name="2_preferred_surface" value="Sand Filled Turf"></td></tr> <tr><td>Sand Dressed Turf or<br>a Water Based Surface</td><td><input type="radio" name="2_preferred_surface" value="Sand Dressed Turf or a Water Based Surface"></td></tr> </table> <p> <script> function submitForm(action){ document.getElementById('page2').action = action; document.getElementById('page2').submit(); } </script> <input class="blue" type="button" onclick="submitForm('/calculator_q1.php')" value="Previous" /> <input class="blue" type="button" onclick="submitForm('/calculator_q3.php')" value="Next" /> </form>So far so good, but when I introduce page 3 (calculator_q3.php) then it prints the previous page's (from page 2) variable but can't find the session variable from question 1. This is from calculator_q3.php: <?php //Start the session session_start(); //Store our posted values in the session variables $_SESSION['2_preferred_surface'] = $_POST['2_preferred_surface']; ?> <?php $debug=True; if ($debug) { echo ("Debug: session for q1 = ".$_SESSION['1_primary_secondary_combo']); echo ("<br>Debug: session for q2 = ".$_SESSION['2_preferred_surface']); } ?> <form id="page3" method="post" action="calculator_q4.php"> <h1>3. Please choose one watering option</h1> <table> <tr><td>With a Rain Gun System</td><td><input type="radio" name="3_watering_option" value="With a Rain Gun System"></td></tr> <tr><td>With a Rain gun System + Water Borehole</td><td><input type="radio" name="3_watering_option" value="With a Rain gun System + Water Borehole"></td></tr> <tr><td>Not Required</td><td><input type="radio" name="3_watering_option" value="Not Required"></td></tr> </table> <p> <script> function submitForm(action){ document.getElementById('page3').action = action; document.getElementById('page3').submit(); } </script> <input class="blue" type="button" onclick="submitForm('/calculator_q2.php')" value="Previous" /> <input class="blue" type="button" onclick="submitForm('/calculator_q4.php')" value="Next" /> </form>To see this in action see: http://www.sports.ha...lculator_q1.php Any insights would be appreciated. Many thanks. Hi,
In reference to my first attached image, I have a form which displays two SELECT/drop-down fields (labeled "Store Name" and "Item Description".....and both of which pull-in values from two separate lookup/master tables, in addition to providing an additional option each for "NEW STORE" and "NEW ITEM").
Now, when first-run, and/or if "NEW STORE" and "NEW ITEM" are not selected from the drop-down's then the two fields in green ("New Store Name" and "New Item Name" are hidden, by means of the following code:
<div class="new-store-container" id="new-store-container" name="new-store-container" style="display:none;"> <div class="control-group"> <div class="other-store" id="new_store_name"> <?php echo standardInputField('New Store Name', 'new_store_name', '', $errors); ?> </div> </div> </div>Conversely, if "NEW STORE" and/or "NEW ITEM" are selected from the two drop-down's then one (or both) of the "New Name" fields are unhidden by means of the following two pieces of code, one PHP and the second JS: <select class="store-name" name="store_id" id="store_id" onclick="toggle_visibility('store_id','new-store-container')"> <?php echo $store_options; ?> <?php if($values['store_id'] == "OTH") { echo "<option value='OTH' selected> <<<--- NEW STORE --->>> </option>"; } else { echo '<OPTION VALUE="OTH"> <<<--- NEW STORE --->>> </OPTION>'; } ?> </select> function toggle_visibility(fieldName, containerName) { var e = document.getElementById(fieldName); var g = document.getElementById(containerName); if (e.value == 'OTH') { if(g.style.display == 'none') g.style.display = 'block'; else g.style.display = 'none'; } }All of that is working just fine. The problem I'm having is that when I click the "Create" button, after having left any one of the form fields blank, the two "New Name" fields are hidden again, which I don't want to happen i.e. I want them to remain visible (since the values of "store_id" and/or "item_id" are "OTH"), so that the user can enter values into one or both of them, without havng to click on the drop-down a second time in order to execute the "on-click" code. The second attached image shows how the fields are hidden, after clicking "Create". How can I achieve that? It would be greate if someone could cobble-up the required code and provide it to me, since I'm relatively new to this. Thanks much. Snap1.png 26.14KB 0 downloads Snap2.png 149.47KB 0 downloads I have 2 scripts that take a while to process... The first takes a few minutes, the second takes over an hour... The first script completed successfully, but the second script seems like it just stops most of the way through the script... I have this set on both files: set_time_limit(0); ini_set('memory_limit', -1); I NEED to disable ALL time limits and all of that, does ANYONE have any clue as to why my second script is failing? It is NOT the programming, I know that for sure... But the script just stops executing, and I think it is because it times out... But after setting those 2 options, I don't see why it times out.. Also for reference, I am NOT using any database... I am simply downloading files from an FTP server to my server... Any help would be appreciated, I have been searching for the last few days on an answer. Rob I am trying to make a database application. I encounterd a problem that. suppose multiple users tryto access data it may cause problem. to clearly understand please see the attachment. How can I resolve it?
hey guys im trying to make a file upload script so that when the user uploads a pic it gets shown in a div...when you add another it is the added by the side of the 1st pic...but some reason when selecting a image nothing shows...
what am i doing wrong?
here is my code below if anyone can tell me what it is wrong im doing...thank you
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script> $( document ).ready(function() { var files = $('.input-file').prop("files"); var file_count = files.length; var names = $.map(files, function(val) { return val.name; }); $('#input-file-button').click(function() { $('.input-file').click(); }); $('.input-file').change(function (){ var file_name = $(this).val(); var file_path = URL.createObjectURL(event.target.files[0]); $('#uploaded-images').append('<div><img src="'+ file_path +'" /></div>' + file_name); }); if (file_count < 1) { $('#uploaded-images').text("No images are selected."); } }); </script> <style> .input-file { display: none; } </style> </head> <body> <div id="uploaded-images"></div> <br /> <input type="file" name="files[]" class="input-file"/><span id='input-file-button'>Upload Photo</span> </body> </html> Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? Hi to all !
I would like to ask that :-
1. what is the best way to / or how to best test a multi-user login script.
2. The best way to test a multi user website that saves data from the users into a database.
Are there any tools that can hep me in testing my work locally on a localhost before I move them out to a website. ?
I have heard that testing routines can be written for such purposes to automate the testing. If so where should I begin to look for them? I have no idea at all about writing test routines / scripts. A tutorial , if any exists, would be a good place to start.
Thanks very much.
So let's assume i'm making a script for searching cars by different criteria. Name of the car, color, and mileage. I used to do this by using LIKE and just adding AND for as many times as needed. But i've read that that is obsolete and is giving servers a hard time, so i went ahead and started making a new script that will use fulltext search. I've hit a dead end. Code: [Select] function search($table,$what,$string,$limit,$start,$country) { global $totrows; global $pages; $string = explode("*",$string); $what = explode("*",$what); $cname = trim($string[0]); $t = 0; $parameters = ""; while (isset($what[$t])){ if ($t>0) { $paramm .= ", "; } $paramm .= trim($what[$t]); if ($t>0) { $parama .= " "; } $parama .= trim($string[$t]); $t++; } $parameters .= " AND locationc = '".$country."'"; $sql = "SELECT *, MATCH(".$paramm.") AGAINST('".$parama."') AS score FROM main WHERE MATCH(".$paramm.") AGAINST('".$parama."') ORDER BY score DESC"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { var_dump($row); } } How does this work: The user selects and enters his parameters> The script then joins them all into a single variable which is then sent to the function(the reason i do this i because the user might input only the name, so that way i can add more criteria and not need to change the script)> The script explodes those into arrays and then it processes them into a form for use with sql> I run the sql query and then return the results. What's the problem? There's two of them actually> The first one is that mysql returns an error "Can't find FULLTEXT index matching the column list" even though i did setup fulltext indexes. (phpmyadmin c/p) Code: [Select] name FULLTEXT No No name 0 YES color FULLTEXT No No color 0 YES mileage FULLTEXT No No mileage 0 YES The second problem is that the script is not selective and will not work as intended. For example, a car's name is 300, the users input's 300, and the script will return those rows that had mileage 300 or 300000 or whatever. How do i fix this, and is FULLTEXT the right way to go with multi criteria search? I'm just starting to learn PHP and I'm working on something that involves two files, one HTML and another PHP. The HTML file basically accesses the PHP file anyway though, to avoid repetition in the HTML code...the actual HTML form is hardcoded within the PHP file itself. The user will be able to enter the quantity of items they want, and either add them to their shopping cart (display their order back to them on the same page as the order form) or submit the order (display their order back to them without the order form visible). I already have the shopping cart portion done, so I'm really only having problems with two things: 1) If they place their order, how do I redisplay the information without the HTML order form visible and 2) If they already have an order in their shopping cart and they place their order, how do I carry over all the information in the cart to redisplay it (my variables all seem to reset after they add to their cart and display so I can't use the same function I used to retrieve it all in the first place)? Thanks in advance...I've been trying to figure this out for over an hour now and I just need a push in the right direction If you need anything else clarified let me know, I'll be lurking... Hello
I write following code to get Multiple page of the this site: www.mobile.ir
This website have mobile price category .. this category have 42 navigation page.
I write following code with curl_multi_init and xpath to get data from Multiple page from category.
$ch1= curl_init ("http://www.mobile.ir...es/prices.aspx"); $ch2 = curl_init ("http://www.mobile.ir...hopid=0&page=2"); curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch1,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); curl_setopt($ch1, CURLOPT_HEADER, 0); curl_setopt($ch1, CURLOPT_ENCODING, 'UTF-8'); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch2,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); curl_setopt($ch2, CURLOPT_HEADER, 0); curl_setopt($ch2, CURLOPT_ENCODING, 'UTF-8'); $mh = curl_multi_init(); //add the two handles curl_multi_add_handle($mh,$ch1); curl_multi_add_handle($mh,$ch2); $active = null; //execute the handles do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) { if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } $dom = new DOMDocument('1.0', 'utf-8'); libxml_use_internal_errors(true); $dom->loadHTML($mrc); libxml_clear_errors(); $xpath = new DOMXpath($dom); $data = array(); $table_rows = $xpath->query('//table[@id="price_table"]/tbody/tr'); // target the row (the browser rendered <tbody>, but actually it really doesnt have one) if($table_rows->length <= 0) { // exit if not found echo 'no table rows found'; exit; } $s = "st\xECna"; foreach($table_rows as $tr) { // foreach row $row = $tr->childNodes; if($row->item(0)->tagName != '<tr class="carHeader"> <td>نام کارخانه </td> <td>نام خودرو </td> <td>قیمت نمایندگی (ریال) </td> <td>قیمت بازار (ریال) </td> </tr>') { // avoid headers $data[] = array( 'Name' => trim($row->item(2)->nodeValue), 'Price' => trim($row->item(4)->nodeValue), ); } } echo '<pre>'; print_r($data); But don't display data ... when I use curl_init() to get data from one page without problem working and displaying data (name and price) but when use curl_multi_init dont display I really need.. So far with my inbox I got it to grab the message and display them in order by most recently sent. but now I want to add multiple inbox pages and set a limit on how many messages are on each page. I cant think of the idea behind of doing it. If someone could kindly guide me please. I know i need to use tokens in the link for each page but i dont understand the concept behind having newest messages to oldest showing up on each page Code: [Select] <?php $take3 = "SELECT time_offset FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; $take2 = mysql_query($take3) or die(mysql_error()); $take1 = mysql_fetch_array($take2); $result = mysql_query("SELECT * FROM pm WHERE id = '".($_SESSION['user_id'])."' ORDER BY time DESC"); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { $pm_id = $row['pm_id']; $msggoauld = $row['sentfrom']; $subject = $row['subject']; $recieved = $row['time']; $time = ($recieved + $take1['time_offset']); date_default_timezone_set('UTC'); $offset = date('m/d/Y/H:i:s', $time); ?> <tr> <td><center><input type="checkbox" name="messageid" class="select-all-box" value="327990" ?></center></td> </label></td> <td><center><a href="search_goaulds.php?goauld=<?php echo $msggoauld; ?>"><?php echo $msggoauld ?></a></center></td> <td><center><a href="view.php?pm_id=<?php echo $pm_id; ?>"><?php echo $subject ?></a></center></td> <td><center><?php echo $offset ?></center></td> </tr> <?php } // while loop ?> </table> <p> </p> </center> </p> </form> ONE of my SESSION values isn't remaining after login while others do. This works fine on my localhost, it's on the live site that there is a problem and it just started yesterday. Before that it worked great. Out of the four SESSIONs made I can only echo three values on other pages, member id the most important doesn't transfered to other pages Notes: all these files are in the same folder, there is a SESSION started for the member id on the login page, you can see that it is used in the redirect below and the redirect works fine with the redirect going to the correct page " $home/member/index.php?user=$id_mem " Here is the login page // Here's the basic login page info <?php # login.php session_start(); ob_start() ...connect to db & header called... ...Form validation..... if ($e && $p) { // If everything's OK. // Query the database: $q = "SELECT id_mem, display_name, mem_group FROM sn_members WHERE (email='$e' AND password=SHA1('$p')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); // or die("Error: ".mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { // If a match was made. // Register the values & redirect: // Give SELECTED elements a session $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); mysqli_free_result($r); // Update db for last login $id_mem = $_SESSION['id_mem']; // <<< SESSION member id has a value here because it's used in the redirect below $ip = $_SERVER['REMOTE_ADDR']; // Get ip address of person logging in $q = "UPDATE sn_members SET last_login = Now(), ip = '$ip' WHERE id_mem = '$id_mem' LIMIT 1"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); header("Location: $home/member/index.php?user=$id_mem"); exit(); // Quit the script. } ?> Here is the main page that a user would be redirect to above <?php // /member/ all member info is through this folder session_start(); ob_start(); if (isset($_GET['user']) && is_numeric($_GET['user'])) { $user = $_GET['user']; $user = $user; if ($user < 0) { header("Location: $home/index.php"); exit(); } } if ((!isset($_SESSION['id_mem'])) && (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])))){ // If not a logged in member redirect header("Location: $home/index.php"); exit(); // Quit the script. } ?> Thanks in advance for the help SJ Hallo my problems is something with the session in my script as it redirects even when i logged in can someone help out please.. the code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> </title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="post"> Username:<input type="text" name="username" /> Password:<input type="password" name="password" /> <input type="submit" name="submit" value="submit" /> </form> <?php $host = '---'; $user = '---'; $pass = '---'; $db = '---'; $connect = mysql_connect($host, $user, $pass) or die ('Could not connect'); $database = mysql_select_db($db) or die ('Could not connect'); $username = $_POST['username']; $password = $_POST['password']; $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql= " SELECT * FROM Users WHERE username= '".$username."' AND password = '".$password."' "; $result = mysql_query($sql); if(mysql_num_rows($result) == 1){ $_SESSION['username'] = $username; $_SESSION['password'] = $password; header("location: login_succes.php"); } ?> </body> </html> code login_succes.php <?php session_start(); if(!isset($_SESSION['username'])){ header('location: login.php'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> </title> <link rel="stylesheet" href="stylesheet.css" type="text/css" /> </head> <body> login succesfull </body> </html> hey, i have this code: Code: [Select] <?php //-------------------------------- // Starting our session //-------------------------------- session_start(); //-------------------------------- // load database connection //-------------------------------- require "connect.php"; //-------------------------------- // Make some checks if the admin // Are loged in //-------------------------------- if ( ! isset($_SESSION['admin']) || ! isset($_SESSION['name']) ) { require "login.php"; die(); } if ( $_SESSION['admin'] != 1 || $_SESSION['name'] == "" ) { require "login.php"; die(); } if ( $core->input['act'] == logout ) { unset($_SESSION['admin']); unset($_SESSION['name']); session_destroy(); header('Location: index.php'); } ?> im trying to set a simple session, but i getting this error: Quote Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php:1) in /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php on line 7 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php:1) in /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php on line 7 but as you can see i put the session start in the top of the file... any ideas? Thanks! Hi, i've got a strange problem: i get this errors: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at e:\Internet\pmtopagents\test.php:1) in e:\Internet\pmtopagents\test.php on line 3 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at e:\Internet\pmtopagents\test.php:1) in e:\Internet\pmtopagents\test.php on line 3 but in my test.php is nothing else than: <?php session_start(); ?> there is no space in front of <?php where could be the error? best hi all, I have a form that pass some $_POST values to a page that sets a session like this: session_start(); $_SESSION['TESTE'] = array ($_POST['sexo'],$_POST['nome'],$_POST['senha'],$_POST['senha2'],$_POST['login']); header ("Location: dddl.php"); Then the dddl.php should print the values on this line: print_r ($_SESSION['TESTE']) ; But when i run the application the dddl.php page returns this error: Notice: Undefined variable: _SESSION in C:\Users\Danilo\wamp\www\CNTur\dddl.php on line 2 Why it's not setting or why can't I reach the values? When I run the following code on the same page the session values are returned correctly: session_start(); $_SESSION['TESTE'] = array ($_POST['sexo'],$_POST['nome'],$_POST['senha'],$_POST['senha2'],$_POST['login']); print_r ($_SESSION['TESTE']) ; Thankx Danilo Jr. It is my understanding that <?php session_start (); ?> must go on the very first line otherwise "it won't work." But mine still isn't working, and I'm not sure why. These errors were returned EVEN AFTER I deleted everything in index.php except <? session_start (); ?>.... Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/xxx/public_html/xxx/xxx/index.php:1) in /home/xxx/public_html/xxx/xxx/index.php on line 1 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/xxx/public_html/xxx/xxx/index.php:1) in /home/xxx/public_html/xxx/xxx/index.php on line 1 SO I have been developing a log in system and wanted to make my own simple CAPTCHA. I found one on the internet and ported the code across to get started and see how someone had made it. The issue I am having is that the dynamically generated image that I have created it seems is one step ahead of the session variable (the string is generated and then saved into session - then generates the image). But when i echo back the session it is always one step behind the actual image... Anyway here is my code and ask away please
<?php require('includes/util.inc.php'); $form = ' <form action="register.php" method="post"> <p>username <input type="text" name="username" id="usrinp"></p> <p>email <input type="text" name="email" id="emainp"></p> <p>password <input type="password" name="password1" id="psw1inp"></p> <p>re-enter password <input type="password" name="password2" id="psw2inp"></p> <p><img src="captcha.php"/></p> <p>captcha <input type="text" name="captcha" id="capinp"></p> <p><input type="submit" value="Register" id="subinp"></p> </form> '; if(isset($_SESSION['captcha'])) { echo $_SESSION['captcha']; } if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['username']) && !empty($_POST['email'])) { if($_POST['captcha'] == $_SESSION['captcha']) { $username = $_POST['username']; $email = $_POST['email']; $password = SHA1($_POST['password1']); $password = SHA1($_POST['password2']); $q = 'SELECT username FROM users WHERE username = :username'; $stmt = $pdo->prepare($q); $stmt->bindParam(':username', $username); $stmt->execute(); if($stmt->rowCount() > 0) { echo "<pre>This username has already been taken</pre>"; } else { $qi = 'INSERT INTO users ( username, password, email ) VALUES ( :username, SHA1(:password), :email )'; $query = $pdo->prepare($qi); $result = $query->execute( array( ':username'=>$username, ':password'=>$password, ':email'=>$email ) ); if($result) { header("location:login.php"); exit; } else { echo '<pre>Error, please try again</pre>'; } } } } $pageTitle = 'Register'; include('includes/header.inc.php'); include('pages/register.html'); ?> <?php require('includes/util.inc.php'); $string = ''; for ($i = 0; $i < 5; $i++) { $string .= chr(rand(97, 122)); } $_SESSION['captcha'] = $string; $font_path = 'includes/fonts/'; $captcha_image = imagecreatetruecolor(150, 60); $text_color = imagecolorallocate($captcha_image, 0, 0, 0); $bg_color = imagecolorallocate($captcha_image, 255, 255, 255); imagefilledrectangle($captcha_image, 0, 0, 399, 99, $bg_color); imagettftext($captcha_image, 30, 0, 10, 40, $text_color, $font_path . "dashdot.ttf", $_SESSION['captcha']); header("Content-type: image/png"); imagepng($captcha_image); ?> <?php session_start(); function class_loader($class) { require 'classes/' . $class . '.class' . '.php'; } spl_autoload_register('class_loader'); $user = (isset($_SESSION['user'])) ? $_SESSION['user'] : null; $cat = (isset($_SESSION['cat'])) ? $_SESSION['cat'] : null; try { $pdo = new PDO('mysql:dbname=phpcat; host=localhost', 'root', ''); } catch (PDOException $e) { $pageTitle = 'Error!'; include('header.inc.php'); include('../pages/error.html'); exit(); } I don't know how to solve this error;
Parse error: syntax error, unexpected '$db' (T_VARIABLE)
code:
|