
ntroycondo
Members-
Posts
64 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
ntroycondo's Achievements

Member (2/5)
0
Reputation
-
I'm switching my blog to Wordpress and importing posts fine via RSS but comments aren't importing cleanly. So figured I could import comments with phpMyAdmin. Current DB is MSSql DB. But not sure the best way to do this and the best way to Join the old comments to the appropriate new post IDs. I will probably use post_name to Join comment to appropriate posts. I'm new to SQL so any tips to point me in the right direction are appreciated.
-
I removed the extra ";" ... good catch. But it doesn't make a difference. echo $coin_name; returns nothing. if I echo any other, like $coin_value; it will return the correct string.
-
I have a simple INSERT statement that isn't inserting anything into one of the columns: coin_name I've gone over everything and can't figure out why. All other columns get data. HTML form passes everything fine. Is there a good way to debug this? I've triple checked everything and there are no type-o's that I see. Driving me mad... $query = "INSERT INTO Coin (coin_name, coin_value, coin_condition, year_minted, face_value, purchase_price) VALUES ('$coin_name', '$coin_value', '$coin_condition', '$year_minted', '$face_value', '$purchase_price');";
-
Thanks for advice. I'll keep your idea for $errors for the future. It's working now for me by using strlen: if ((strlen($name)) == 0) { $name= 'NULL'; } if ((strlen($email)) == 0) { $email= 'NULL'; }
-
I've gotten it work for email or name, but not for both. This was using the if(empty) or using strlen. But I'm sure there a cleaner way and for getting both name and email to do this. Search page: <?php // Get value from HTML form $name = $_POST['name']; $connection = mysql_connect('xxxxxxx'); if (! $connection) { die('Error connecting to database ' . mysql_error()); } $name = mysql_real_escape_string($name); // select the proper database (your username) mysql_select_db('User'); // run the query with the properly escaped string $result = mysql_query( "SELECT * FROM User WHERE name like '%$name%'" ); // Check that there were results if(!$result){ die('No results ' . mysql_error()); } echo "<form method='post' action='update.php'>"; while ($row = mysql_fetch_array($result)) { echo "User Info<br />\n"; echo "<input type='hidden' name='userid' value='$row[uSERID]' />\n"; echo "User Name: <input type='text' name='name' value='$row[name]' /><br />\n"; echo "User Email: <input type='text' name='email' value='$row[email]' /><br />\n"; echo "<input type='submit' value='Save' />\n</form>"; // Print number of matching donors echo 'There were ', mysql_num_rows($result), 'Matching Users'; // process results while ($row = mysql_fetch_array($result)) { echo "User Info<br />"; echo "User Name: $row[name]<br />"; echo "User Email: $row[email]<br />"; echo "User ID: $row[uSERID]<br /><br />"; } ?> Update page: <?php // Get value from HTML form $name = $_POST['name']; $email = $_POST['email']; $userid = $_POST['userid']; // Connect using your username and password. $connection = mysql_connect(xxxxxxxxx); if (!$connection) { die("Error connecting to database " . mysql_error()); } // Secure the data before it is used $name = mysql_real_escape_string($name); $email = mysql_real_escape_string($email); // select the proper database mysql_select_db("User"); // Create the query $result = mysql_query("UPDATE User set name= '$name', email = '$email' WHERE USERID = '$userid'"); // Find number of affected rows echo mysql_affected_rows()," row was updated"; ?>
-
I suspect the original IF statement isn't failing at all because the empty string is seen as a value. So comparing string length would probably work. if (strlen($email)) == 0 { $email= 'NULL'; }
-
Now I think I just I want to add an IF into the mysql statement to add the 'NULL' string. Not sure of the syntax to use: mysql_query("UPDATE User set name= IF("'$name'='' ,NULL, '$name'"), email= '$email' WHERE USERID = '$userid'");
-
So it does work with if(empty($name)) { $name = 'NULL'; } else { $name = $_POST['name']; } but if I try to add another if statement for email they both don't work. Do I need anything separating them? if(empty($name)) { $name = 'NULL'; } else { $name = $_POST['name']; } if(empty($email)) { $email = 'NULL'; } else { $email = $_POST['email']; }
-
Using 'if empt'y works. Using '!isset' doesn't give any error. I probably could also put an 'if' into the mysql_query SELECT statement.
-
if(!isset($name)) { $name = 'NULL'; } Does not work for me. if(isset($name)) { $name = 'NULL'; } Does work fine but in the opposite way than desired so i tried IF ELSE but it doesn't work either" if(isset($email)) { $email = $email; } else { $email = 'NULL';}
-
Thanks in advance! I have two PHP pages with one html form page that searches the DB and list results. Code below for both PHP pages. Search php page: <?php // Get value from HTML form $name = $_POST['name']; $connection = mysql_connect('xxxxxxx'); if (! $connection) { die('Error connecting to database ' . mysql_error()); } $name = mysql_real_escape_string($name); // select the proper database (your username) mysql_select_db('User'); // run the query with the properly escaped string $result = mysql_query( "SELECT * FROM User WHERE name like '%$name%'" ); // Check that there were results if(!$result){ die('No results ' . mysql_error()); } echo "<form method='post' action='update.php'>"; while ($row = mysql_fetch_array($result)) { echo "User Info<br />\n"; echo "<input type='hidden' name='userid' value='$row[uSERID]' />\n"; echo "User Name: <input type='text' name='name' value='$row[name]' /><br />\n"; echo "User Email: <input type='text' name='email' value='$row[email]' /><br />\n"; echo "<input type='submit' value='Save' />\n</form>"; // Print number of matching donors echo 'There were ', mysql_num_rows($result), 'Matching Users'; // process results while ($row = mysql_fetch_array($result)) { echo "User Info<br />"; echo "User Name: $row[name]<br />"; echo "User Email: $row[email]<br />"; echo "User ID: $row[uSERID]<br /><br />"; } ?> And my update php page: <?php // Get value from HTML form $name = $_POST['name']; $email = $_POST['email']; $userid = $_POST['userid']; // Connect using your username and password. $connection = mysql_connect(xxxxxxxxx); if (!$connection) { die("Error connecting to database " . mysql_error()); } // Secure the data before it is used $name = mysql_real_escape_string($name); $email = mysql_real_escape_string($email); // select the proper database mysql_select_db("User"); // Create the query $result = mysql_query("UPDATE User set name= '$name', email = '$email' WHERE USERID = '$userid'"); // Find number of affected rows echo mysql_affected_rows()," row was updated"; ?>
-
I am working just with just a string so: if(!isset($name)) { $name = 'NULL'; } will work fine for me. But I haven't figured out the right spot to put the code where it works. Should it be on the form page, or the page with the update php code? Should it be before or after the mysql_query statement? I tried putting it a bunch of spots but haven't got it to work yet.
-
I've changed code around a little but still not working. But I've also been working at it way too long to. Now I get a error from the second ELSE statement: There has been an error in updating the database: 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 1 <?php $connection = mysql_connect("xxxxxxxxxxxxx","xxxxxxxxxxxx", "xxxxxxxxxxxx"); if (!$connection) die("Error connecting to database " . mysql_error()); mysql_select_db('Photographers'); if (isset($_POST['submitted'])) { $name = $_POST['name']; $email = $_POST['email']; $PHOTOGRAPHERID = $_POST['PHOTOGRAPHERID']; } $query = "UPDATE Photographers SET name='$name',email='$email' WHERE PHOTOGRAPHERID=$PHOTOGRAPHERID"; $result = mysql_query($query); if($result){ echo "<p>The user has been updated.</p>"; }else{ echo "<p>There has been an error in updating the database: ".mysql_error()."</p>"; } $query = "SELECT name, email FROM Photographers WHERE PHOTOGRAPHERID=$PHOTOGRAPHERID"; $result = @mysql_query ($query); // Run the query. // Create the form. echo '<h2>Edit a User</h2> <form action="update.php" method="post"> <p>Name: <input type="text" name="name" size="60" maxlength="60" value="' . $row[0] . '" /></p> <p>Email: <input type="text" name="email" size="60" maxlength="60" value="' . $row[1] . '" /></p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="PHOTOGRAPHERID" value="' . $id . '" /> </form>'; ?>
-
Yeah, the mysql_select_db() was commented out in my notes. I've put it in there now but get same error.
-
Trying to get this to work but I know I'm missing something here. It's a form that is meant to update a record in DB. I am getting errore reference to first if (mysql_num_rows($result) == 1) in code and error message: Error has occurred. $connection = mysql_connect("xxxxxxxx","xxxxxx","xxxxxx"); if (!$connection) { die("Error connecting to database " . mysql_error()); } if (isset($_POST['submitted'])) $name = $_POST['name']; $email = $_POST['email']; $PHOTOGRAPHERID = $_POST['PHOTOGRAPHERID']; $query = "SELECT * FROM Photographers WHERE PHOTOGRAPHERID = $PHOTOGRAPHERID"; $result = mysql_query($query); if (mysql_num_rows($result) == 1){ // Make the query. $query = "UPDATE Photographers SET name='$name',email='$email' WHERE PHOTOGRAPHERID=$PHOTOGRAPHERID"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/"."search.php"); } else { // If it did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">The name could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. exit(); } } else { echo '<h1 id="mainhead">Error!</h1> <p class="error">Error has occurred.</p>'; } $query = "SELECT name, email FROM Photographer WHERE PHOTOGRAPHERID=$PHOTOGRAPHERID"; $result = @mysql_query ($query); // Run the query. // Create the form. echo '<h2>Edit a User</h2> <form action="update.php" method="post"> <p>Name: <input type="text" name="name" size="60" maxlength="60" value="' . $row[0] . '" /></p> <p>Email: <input type="text" name="email" size="60" maxlength="60" value="' . $row[1] . '" /></p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="PHOTOGRAPHERID" value="' . $id . '" /> </form>';