Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
Thanks. Out of curiosity, that code snippet at the end,

php:
<?
echo Xhtml::create('img')
    ->setAttribute('src', 'images/happycat.jpg')
    ->setAttribute('alt', 'A Happy Cat')
    ->addClass('align_right')
    ->addClass('drop_shadow')
    ->render();
?>
Is this legal PHP code, or just shortened for our benefit? Can you do multiple functions at once in this method? I never thought about it this way; initially it looked like each -> was adding a new object to it, but yeah, with the ()s there it's basically running the next function off the return of the previous one. Neat. So instead of running 10 commands to add data to my record, I can run a single one formatted like that. I guess my question is, I had assumed this kind of thing was executed right-to-left, but the example you gave shows it's left-to-right. Neat.

Adbot
ADBOT LOVES YOU

KuruMonkey
Jul 23, 2004
Because I made my functions return $this each time I can chain them like that. Its also why I used a create() function to call the constructor (you cannot do new Xhtml()->func() it will not work)

Interestingly... I executed that code before I posted it, and it works fine. Yet I had left off the static keyword in front of the create() function. Yet its callable statically. Every day I find some new oddity in PHP...

Its a nice construct for things you are going to use and discard immediately.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Golbez posted:

This is more general programming theory, but what is the best way to handle data in an object? Have a generic record and functions to handle it, or make a separate function for each piece of data?

Since you seem to be using PHP5, have you thought about using __get, __set and __call instead?

Recycle Bin
Feb 7, 2001

I'd rather be a pig than a fascist
EDIT: Nevermind. Just a server config issue.

Recycle Bin fucked around with this message at 06:17 on Jun 28, 2009

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

I'm currently using ADODB to handle MySQL abstraction on my website but I recently updated to PHP5 and thought it might be a better idea to use something like mysqli or PDO.

Which of the two should I use to handle all my MySQL transactions?

If it matters, I use "update" a lot.

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
PDO.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
mysqli.

Edit: OK, so this is just a bitchy response to the above, why PDO?

MrMoo
Sep 14, 2000

Golbez posted:

why PDO?

Less chunky than Pear::DB_DataObject and reasonable parameter and exception handling? PDO::FETCH_CLASS is very convenient too.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
Edit: PDO is nice, I'm sure. I just don't like the verbosity. And 90% of the servers I work on are on RHEL<=5.

Tad Naff fucked around with this message at 05:57 on Jul 1, 2009

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

MrMoo posted:

Less chunky than Pear::DB_DataObject and reasonable parameter and exception handling? PDO::FETCH_CLASS is very convenient too.

But the question was PDO vs mysqli, not PDO vs Pear.

gibbed
Apr 10, 2006

Doesn't mysqli force you to bind variables?

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
I'd hate to be a bitch two posts in a row, but there's really already a ton of discussion on the subject:
http://www.google.com/search?q=mysqli+vs+pdo

My personal preference is PDO because I feel it's API is much nicer to work with than mysqli.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

gibbed posted:

Doesn't mysqli force you to bind variables?

Doesn't force it, no. You have the choice to send a straight query string, or to bind variables. That said, I'm near giving up on it, due to this monstrosity I've spent the last few minutes creating:
php:
<?
        $query = 'UPDATE tblcases SET
                         CaseType        = ?
                        ,UserID            = ?
                        ,UserEmail        = ?
                        ,UserCompany        = ?
                        ,UserName        = ?
                        ,UserPhone        = ?
                        ,DateOpened        = ?
                        ,DateClosed        = ?
                        ,Resolution        = ?
                        ,Question        = ?
                    WHERE CaseID = ?';
        $mysqli = new InternalDBConnection;
        $stmt = $mysqli->prepare($query);
        $stmt->bind_param('iisissssssi'
                          ,$this->getData('CaseTypeID')
                          ,$this->getData('UserID')
                          ,$this->getData('UserEmail')
                          ,$this->getData('UserCompany')
                          ,$this->getData('UserName')
                          ,$this->getData('UserPhone')
                          ,$this->getData('DateOpened')
                          ,$this->getData('DateClosed')
                          ,$this->getData('Resolution')
                          ,$this->getData('Question')
                          ,$this->getData('CaseID'));
        $stmt->execute();
