Jim R
Members-
Posts
988 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Jim R
-
Matching file names with mysql queries / Stripping capital letters...
Jim R replied to Jim R's topic in PHP Coding Help
I need to change the variables to all lowercase $line['nameLast'] and $line['nameFirst']. I found what you were referring to, but it doesn't show how to handle multiple column queries. I tried this, but it didn't work: $nf = $line['nameFirst']; $nl = $line['nameLast']; $str = strtolower($nl,$nf); echo '<div><img src="/wp-content/gallery/head_shots/' . $str . '.jpg"></div>'; -
Matching file names with mysql queries / Stripping capital letters...
Jim R replied to Jim R's topic in PHP Coding Help
After changing the collation, I changed my code to echo what the image plugin produces, and the image doesn't show. I just need my code to get nameLast = Smith, nameFirst = Joe, and echo it as smithjoe. -
Matching file names with mysql queries / Stripping capital letters...
Jim R replied to Jim R's topic in PHP Coding Help
Ok...just changed it to latin1_general_ci, and I didn't get an error. I may have tried a different setting. -
Matching file names with mysql queries / Stripping capital letters...
Jim R replied to Jim R's topic in PHP Coding Help
I tried changing it to latin1_general_ci because you had referred to that setting, but it gave me an error. How and where (db or query) do I convert from upper to lower using strtolower()? -
Matching file names with mysql queries / Stripping capital letters...
Jim R replied to Jim R's topic in PHP Coding Help
I'm using latin1_swedish_ci, BTW. Not sure why. -
Matching file names with mysql queries / Stripping capital letters...
Jim R replied to Jim R's topic in PHP Coding Help
The code I put here is actually the entirety of my need on this issue. I'm using WordPress, and I'm matching WordPress slugs to records in my custom data table. That has to be case sensitive (or has been my experience), but when I upload images via one of the plugins, it strips the capital letters. I'd like for my other writers to be able to access photos more easily, so that plugin really helps. -
Matching file names with mysql queries / Stripping capital letters...
Jim R replied to Jim R's topic in PHP Coding Help
Will that change how it's used by other code where it needs the capital letters? -
In querying my database, I'm Selecting nameFirst and nameLast, and it produces a name like Joe Smith. I'm trying to match a photo with the name. Right now I'm uploading photos into a folder naming the file (e.g. SmithJoe.jpg). For reasons that involve writers being able to upload and access photos, I'm trying to use an image plugin. When uploading photos, it strips capital letters, so SmithJoe,jpg goes in as smithjoe.jpg, and it's not matching my database query. Here is the code I'm working with that works quite well with this one exception: $query = 'SELECT * FROM wp_playerRank'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { if ($line['wpID'] == $wp_tagID) { echo '<div class="player">'; // Here is the code that produces the image. I need to get rid of capital letters for ease of use echo '<div><img src="/wp-content/uploads/' . $line['nameLast'] . $line['nameFirst'] . '.jpg"></div>'; echo '<div class="playerData">' . $line['height'] . ' '; if ($line['position'] == 'PG') {echo 'Point Guard';} elseif ($line['position'] == 'SG') {echo 'Shooting Guard';} elseif ($line['position'] == 'SF') {echo 'Small Forward';} elseif ($line['position'] == 'PF') {echo 'Power Forward';} elseif ($line['position'] == 'C') {echo 'Center';} echo '</div>'; echo '<div class="playerData">' . $line['hschool'] . '</div>'; echo '<div class="playerData">' . $line['summer'] . '</div>'; echo '<div class="playerData">Class of ' .$line['year'] . '</div>'; if ($line['committed'] == 'y') { echo '<div> <br>Committed to <strong>'. $line['college'] . '</strong></div> ';} } }
-
It works now. Thanks...I do appreciate it. Make sure you remove the test echo if should port this over to something you need. That goes for anyone who would use this.
-
I found the error, and it has nothing to do with what we're talking about. In what you wrote, the School is missing. So as I cleared my test record, when it put it in there it didn't insert the school name.
-
Here is what it says: However, there is an exact match in the database. I'm looking right at it.
-
It was an exact match. I back up to the registration page, so all the information is the same. From there I changed street address. It didn't reflect the change. It entered a new record.
-
It didn't work. I went back to the form, entered my first name, my last name and, the same school name to test it, and I changed my address to a previous one. It didn't update it. It inserted a new record. Could there be an issue with the variables in the IF statement? In what you wrote, they don't appear to match the query.
-
It's not recognizing the similar record and just inserting.
-
I really do appreciate your help and your time. I do. I have been involved in a lot of topics on here asking for help and giving a little from the experiences I have had. I never been given the advice of using those escape strings. It was working and worked multiple times, and I tried it on different names, both inserting and updating. Suddenly it doesn't work. That said, the code you wrote didn't work. I got an error:
-
I commented out of this code, and it passes the User through to the Payment page. What does this code do? if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } Hmmm...not it's not inserting.
-
I went back to the code I had, without the escapes, as I was getting the same error without the escapes. It is updating the data base, but it isn't passing the User through to the payment page. So it appears to be getting stuck on the following code: if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header( 'Location: /fall-league/payment' ); mysql_close($con)
-
And since changing to the escape string, it won't Insert either.
-
I'm getting the same error:
-
Ok...I used the IF statement as you described it. It's Inserting just fine if doesn't find a match. If it does find a match, I'm getting an error. It's looking for a matching first name, last name and school, and if found, it's supposed to Update the information. Here is the error: Here is the code I'm using: <?php $con = mysql_connect("localhost","jwrbloom_","redcoach"); if (!$con) { die('Could not connect: ' . mysql_error()); } $nameFirst=$_POST['nameFirst']; $nameLast=$_POST['nameLast']; $email=$_POST['email']; $addressHome=$_POST['addressHome']; $stateHome=$_POST['stateHome']; $zipHome=$_POST['zipHome']; $phoneHome=$_POST['phoneHome']; $phoneMobile=$_POST['phoneMobile']; $school=$_POST['school']; $grade=$_POST['grade']; $coachSchool=$_POST['coachSchool']; $feet=$_POST['feet']; $inshces=$_POST['inches']; mysql_select_db("jwrbloom_wpMIB", $con); $result = mysql_query( "SELECT id FROM fallLeague10 WHERE nameFirst='$nameFirst' AND nameLast='$nameLast' AND school='$school' "); if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); // update existing row $result = mysql_query("UPDATE fallLeague10 SET confirm='y', email='$email', addressHome='$addressHome', stateHome='$stateHome', zipHome='$zipHome', phoneHome='$phoneHome', phoneMobile='$phoneMobile', coachSchool='$coachSchool', feet='$feet', inches='$inches' WHERE id='".$row['id']."'"); } else { $result="INSERT INTO fallLeague10(confirm,nameFirst,nameLast,email,addressHome,stateHome,zipHome,phoneHome,phoneMobile,school,grade,coachSchool,feet,inches) VALUES ('y','$_POST[nameFirst]','$_POST[nameLast]','$_POST[email]','$_POST[addressHome]','$_POST[stateHome]','$_POST[zipHome]','$_POST[phoneHome]','$_POST[phoneMobile]','$_POST[school]','$_POST[grade]','$_POST[coachSchool]','$_POST[feet]','$_POST[inches]')"; }
-
Neil, When you look at the Select vs. what I would otherwise Insert I have showed what I'm trying to do. I'm trying to Update the rest of it into an already existing record. My issue is getting it do differentiate between when to Insert vs. when to Update. I know how to use Select, Insert and Update separately. I'm just trying to figure out the syntax of the IF, ELSE (ELSEIF). I've asked twice before about the syntax of the IF and establishing the right condition.
-
Would this work: (I need to change the echo part of the IF statement into my UPDATE code) <?php $con = mysql_connect("localhost","jwrbloom_","redcoach"); if (!$con) { die('Could not connect: ' . mysql_error()); } $nameFirst=$_POST['nameFirst']; $nameLast=$_POST['nameLast']; $school=$_POST['school']; mysql_select_db("jwrbloom_wpMIB", $con); $result = mysql_query( "SELECT * FROM fallLeague10 WHERE nameFirst='$nameFirst' AND nameLast='$nameLast' AND school='$school' "); $aff_rows = mysql_affected_rows($result); if( $aff_rows === 1 ) { echo 'One row was updated.'; // Or do something else, whatever . . . } else { $sql="INSERT INTO fallLeague10(nameFirst,nameLast,email,addressHome,stateHome,zipHome,phoneHome,phoneMobile,school,grade,coachSchool,feet,inches) VALUES ('$_POST[nameFirst]','$_POST[nameLast]','$_POST[email]','$_POST[addressHome]','$_POST[stateHome]','$_POST[zipHome]','$_POST[phoneHome]','$_POST[phoneMobile]','$_POST[school]','$_POST[grade]','$_POST[coachSchool]','$_POST[feet]','$_POST[inches]')"; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header( 'Location: /fall-league/payment' ); mysql_close($con) ?>
-
I have the SELECT part already, as well as the INSERT portion after an ELSEIF. My question gets to how do I set up the IF portion? I read what you posted above, but I'm not sure what applies to me or what is mostly general recommendation.
-
I know, but the insert code was left over from last year's entries. Here is the correct version: <?php $con = mysql_connect("localhost","db_name","db_password"); if (!$con) { die('Could not connect: ' . mysql_error()); } $nameFirst=$_POST['nameFirst']; $nameLast=$_POST['nameLast']; $school=$_POST['school']; mysql_select_db("db_table_name", $con); $result = mysql_query( "SELECT * FROM fallLeague10 WHERE nameFirst='$nameFirst' AND nameLast='$nameLast' AND school='$school' "); $sql="INSERT INTO fallLeague10(nameFirst,nameLast,email,addressHome,stateHome,zipHome,phoneHome,phoneMobile,school,grade,coachSchool,feet,inches) VALUES ('$_POST[nameFirst]','$_POST[nameLast]','$_POST[email]','$_POST[addressHome]','$_POST[stateHome]','$_POST[zipHome]','$_POST[phoneHome]','$_POST[phoneMobile]','$_POST[school]','$_POST[grade]','$_POST[coachSchool]','$_POST[feet]','$_POST[inches]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header( 'Location: /fall-league/payment' ); mysql_close($con) ?>
-
Crap...I'm not. My fault. When I put that PHP page online, it will all be fallLeague10.