frijole Posted March 7, 2008 Share Posted March 7, 2008 I am trying to build a CMS for my site so I can add videos with a description to my DB. I am not sure if this makes sense? <table> <tr> <td> <form method="post" action="mailto:joelklabo@gmail.com"> Embed HTML:</td><td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML"> Enter Embed HTML Here </textarea></td></tr> <br /> <tr><td> Description: </td><td> <textarea rows="5" cols="50" wrap="physical" name="description"> Describe The Video Here </textarea></td></tr> <tr><td> <input type="submit" value="Add Video!"> </form> </td></tr> </table> <?php require_once "dbConnect.php"; $embedHTML = mysql_real_escape_string($_POST['embedHTML']); $videoDesc = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; mysql_query($query) or die("could not insert data into database"); ?> Quote Link to comment Share on other sites More sharing options...
phpnoobie9 Posted March 7, 2008 Share Posted March 7, 2008 Take action="mailto:joelklabo@gmail.com" and replace it with whatever php file you have with your php code. Quote Link to comment Share on other sites More sharing options...
Naez Posted March 7, 2008 Share Posted March 7, 2008 Besides redoing the mailto of the form, have it echo itself. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Then do: <?php if ($_POST['embedhtml'] && $_POST['description']) { require_once "dbConnect.php"; $embedHTML = mysql_real_escape_string($_POST['embedHTML']); $videoDesc = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; mysql_query($query) or die("could not insert data into database"); echo "Video entered into DB"; } ?> Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 i made those modifications, but when i execute nothing happens. The form reappears and nothing new is echoed to the screen. Any ideas? My connection: <?php // Database settings define("HOST", "localhost"); define("DBUSER", "********"); define("PASS", "********"); define("DB", "********"); // MySQL connection $conn = mysql_connect(HOST, DBUSER, PASS); if (!conn) { // the connection failed so quit the script die('Could not connect !<br />Please contact the site\'s administrator.'); } $db = mysql_select_db(DB); if (!db) { // cannot connect to the database so quit the script die('Could not connect to database <br /> Please contact the site\'s administrator.'); } ?> And the add video script: <?php if ($_POST['embedHTML'] && $_POST['description']) { require_once "dbConnect.php"; $embedHTML = mysql_real_escape_string($_POST['embedHTML']); $videoDesc = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; mysql_query($query) or die("could not insert data into database"); echo "video added to the DB!"; } else { die("the fileds are empty") } ?> <html> <table> <tr> <td> <form method="post" action="videoSubmit.php"> Embed HTML:</td> <td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML"> Enter Embed HTML Here </textarea></td> </tr> <tr> <td>Description: </td> <td><textarea rows="5" cols="50" wrap="physical" name="description"> Describe The Video Here </textarea></td> </tr> <tr> <td><input type="submit" value="Add Video!"></form></td> </tr> </table> </html> Any help would be greatly appreciated. Or any constructive criticisms. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 <?php if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once "dbConnect.php"; $embedHTML = mysql_real_escape_string($_POST['embedHTML']); $videoDesc = mysql_real_escape_string($_POST['description']); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; $result2=mysql_query($query) or die(mysql_error()); if($result2){ echo "video added to the DB!";} } elseif(empty($result2)){ echo "The Fields Are empty";} ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 <?php if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once("dbConnect.php"); $embedHTML = trim(mysql_real_escape_string($_POST['embedHTML'])); $videoDesc = trim(mysql_real_escape_string($_POST['description'])); $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; $result2=mysql_query($query) or die(mysql_error()); } if($result2){ echo "video added to the DB!";} elseif(empty($result2)){ echo "The Fields Are empty";} ?> Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 I just tried it again and got this error: Parse error: syntax error, unexpected '{' in /home/thinksna/public_html/videoSubmit.php on line 10 and this is line 10: $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; anything out of the ordinary? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 <?php $query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")"; ?> should be: <?php $query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)";?> Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 nice, that worked. now: Parse error: syntax error, unexpected '}' in /home/thinksna/public_html/videoSubmit.php on line 23 this is line 23: else { die("the fileds are empty") } Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 use my code man it will work trust me your reverting back to your old code and adding bits and pieces of mine <?php if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once("dbConnect.php"); $embedHTML = trim(mysql_real_escape_string($_POST['embedHTML'])); $videoDesc = trim(mysql_real_escape_string($_POST['description'])); $query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)"; $result2=mysql_query($query) or die(mysql_error()); } if($result2){ echo "video added to the DB!";} elseif(empty($result2)){ echo "The Fields Are empty";} ?> Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 what is the best way to incorporate the form into this? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 <?php if ($_POST) {?> form here <?php }else{ if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once("dbConnect.php"); $embedHTML = trim(mysql_real_escape_string($_POST['embedHTML'])); $videoDesc = trim(mysql_real_escape_string($_POST['description'])); $query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)"; $result2=mysql_query($query) or die(mysql_error()); } if($result2){ echo "video added to the DB!";} elseif(empty($result2)){ echo "The Fields Are empty";} } ?> Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 So I wouldn't echo the form. Just place between the to php blocks? Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 I am now getting this error: Parse error: syntax error, unexpected $end in /home/thinksna/public_html/videoSubmit2.php on line 43 And here is the new version of the whole script: <?php if($_POST){?> <html> <table> <tr> <td> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> Embed HTML:</td> <td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML"> Enter Embed HTML Here </textarea></td> </tr> <tr> <td>Description: </td> <td><textarea rows="5" cols="50" wrap="physical" name="description"> Describe The Video Here </textarea></td> </tr> <tr> <td><input type="submit" value="Add Video!"></form></td> </tr> </table> </html> <?php if (isset($_POST['embedHTML'])||isset($_POST['description'])) { require_once("dbConnect.php"); $embedHTML = trim(mysql_real_escape_string($_POST['embedHTML'])); $videoDesc = trim(mysql_real_escape_string($_POST['description'])); $query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)"; $result2=mysql_query($query) or die(mysql_error()); } if($result2){ echo "video added to the DB!";} elseif(empty($result2)){ echo "The Fields Are empty";} ?> line 43 is the very last line of code. just ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 doood are you even listening? copy the exact code i posted above or u will get errors Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 thats what i did. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 7, 2008 Share Posted March 7, 2008 um no you obviously did not or else there would be an else statement in the bottom which there is not Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 ok, i got it now. thanks for all your help. Quote Link to comment Share on other sites More sharing options...
frijole Posted March 7, 2008 Author Share Posted March 7, 2008 the script is running now but MySQL doesn't like the query its getting. Here is the query: $query = "INSERT INTO videos (embed_html, description) VALUES ($embedHTML,$videoDesc)"; Any ideas? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.