?>
just to realize that bind_param probably doesn't work that way; for it to work, I'll have to load all of those getDatas into individual variables, then bind THOSE. Yet I still want to have a secure input; back to mres() for me, I guess. Oh, and a new one: Apparently mysqli_bind_param doesn't support NULLs! Well that's just loving great. So now I have to dynamically edit the query as well?

Zend_DB is looking kind of nice. I think I need a beer.

gibbed
Apr 10, 2006

Golbez posted:

just to realize that bind_param probably doesn't work that way; for it to work, I'll have to load all of those getDatas into individual variables, then bind THOSE. Yet I still want to have a secure input; back to mres() for me, I guess. Oh, and a new one: Apparently mysqli_bind_param doesn't support NULLs! Well that's just loving great. So now I have to dynamically edit the query as well?

Zend_DB is looking kind of nice. I think I need a beer.
Yes, that's what I meant, bind_param requires variables to bind to, whereas in PDO you can just do $statement->execute(array($var1, $var2, ...)) (this probably isn't the correct names but you get the idea). And you can bind variables too, if you want to.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
Though in retrospect there's really no reason for me to use "getData" and "setData"; all those commands do is verify the array key exists in $Record. I could just have public variables like, y'know, $UserID, $CaseTypeID, etc. Would make the sanitize function a little more complicated (having to run specifically on each variable, rather than just pass an array to it), but it might make life simpler. And since most of what sanitize() does is escape it, I could skip that if I'm still parameterizing.

Thoughts?

Edit: Or I could skip using the functions to read its own data and pass the Record directly. Duh.

Golbez fucked around with this message at 08:08 on Jul 1, 2009

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Hmmm. Binding parameters one by one is a little troublesome, but then again I only need to bind three or four at max...

If using adodb seems to be "slow" would that be an issue with adodb or MySQL?

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
Likely your queries/tables/datbase. Define "slow".

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

It takes a few seconds every once and awhile but not always.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

Golbez posted:

Though in retrospect there's really no reason for me to use "getData" and "setData"; all those commands do is verify the array key exists in $Record. I could just have public variables like, y'know, $UserID, $CaseTypeID, etc. Would make the sanitize function a little more complicated (having to run specifically on each variable, rather than just pass an array to it), but it might make life simpler. And since most of what sanitize() does is escape it, I could skip that if I'm still parameterizing.

Thoughts?

Edit: Or I could skip using the functions to read its own data and pass the Record directly. Duh.

The idea of using prepared statements is that the API does the escaping for you, you shouldn't need to do any sanitizing as far as database security (but still want to check user input for validity).

Personally I used PDO or Zend_DB (which you can have ride on top of PDO). Also, its really easy to extend PDO or Zend_DB into your own subclasses, which is extremely handy.

With Zend_DB you don't have to use the entire gay framework, just the DB library, and you can do stuff like this, but still have the power to write your own SQL statements when needed.

code:
$values = array(
  'name' => 'Abe Vigoda',
  'status' => 'alive',
  'comments' => $comments
);
$db->insert('mytable', $values);
$newID = $db->lastInsertId();
You could also rather easily subclass PDOStatement/PDO and create your own insert method that does the above, might be good practice if you want to learn PDO inside and out.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
I *like* writing queries. Why do all these advanced things take that tiny joy away from me? :sigh:

duck monster
Dec 15, 2004

drcru posted:

I'm currently using ADODB to handle MySQL abstraction on my website but I recently updated to PHP5 and thought it might be a better idea to use something like mysqli or PDO.

Which of the two should I use to handle all my MySQL transactions?

If it matters, I use "update" a lot.

Stick with ADODB if you can. Its still a fine library.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

Golbez posted:

I *like* writing queries. Why do all these advanced things take that tiny joy away from me? :sigh:

