Jump to content

Nexx

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Nexx's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I have a weird problem, and I think it has something to do with my array. [code] <?php $arrError=array(); if (isset($_POST['hidden'])==1){ if ($_POST['first_name']==''){         $arrError['first_name'] = 'First Name: Everyone has a first name!'; }else{$first_name=$_POST['first_name'];}               //many other $_POST here, following the same format as the others. if ($_POST['email']==''){         $arrError['email'] = 'Email: Email address must be in the name@domain.com format.'; }else{$email=$_POST['email'];} if (count($arrError) == 0) { //database stuff here. }else{$strError = '<br /><div align=\"left\"><p class=\"error\">Please correct the following errors:</p>'; foreach ($arrError as $strError) {                     $strError .= '<li>$strError</li>';         } $strError .= '</div>'; } } echo $strError; ?> [/code] When I hit the submit button, and a field fails to validate, it doesnt echo what I think should be in $strError. Instead it echos this:   Email: Email address must be in the name@domain.com format. •Email: Email address must be in the name@domain.com format. • = bullet Now if I enter an email address, it will do the same thing but with the previous failed field. -------------------------------------------- Edit: I figured it out, [code]<?php foreach ($arrError as $error) {   $strError .= '<li>$error</li>';   }   $strError .= '</div>'; }?>[/code] Ooops
  2. [code] <?php include("login.inc.php"); mysql_connect($hostname,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $file = file("names.txt"); foreach ($file as $names) { //echo just to see its working echo $names."<br>"; mysql_query("INSERT INTO vote (id,name,vote) VALUES (NULL,$names,'')"); } mysql_close(); ?>[/code] Hello, I have a text file which is a list of names, each on its own line. I'm trying to use the above code to take each name and insert it into a mysql database. My problem is, that mysql_query will only take a value if it is a number. If I replace names in the text file with numbers it works perfectly. I have also tried replacing file() with file_get_contents() and exploding it, same problem. I am possitive my database is set up correctly, I tested the same code by replacing $names with actual text and it inserted just fine. As you can probably tell I'm new at this, I appreciate any help that can point me in the right direction here.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.