You still can with PDO if you want. You can do stuff like this, and it will still do all the data cleansing.

$sql = "INSERT into mytable(field) VALUES(@field)";

Then you can do $stmt->bindValue("@field", $value);

(probably not exact syntax, but something similar).

ATM Machine
Aug 20, 2007

I paid $5 for this
I'm stumped on this, I'm not a big fan of loops in php because they seem to go horribly wrong, but I'm trying to do a simple preg_replace on tags that a matched through regex on an included file, now its not that it doesn't work, its that the final result sets all the name fields with just 1 variable.

This is the actual function.
php:
<?
    $type = "[a-zA-Z]*";
    $tag = "[a-zA-Z]*";
    $pattern = "/({)(?:(".$type.")[_](".$tag."))(})/";
    $text = file_get_contents("template.html");
    
    preg_match_all($pattern,$text,$matches);
    $i=0;
    foreach($matches as $foo => $bar){
            $replaced = preg_replace($pattern,"<select name='".$matches[3][$i]."'>".$matches[2][$i]."</select>",$text);
            $i++;
    }
    echo $replaced;
?>
and this is the html
code:
<form action="submit.php" method="post" name="submit">
   {drop_uwStart} - {drop_uwEnd} Unwanted Time<br />
   {drop_wStart} - {drop_wEnd} Wanted Time<br /> 
   {drop_uwDay}/{drop_uwMonth}/{drop_uwYear} Unwanted Date<br />
   {drop_wDay}/{drop_wMonth}/{drop_wYear} Wanted Date<br />
   <input type="submit" name="submit" value="submit"/>
   <input type="reset" name="reset" value="reset"/>
</form>
Now I want it to replace the bits in {}'s with a select field, with the part under the underscore as its name, but when I run the script, it does the replace fine, but all the variables are the last matched variable.

Am I doing this the wrong way or something else?

Ferg
May 6, 2007

Lipstick Apathy

ATM Machine posted:

I'm stumped on this, I'm not a big fan of loops in php because they seem to go horribly wrong, but I'm trying to do a simple preg_replace on tags that a matched through regex on an included file, now its not that it doesn't work, its that the final result sets all the name fields with just 1 variable.

This is the actual function.
php:
<?
    $type = "[a-zA-Z]*";
    $tag = "[a-zA-Z]*";
    $pattern = "/({)(?:(".$type.")[_](".$tag."))(})/";
    $text = file_get_contents("template.html");
    
    preg_match_all($pattern,$text,$matches);
    $i=0;
    foreach($matches as $foo => $bar){
            $replaced = preg_replace($pattern,"<select name='".$matches[3][$i]."'>".$matches[2][$i]."</select>",$text);
            $i++;
    }
    echo $replaced;
?>
and this is the html
code:
<form action="submit.php" method="post" name="submit">
   {drop_uwStart} - {drop_uwEnd} Unwanted Time<br />
   {drop_wStart} - {drop_wEnd} Wanted Time<br /> 
   {drop_uwDay}/{drop_uwMonth}/{drop_uwYear} Unwanted Date<br />
   {drop_wDay}/{drop_wMonth}/{drop_wYear} Wanted Date<br />
   <input type="submit" name="submit" value="submit"/>
   <input type="reset" name="reset" value="reset"/>
</form>
Now I want it to replace the bits in {}'s with a select field, with the part under the underscore as its name, but when I run the script, it does the replace fine, but all the variables are the last matched variable.

Am I doing this the wrong way or something else?

Basically each time through the loop you're replacing all occurrences of the matching pattern with the current drop/xTime pair, so at the end you're given all occurrences that originally matched the pattern replaced with the last one. You want to create a second search for the specific occurrence as you loop through each match. Also, when doing a $key => $value pair loop, $key is the index. So in this case, $foo and $i are the same thing. Try this code out:

php:
<?php
    $type "[a-zA-Z]*";
    $tag "[a-zA-Z]*";
    $pattern "/({)(?:(".$type.")[_](".$tag."))(})/";
    $text file_get_contents("template.html");
    
    preg_match_all($pattern,$text,$matches);

    foreach($matches[2] as $foo => $bar)
    {
        $sub_pattern "/({)(?:(".$matches[2][$foo].")[_](".$matches[3][$foo]."))(})/";
        preg_match_all($sub_pattern,$text,$sub_matches);

        $text preg_replace($sub_pattern,"<select name='".$sub_matches[3][0]."'>".$matches[2][0]."</select>",$text);
    }
    
    echo $text;
?>

We (should) have a $matches[3] for each $matches[2] so loop over that to assure you get each occurrence, then replace that specific match with a second preg_replace() call.

KuruMonkey
Jul 23, 2004

ATM Machine posted:

I'm stumped on this, I'm not a big fan of loops in php because they seem to go horribly wrong, but I'm trying to do a simple preg_replace on tags that a matched through regex on an included file, now its not that it doesn't work, its that the final result sets all the name fields with just 1 variable.

Well, the immediate good news is you don't need a loop to do a working version of what you have:

php:
<?
$replaced = preg_replace('/{([a-zA-Z]+)_([a-zA-Z]+)}/', '<select name="$2">$1</select>', $text);
?>
Now, given that I can't see how you're thinking to get meaningful contents into the body of the select tags here... That function call does what you were doing, but with the right names for the selects.

But I don't see any attempt to create the <option> tags in your code, and you will need a loop to do that (probably).

Lets assume you can get that content into $uwStart for {drop_uwStart}, don't you want something more like this?

php:
<?
$matches = array();
$hits = preg_match_all('/{drop_([a-zA-Z]+)}/', $text, $matches);
if($hits > 0)
{
 foreach($matches[1] as $match)
 {
   if(isset($$match))
   {
     $text = str_replace('{drop_'.$match.'}', '<select name="'.$match.'">'.$$match."</select>", $text);
     // when we match {drop_uwStart} $match is "uwStart" so $$match is $uwStart
     // you could also setup $associative_array['uwStart'] and use $associative_array[$match] instead of $$match
   }
 }
}
?>
Oh, and you're probably having trouble with loops because you're doing weird poo poo with them. (like setting up an external index variable then using a foreach and not using the loop variables at all) There's nothing wrong with the loops in PHP, if you use them sanely.

ATM Machine
Aug 20, 2007

I paid $5 for this

Ferg posted:

helping

KuruMonkey posted:

helping

Both help, but yeah, I do want to put options in the select fields. The current way was to call the function that did the options seperately and that'd print off the list, but I hadn't thought about how to go about adding the options in, I knew calling the function probably wouldn't work but I'm out of my area of how I used to code, I'm just trying to break out of the <html><?php $foo ?></html> system I have so that I can reuse and manage similar code easier. So anything more on this is me learning.

And yeah, I'm terrible with loops, I just figured that seeing as what I was aiming for was going to be, find tag -> set the variables -> a loop to fill with options -> next tag, but I think I've missed the mark with this.

EDIT: I actually tried calling my function in Fergs suggestion and it prints the time correctly, but only the first part of the array, but at least its not doing nothing on me. The result is <select name='uwStart'><option value='0000'>0000</option></select> which is pretty much spot on, but because return ends the function straight away, it stops at the first result, and echo just lumps everything up the top of the page instead of where its called

ATM Machine fucked around with this message at 03:57 on Jul 5, 2009

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
Because of duz, I looked into using __get and __set, and kind of like them. However, I'm running into a problem:

php:
<?
$stmt->bind_param('iisi',$this->Type,$this->UserID,$this->UserEmail,$this->UserCompany);
?>
returns notices like this for each $this:

code:
Notice: Indirect modification of overloaded property Record::$UserEmail has no effect in /var/www/foo/bar/Record.php on line 187
etc etc. This is a read function, not a write, yet it's giving a notice about writing it. I prefer to avoid all notices, I like my code clean. Is there any way around this other than writing all of the $this->etc to variables, then pass those variables to the bind_param?

On a similar note, is there any way to see the raw query text of a query mysqli has just executed? It would help with debugging.

SpoonsForThought
Jul 1, 2007

I'm trying to get his php mailer to work, but forever reason it just won't. Everything looks right to me. I grabbed it off another forum, did some slight changes, they had some errors, but no dice. Any help would be appreciated.

<?php

$Subject = "Test E-mail";
$toEmail = "********@gmail.com";

if($submit)
{
$resultMail = mail($toEmail, $Subject, $nMessage);
if($resultMail)
{
print "Your e-mail has been sent.";
}
else
{
print "Your e-mail has not been sent.";
}
}
?>

<html>
<head>
<title>Mail Tutorial</title>
</head>
<body bgcolor="#FFFFFF">

<form method="post" action="<?php echo($PHP_SELF) ?>">
Your E-mail:

<input type="text" name="fromEmail" size="25"> <br>

Your Name: <input type="text" name="fromName" size="25"> <br>

Your Message: <br>

<textarea cols="50" rows="5" name="nMessage">Your Message Here...</textarea> <br>

<input type="submit" value="submit" name="submit">
</form>

</body>
</html>

Supervillin
Feb 6, 2005

Pillbug

SpoonsForThought posted:

I'm trying to get his php mailer to work...

Just to get the easy guess out of the way, is your code on a Windows server (or your own (Windows) computer)? mail on a Linux server basically just hands off to a native command that does a lot of stuff for you, but Windows is different because you're actually delivering it to an SMTP server.

If you're on Windows, make sure all line endings are \r\n and not just \n, and make sure php.ini is modified as appropriate.

SpoonsForThought
Jul 1, 2007

Supervillin posted:

Just to get the easy guess out of the way, is your code on a Windows server (or your own (Windows) computer)? mail on a Linux server basically just hands off to a native command that does a lot of stuff for you, but Windows is different because you're actually delivering it to an SMTP server.

If you're on Windows, make sure all line endings are \r\n and not just \n, and make sure php.ini is modified as appropriate.

I'm new to php so I'll answer these the best I can.

I use a Mac, and I'm not sure of the server type as it is my university's web space that I'm uploading to. There is literally one line about the server and it says it supports PHP scripting.

SpoonsForThought fucked around with this message at 01:05 on Jul 9, 2009

gibbed
Apr 10, 2006

SpoonsForThought posted:

I'm new to php so I'll answer these the best I can.

I use a Mac, and I'm not sure of the server type as it is my university's web space that I'm upload thing to. There is literally one line about the server and it says it supports PHP scripting.
Upload a PHP script with the contents <?php phpinfo(); and access it. The output of phpinfo should give sufficient information about the server and php's configuration.

(and of course, don't leave that script there, remove it when you're done)

SpoonsForThought
Jul 1, 2007

gibbed posted:

Upload a PHP script with the contents <?php phpinfo(); and access it. The output of phpinfo should give sufficient information about the server and php's configuration.

(and of course, don't leave that script there, remove it when you're done)

Ok information:

It is a Linux server, with PHP Version 5.2.4. What else should I be looking for?

Here is my code, a thanks goes DarkLotus for helping me out. For whatever reason, it doesn't work on this server but he says it runs fine on his. Here is the code:

code posted:


<?php
$Subject = "Test E-mail";
$toEmail = "\"Joe Bloe\" <tsiedsma@gmail.com>";
$fromEmail = $_POST['fromEmail'];
$fromName = $_POST['fromName'];
$message = wordwrap($_POST['nMessage'], 70);
$headers = "From: \"$fromName\" <$fromEmail> \r\n" .
"Reply-To: \"$fromName\" <$fromEmail> \r\n" .
'X-Mailer: PHP/' . phpversion();

if($_POST['submit'])
{
$resultMail = mail($toEmail, $Subject, $message, $headers);
if($resultMail)
{
print "Your e-mail has been sent.";
}
else
{
print "Your e-mail has not been sent.";
}
}
?>

Supervillin
Feb 6, 2005

Pillbug

SpoonsForThought posted:

Here is my code, a thanks goes DarkLotus for helping me out. For whatever reason, it doesn't work on this server but he says it runs fine on his. Here is the code:

What's the result? Do you get "Your email has not been sent" or just nothing? If nothing, add this as the first line after <?php:
code:
error_reporting(E_ALL);
Then submit the form again and see if any warnings or errors show up on the page.

SpoonsForThought
Jul 1, 2007

I get these before I even submit:

Notice: Undefined index: fromEmail in /export/webhome/*****/web_pages/request/test.php on line 5

Notice: Undefined index: fromName in /export/webhome/*****/web_pages/request/test.php on line 6

Notice: Undefined index: nMessage in /export/webhome/*****/web_pages/request/test.php on line 7

Notice: Undefined index: submit in /export/webhome/******/web_pages/request/test.php on line 12

And then when I try to submit:

The requested URL /*****/request/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>/export/webhome/*****/web_pages/request/test.php</b> on line <b>37</b><br /> was not found on this server.


The ***** being my username/etc.

jasonbar
Apr 30, 2005
Apr 29, 2005

SpoonsForThought posted:

The requested URL /*****/request/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>/export/webhome/*****/web_pages/request/test.php</b> on line <b>37</b><br /> was not found on this server.

SpoonsForThought posted:

<form method="post" action="<?php echo($PHP_SELF) ?>">

$PHP_SELF should be $_SERVER['PHP_SELF']

Also, you can just try this script to see that mail() actually works without worrying about the rest of your script potentially breaking or mis-directing. If that doesn't work your university may have blocked access to sendmail. When hosting companies do this they usually provide access to an alternative, like PEAR mail. http://pear.php.net/package/Mail
php:
<?
mail($your_email, "Test", "Test Message");
?>

jasonbar fucked around with this message at 08:21 on Jul 9, 2009

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Is there anyway to do the following with PDO?

Original
Array ( [0] => Array ( [map_id] => 1 [name] => Peanut Butter [width] => 25 [height] => 15 [start_sector] => 1 ) [1] => Array ( [map_id] => 2 [name] => Cold Lamb Sandwhich [width] => 11 [height] => 15 [start_sector] => 376 ) )

Array Index is map_id
Array ( [1] => Array ( [name] => Peanut Butter [width] => 25 [height] => 15 [start_sector] => 1 ) [2] => Array ( [name] => Cold Lamb Sandwhich [width] => 11 [height] => 15 [start_sector] => 376 ) )

I'm using fetchAll(PDO::FETCH_ASSOC) right now.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

drcru posted:

Is there anyway to do the following with PDO?

Original
Array ( [0] => Array ( [map_id] => 1 [name] => Peanut Butter [width] => 25 [height] => 15 [start_sector] => 1 ) [1] => Array ( [map_id] => 2 [name] => Cold Lamb Sandwhich [width] => 11 [height] => 15 [start_sector] => 376 ) )

Array Index is map_id
Array ( [1] => Array ( [name] => Peanut Butter [width] => 25 [height] => 15 [start_sector] => 1 ) [2] => Array ( [name] => Cold Lamb Sandwhich [width] => 11 [height] => 15 [start_sector] => 376 ) )

I'm using fetchAll(PDO::FETCH_ASSOC) right now.

I don't believe so. But it is pretty easy to create a function that will take your array from pdo and spit out your new fancy array. Like

code:
$newArray = ReKeyArray('map_id', $resultArray);

SpoonsForThought
Jul 1, 2007

jasonbar posted:

$PHP_SELF should be $_SERVER['PHP_SELF']

Also, you can just try this script to see that mail() actually works without worrying about the rest of your script potentially breaking or mis-directing. If that doesn't work your university may have blocked access to sendmail. When hosting companies do this they usually provide access to an alternative, like PEAR mail. http://pear.php.net/package/Mail
php:
<?
mail($your_email, "Test", "Test Message");
?>

I did that. Nothing happens, no errors, but yet no e-mail comes.

php:
<?
mail("****@gmail.com", "Test", "Test Message");
?>
However, using the other code I still get:

Notice: Undefined index: fromEmail in /export/webhome/*****/web_pages/request/requestwinders.php on line 6

Notice: Undefined index: fromName in /export/webhome/*****/web_pages/request/requestwinders.php on line 7

Notice: Undefined index: fromCompany in /export/webhome/******/web_pages/request/requestwinders.php on line 8

Notice: Undefined index: fromPhone in /export/webhome/*******/web_pages/request/requestwinders.php on line 9

Notice: Undefined index: whichProduct in /export/webhome/******/web_pages/request/requestwinders.php on line 10

Notice: Undefined index: literature in /export/webhome/*******/web_pages/request/requestwinders.php on line 11

Notice: Undefined index: pricing in /export/webhome/*******/web_pages/request/requestwinders.php on line 12

Notice: Undefined index: contact in /export/webhome/******/web_pages/request/requestwinders.php on line 13

Notice: Undefined index: nMessage in /export/webhome/******/web_pages/request/requestwinders.php on line 14

And here is the php:

php:
<?
error_reporting(E_ALL);
$Subject = "ONLINE INFORMATION / SALES REQUEST";                         
$toEmail = "******@gmail.com";
$fromEmail = $_POST['fromEmail'];  
$fromName = $_POST['fromName']; 
$fromCompany = $_POST['fromCompany'];
$fromPhone = $_POST['fromPhone'];
$whichProduct = $_POST['whichProduct'];
$literature = $_POST['literature'];
$pricing = $_POST['pricing'];
$contact = $_POST['contact'];
$message = wordwrap($_POST['nMessage'], 70);
$headers = "From: \"$fromName\" <$fromEmail> \r\n" .
    "Company: \"$fromCompany\" <$fromPhone> \r\n" .
    "Request: \"$whichProduct\" <$literature> <$pricing> <$contact> \r\n" .
    "Reply-To: \"$fromName\" <$fromEmail> \r\n" .
    'X-Mailer: PHP/' . phpversion();
        
if(isset($_POST['submit']))
{
      $resultMail = mail($toEmail, $Subject, $message, $headers);
      if($resultMail)
      {
            print "Your e-mail has been sent.";
      }
      else
      {
            print "Your e-mail has not been sent.";
      }
}  
?>

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Begby posted:

I don't believe so. But it is pretty easy to create a function that will take your array from pdo and spit out your new fancy array. Like

code:
$newArray = ReKeyArray('map_id', $resultArray);

Thanks, I did something like that instead. Is there a nicer way to do this?

php:
<?
    function rekey($array)
    {
        $out = array();
        $max = count($array);

        for($i = 0; $i < $max; $i++)
        {
            $keys = array_values($array[$i]);
            if(is_numeric($keys[0]))
            {
                array_shift($array[$i]);
                $out[$keys[0]] = $array[$i];
            }
        }
        return $out;
    }
?>

Adbot
ADBOT LOVES YOU

Supervillin
Feb 6, 2005

Pillbug

SpoonsForThought posted:

NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE

To get rid of the notices, just move all your variable declarations into the if (isset($_POST['submit'])) block. You only need those if the form is being processed anyway.

It's still strange that you'd get NOTHING though, if there's no warning but mail() fails you should hit the "Your e-mail message has not been sent" block. Try this to see if it even starts processing the form:

php:
<?
if(isset($_POST['submit']))
{
    // (right here is where you put the variable assignments, by the way)
    
    print 'Submit value: ' . $_POST['submit'];
    $resultMail = mail($toEmail, $Subject, $message, $headers);
    if($resultMail)
    {
        print "Your e-mail has been sent.";
    }
    else
    {
        print "Your e-mail has not been sent.";
    }
}  
?>
You should at least see "Submit value: submit", and then either an error or your false message. If you don't even see that then there are some pieces missing from this puzzle.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply